Learn R Programming

spaMM (version 1.3.0)

predict: Prediction from a model fit.

Description

Predictions of the response variable, based on given values of the predictor variables for fixed effects, and/or on predicted random effects.

Usage

## S3 method for class 'HLfit':
predict(
                 object,newX = NULL,coeffs=NULL,
                 predVar=FALSE, re.form= NULL,
                 binding = if(is.vector(newX)) {FALSE} else {"fitted"},...)

Arguments

object
The return object of an HLfit or similar function.
newX
Either a matrix or data frame containing all required variables for evaluating fixed and random effects, including an offset. If NULL, the original data are reused. or a numeric vector, which names (if any) are ignored.
coeffs
Precomputed coefficients for the prediction (see Details).
predVar
Either a boolean or "Cov". If this is TRUE, the prediction variances are computed. If this is "Cov", the full covariance matrix is computed. In both cases, the result is included as attribute "predVar"
re.form
formula for random effects to include. If NULL, include all random effects; if NA, include no random effects
binding
If binding is a valid variable name for a data frame, the predicted values are bound (under the given name) with the date frame used for prediction and the resulting frame is returned. If binding is FALSE, The
...
further arguments passed to or from other methods.

Value

  • A matrix or data frame (according to the binding argument), with optionally a prediction variance vector or (co)variance matrix as attribute.

Details

If newX is NULL, predict only returns the fitted responses, including random effects, from the object. Otherwise it computes new predictions including random effects as far as possible. For spatial random effects it constructs a correlation matrix C between new locations and locations in the original fit. Then it infers the random effects in the new locations as C (L'$)^{-1}$ v (see spaMM for notation). If the predictor is used many times, it may be useful to precompute (L'$)^{-1}$ v and to provide this vector through the coeffs argument (see Examples). For non-spatial random effects, it checks whether any group (i.e., level of a random effect) in the new data was represented in the original data, and it adds the inferred random effect for this group to the prediction for individuals in this group. The prediction variance is the variance of the linear predictor ($\eta$). It accounts for the uncertainty in prediction of the random effects. In addition, it accounts for uncertainty in estimation of $\beta$. It is computed as described in Gotway and Wolfinger (2003).

References

Gotway, C.A., Wolfinger, R.D. (2003) Spatial prediction of counts and rates. Statistics in Medicine 22: 1415-1432.

Examples

Run this code
data(blackcap)
fitobject <- corrHLfit(migStatus ~ 1 + Matern(1|latitude+longitude),data=blackcap,
                       ranFix=list(nu=4,rho=0.4,phi=0.05))
predict(fitobject)

predict(fitobject,blackcap) ## same computation, different format 

## same result using precomputed 'coeffs':
coeffs <- predictionCoeffs(fitobject) ## using dedicated extractor function
predict(fitobject,coeffs=coeffs,predVar=TRUE)
attr(.Last.value,"predVar")

## 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,newX=blackcap) ## predicted mu computed as X beta + C

Run the code above in your browser using DataLab