data(blackcap)
fitobject <- corrHLfit(migStatus ~ 1 + Matern(1|latitude+longitude),data=blackcap,
ranFix=list(nu=4,rho=0.4,phi=0.05))
predict(fitobject)
getDistMat(fitobject)
#### multiple controls of prediction variances
## (1) fit with an additional random effect
grouped <- cbind(blackcap,grp=c(rep(1,7),rep(2,7)))
fitobject <- corrHLfit(migStatus ~ 1 + (1|grp) +Matern(1|latitude+longitude),
data=grouped, ranFix=list(nu=4,rho=0.4,phi=0.05))
## (2) re.form usage to remove a random effect from point prediction and variances:
predict(fitobject,re.form= ~ 1 + Matern(1|latitude+longitude))
## (3) comparison of covariance matrices for two types of new data
moregroups <- grouped[1:5,]
rownames(moregroups) <- paste("newloc",1:5,sep="")
moregroups$grp <- rep(3,5) ## all new data belong to an unobserved third group
cov1 <- attr(predict(fitobject,newdata=moregroups,
variances=list(linPred=TRUE,cov=TRUE)),"predVar")
moregroups$grp <- 3:7 ## all new data belong to distinct unobserved groups
cov2 <- attr(predict(fitobject,newdata=moregroups,
variances=list(linPred=TRUE,cov=TRUE)),"predVar")
cov1-cov2 ## the expected off-diagonal covariance due to the common group in the first fit.
## Effects of numerically singular correlation matrix C:
fitobject <- corrHLfit(migStatus ~ 1 + Matern(1|latitude+longitude),data=blackcap,
ranFix=list(nu=10,rho=0.001)) ## numerically singular C
predict(fitobject) ## predicted mu computed as X beta + L v
predict(fitobject,newdata=blackcap) ## predicted mu computed as X beta + C
## point predictions and variances with new X and Z
if(require("rsae", quietly = TRUE)) {
data(landsat)
fitobject <- HLfit(HACorn ~ PixelsCorn + PixelsSoybeans + (1|CountyName),
data=landsat[-33,],HLmethod="ML")
newXandZ <- unique(data.frame(PixelsCorn=landsat$MeanPixelsCorn,
PixelsSoybeans=landsat$MeanPixelsSoybeans,
CountyName=landsat$CountyName))
predict(fitobject,newdata=newXandZ,variances = list(linPred=TRUE,dispVar=TRUE))
}
Run the code above in your browser using DataLab