Learn R Programming

spaMM (version 1.1)

predict: Prediction from a model fit.

Description

Predictions of the response variable in different locations and/or different values of the predictor variables for fixed effects, based on random effects inferred by HLCor / corrHLfit.

Usage

## S3 method for class 'HLfit':
predict(object,newX = NULL,...)
## S3 method for class 'HLCor':
predict(object,newX = NULL,coeffs=NULL,...)
## S3 method for class 'corrHLfit':
predict(object,newX = NULL,coeffs=NULL,...)

Arguments

object
The return object of an HLfit / HLCor / corrHLfit call.
newX
A data frame containing new locations and values of the predictor variables for fixed effects and of any variable required to compute an offset. Its column names must match those of the originally fitted data. If NULL, the original data are r
coeffs
Precomputed coefficients for the prediction (see Details).
...
further arguments passed to or from other methods.

Value

  • A data frame including the locations and the expected value (fv=$\mu$) of the response variable.

Details

If newX is NULL, predict only returns the fitted responses from the object. Otherwise 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 [t(L)]^{-1} v (see spaMM for notation). The fixed effects and offset (if any) are added. If the predictor is used many times, it may be useful to precompute [t(L)]^{-1} v and to provide this vector through the coeffs argument (see Examples).

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)
## same result using precomputed 'coeffs':
coeffs <- with(fitobject$hlfit,solve(t(attr(predictor,"LMatrix")),v_h))
predict(fitobject,blackcap,coeffs=coeffs)

## 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.solve(t(L),v)

Run the code above in your browser using DataLab