Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predVar

Prediction and response variances


Description

spaMM allows computation of four variance components of prediction, returned by predict as “...Var” attributes: predVar, fixefVar, residVar, or respVar. The phrase “prediction variance” is used inconsistently in the literature. Often it is used to denote the uncertainty in the response (therefore, including the residual variance), but spaMM departs from this usage. Here, this uncertainly is called the response variance (respVar), while prediction variance (predVar) is used to denote the uncertainty in the linear predictor (as in Booth & Hobert, 1998). The respVar is the predVar plus the residual variance residVar.

Which components are returned is controlled in particular by the type and variances arguments of the relevant functions. variances is a list of booleans whose possible elements either match the possible returned components: predVar, fixefVar, residVar, or respVar; or may additionally include linPred, disp, cov, as_tcrossfac_list and possibly other cryptic ones.

The predict default value for all elements is NULL, which jointly translate to no component being computed, equivalently to setting all elements to FALSE. However, setting one component to TRUE may reverse the default effect for other components. In particular, by default, component predVar implies linPred=TRUE, disp=TRUE and component respVar additionally implies residVar=TRUE; in both cases, the linPred=TRUE default by default implies fixefVar=TRUE. Calling for one variance may imply that some of its components are not only computed but also returned as a distinct attribute.

By default the returned components are vectors of variances (with exceptions for some type value). To obtain covariance matrices (when applicable), set cov=TRUE. as_tcrossfac_list=TRUE can be used to return a list of matrices X_i such that the predVar\ covariance matrix equals ∑_i X_i X'_i. It thus provides a representation of the predVar that may be useful in particular when the predVar has large dimension, as the component X_is may require less memory (being possibly non-square or sparse).

residVar=TRUE evaluates residVar the residual variances for Gaussian or Gamma responses.

fixefVar=TRUE evaluates fixefVar, the variance due to uncertainty in fixed effects (Xβ).

Computations implying linPred=TRUE will take into account the variances of the linear predictor η, i.e. the uncertainty in fixed effects (Xβ) and random effects (ZLv), for given dispersion parameters (see Details). For fixed-effect models, the fixefVar calculations reduces to the linPred one.

Computations implying disp=TRUE additionally include the effect of uncertainty in estimates of dispersion parameters (λ and φ), with some limitations: this effect can be computed for a scalar residual variance (φ) and for several random effects with scalar variances (λ). Thus, the argument variances=list(predVar=TRUE) implies that uncertainty if linear predictor, including uncertainty in dispersion parameters, is taken into account, and the argument variances=list(respVar=TRUE) additionally includes residual variance.

Details

fixefVar is the (co)variance of Xβ, deduced from the asymptotic covariance matrix of β estimates.

linPred is the prediction (co)variance of η=Xβ+Zv (see HLfit Details for notation, and keep in mind that new matrices may replace the ones from the fit object when newdata are used), by default computed for given dispersion parameters. It takes into account the joint uncertainty in estimation of β and prediction of v. In particular, for new levels of the random effects, predVar computation takes into account uncertainty in prediction of v for these new levels. For prediction covariance with a new Z, it matters whether a single or multiple new levels are used: see Examples.

For computations implying disp=TRUE, prediction variance may also include a term accounting for uncertainty in φ and λ, computed following Booth and Hobert (1998, eq. 19). This computation ignores uncertainties in spatial correlation parameters.

respVar is the sum of predVar (pre- and post-multiplied by dμ/dη for models with non-identity link) and of residVar.

These variance calculations are approximate except for LMMs, and cannot be guaranteed to give accurate results.

References

Booth, J.G., Hobert, J.P. (1998) Standard errors of prediction in generalized linear mixed models. J. Am. Stat. Assoc. 93: 262-272.

Examples

## Not run: 
# (but run in help("get_predVar"))
data("blackcap")
fitobject <- fitme(migStatus ~ 1 + Matern(1|longitude+latitude),data=blackcap,
                       fixed=list(nu=4,rho=0.4,phi=0.05))

#### multiple controls of prediction variances
# (1) fit with an additional random effect
grouped <- cbind(blackcap,grp=c(rep(1,7),rep(2,7))) 
fitobject <- fitme(migStatus ~ 1 +  (1|grp) +Matern(1|longitude+latitude),
                       data=grouped,  fixed=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|longitude+latitude))

# (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.


## End(Not run)
## see help("get_predVar") for further examples

spaMM

Mixed-Effect Models, with or without Spatial Random Effects

v3.10.0
CeCILL-2
Authors
François Rousset [aut, cre, cph] (<https://orcid.org/0000-0003-4670-0371>), Jean-Baptiste Ferdy [aut, cph], Alexandre Courtiol [aut] (<https://orcid.org/0000-0003-0637-2959>), GSL authors [ctb] (src/gsl_bessel.*)
Initial release
2022-02-06

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.