# NOT RUN {
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) <- paste0("newloc",1:5)
moregroups$grp <- rep(3,5) ## all new data belong to an unobserved third group
cov1 <- get_predVar(fitobject,newdata=moregroups,
variances=list(linPred=TRUE,cov=TRUE))
moregroups$grp <- 3:7 ## all new data belong to distinct unobserved groups
cov2 <- get_predVar(fitobject,newdata=moregroups,
variances=list(linPred=TRUE,cov=TRUE))
cov1-cov2 ## the expected off-diagonal covariance due to the common group in the first fit.
# }
# NOT RUN {
## Other extractors:
fix_X_ZAC.object <- preprocess_fix_corr(fitobject,fixdata=blackcap)
# ... for use in multiple calls to get_predCov_var_fix():
get_predCov_var_fix(fitobject,newdata=blackcap[14,],fix_X_ZAC.object=fix_X_ZAC.object)
## prediction with distinct given phi's in different locations:
varphi <- cbind(blackcap,logphi=runif(14))
vphifit <- corrHLfit(migStatus ~ 1 + Matern(1|latitude+longitude),
resid.model = list(formula=~0+offset(logphi)),
data=varphi, ranFix=list(nu=4,rho=0.4))
# for respVar computation, one needs the resid.model formula to specify phi:
get_respVar(vphifit,newdata=data.frame(latitude=1,longitude=1,logphi=1))
# for predVar computation, phi is not needed
# (and could have been specified through ranFix):
get_predVar(vphifit,newdata=data.frame(latitude=1,longitude=1))
## point predictions and variances with new X and Z
if(requireNamespace("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(predVar=TRUE))
get_predVar(fitobject,newdata=newXandZ,variances = list(predVar=TRUE))
}
# }
Run the code above in your browser using DataLab