Function to compute predicted values based on linear predictor and associated standard errors from various fitted models.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  predictSE(mod, newdata, se.fit = TRUE, print.matrix = FALSE, ...)
## S3 method for class 'gls'
predictSE(mod, newdata, se.fit = TRUE, print.matrix =
FALSE, ...)
## S3 method for class 'lme'
predictSE(mod, newdata, se.fit = TRUE, print.matrix =
FALSE, level = 0, ...)
## S3 method for class 'mer'
predictSE(mod, newdata, se.fit = TRUE, print.matrix =
FALSE, level = 0, type = "response", ...)
## S3 method for class 'merMod'
predictSE(mod, newdata, se.fit = TRUE, print.matrix =
FALSE, level = 0, type = "response", ...)
## S3 method for class 'unmarkedFitPCount'
predictSE(mod, newdata, se.fit = TRUE,
print.matrix = FALSE, type = "response", c.hat = 1, parm.type =
"lambda", ...)
## S3 method for class 'unmarkedFitPCO'
predictSE(mod, newdata, se.fit = TRUE,
print.matrix = FALSE, type = "response", c.hat = 1,
parm.type = "lambda", ...)

mod 
an object of class 
newdata 
a data frame with the same structure as that of the original data frame for which we want to make predictions. 
se.fit 
logical. If 
print.matrix 
logical. If 
level 
the level for which predicted values and standard errors are to be
computed. The current version of the function only supports
predictions for the populations excluding random effects (i.e.,

type 
specifies the type of prediction requested. This argument can take
the value 
c.hat 
value of overdispersion parameter (i.e., variance inflation factor)
such as that obtained from 
parm.type 
the parameter for which predictions are made based on the
Nmixture model of class 
... 
additional arguments passed to the function. 
predictSE
computes predicted values and associated standard
errors. Standard errors are approximated using the delta method
(Oehlert 1992). Predictions and standard errors for objects of
gls
class and mixed models of lme
, mer
,
merMod
classes exclude the correlation or variance structure
of the model.
predictSE
computes predicted values on abundance and standard
errors based on the estimates from an unmarkedFitPCount
or
unmarkedFitPCO
object. Currently, only predictions on
abundance (i.e., parm.type = "lambda"
) with the zeroinflated
Poisson distribution is supported. For other parameters or
distributions for models of unmarkedFit
classes, use
predict
from the unmarked
package.
predictSE
returns requested values either as a matrix
(print.matrix = TRUE
) or list (print.matrix = FALSE
)
with components:
fit 
the predicted values. 
se.fit 
the standard errors of the predicted values (if 
For standard errors with better properties, especially for small samples, one can opt for simulations (see Gelman and Hill 2007), or nonparametric bootstrap (Efron and Tibshirani 1998).
Marc J. Mazerolle
Efron, B., Tibshirani, R. J. (1998) An Introduction to the Bootstrap. Chapman & Hall/CRC: New York.
Gelman, A., Hill, J. (2007) Data Analysis Using Regression and Multilevel/Hierarchical Models. Cambridge University Press: New York.
Oehlert, G. W. (1992) A note on the delta method. American Statistician 46, 27–29.
gls
, lme
, glmer
,
simulate.merMod
, boot
,
parboot
, nonparboot
,
pcount
, pcountOpen
,
unmarkedFitclass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  ##Orthodont data from Pinheiro and Bates (2000) revisited
## Not run:
require(nlme)
m1 < gls(distance ~ age, correlation = corCompSymm(value = 0.5, form = ~ 1  Subject),
data = Orthodont, method= "ML")
##compare against lme fit
logLik(m1)
logLik(lme(distance ~ age, random = ~1  Subject, data = Orthodont,
method= "ML"))
##both are identical
##compute predictions and SE's for different ages
predictSE(m1, newdata = data.frame(age = c(8, 10, 12, 14)))
detach(package:nlme)
## End(Not run)
##example with mallard data set from unmarked package
## Not run:
require(unmarked)
data(mallard)
mallardUMF < unmarkedFramePCount(mallard.y, siteCovs = mallard.site,
obsCovs = mallard.obs)
##run model with zeroinflated Poisson abundance
fm.mall.one < pcount(~ ivel + date ~ length + forest, mallardUMF, K=30,
mixture = "ZIP")
##make prediction
predictSE(fm.mall.one, type = "response", parm.type = "lambda",
newdata = data.frame(length = 0, forest = 0, elev = 0))
##compare against predict
predict(fm.mall.one, type = "state", backTransform = TRUE,
newdata = data.frame(length = 0, forest = 0, elev = 0))
##add offset in model to scale abundance per transect length
fm.mall.off < pcount(~ ivel + date ~ forest + offset(length), mallardUMF, K=30,
mixture = "ZIP")
##make prediction
predictSE(fm.mall.off, type = "response", parm.type = "lambda",
newdata = data.frame(length = 10, forest = 0, elev = 0))
##compare against predict
predict(fm.mall.off, type = "state", backTransform = TRUE,
newdata = data.frame(length = 10, forest = 0, elev = 0))
detach(package:unmarked)
## End(Not run)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.