Predict Method for MANYGLM Fits
predict.manyglm.Rd
Obtains predictions and optionally estimates standard errors of those predictions from a fitted manyglm object.
Usage
<!-- % predict.manyglm -->
# S3 method for manyglm
predict(object, newdata, type = c("link", "response",
"terms"), se.fit = FALSE, dispersion = NULL, terms = NULL,
na.action = na.pass, ...)
Arguments
- object
a fitted object of class inheriting from
"manyglm"
.- newdata
optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used.
- type
the type of prediction required. The default is on the scale of the linear predictors; the alternative
"response"
is on the scale of the response variable. Thus for a default binomial model the default predictions are of log-odds (probabilities on logit scale) andtype = "response"
gives the predicted probabilities. The"terms"
option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale.The value of this argument can be abbreviated.
- se.fit
logical switch indicating if standard errors are required.
- dispersion
the dispersion of the MANYGLM fit to be assumed in computing the standard errors. If omitted, that returned by
summary
applied to the object is used.- terms
with
type="terms"
by default all terms are returned. A character vector specifies which terms are to be returned- na.action
function determining what should be done with missing values in
newdata
. The default is to predictNA
.- ...
further arguments passed to or from other methods.
Details
predict.manyglm refits the model using glm before making predictions. In rare (usually pathological) cases this may lead to differences in predictions as compared to what would be expected if using the manyglm coefficients directly.
If newdata
is omitted the predictions are based on the data
used for the fit. In that case how cases with missing values in the
original fit is determined by the na.action
argument of that
fit. If na.action = na.omit
omitted cases will not appear in
the residuals, whereas if na.action = na.exclude
they will
appear (in predictions and standard errors), with residual value
NA
. See also napredict
.
Value
If se = FALSE
, a matrix of predictions or an array of
predictions and bounds.
If se = TRUE
, a list with components
- fit
the predictions
- se.fit
estimated standard errors
- residual.scale
a scalar giving the square root of the dispersion used in computing the standard errors.
Examples
data(spider)
spiddat <- mvabund(spider$abund)
Y <- spiddat[1:20,]
X <- spider$x[1:20,]
glm.spid.poiss <- manyglm(Y~soil.dry+bare.sand, family="poisson", data=X)
glm.spid.poiss$data = X
newdata <- spider$x[21:28,]
predict(glm.spid.poiss, newdata)
#> Alopacce Alopcune Alopfabr Arctlute Arctperi Auloalbi Pardlugu
#> 21 0.173682 1.954209 -1.7986429 0.07223037 -14.81551 1.918754714 1.838984
#> 22 5.287235 1.520908 1.9058763 -3.32962641 -14.81551 0.289921954 -2.464575
#> 23 5.598276 1.449217 1.9768606 -3.48792216 -14.81551 0.257221756 -2.180105
#> 24 3.798268 1.751523 1.1827968 -2.45110546 -14.81551 0.611282508 -2.469944
#> 25 3.000714 1.910875 0.9174565 -2.01896021 -14.81551 0.730964149 -2.904475
#> 26 5.738159 1.588995 2.5944497 -3.74362673 -14.81551 -0.009343657 -4.124837
#> 27 6.765881 1.197188 2.3015098 -4.10047391 -14.81551 0.109448241 -1.318156
#> 28 6.331652 1.378512 2.4790044 -3.96662569 -14.81551 0.036153864 -2.694148
#> Pardmont Pardnigr Pardpull Trocterr Zoraspin
#> 21 2.342095 3.02750539 3.449893 3.910829 2.0503870
#> 22 6.160194 -0.01797223 1.764121 1.923396 -0.1406095
#> 23 6.349804 -0.08756089 1.746517 1.887685 -0.2759097
#> 24 5.146660 0.60234881 2.059304 2.305857 0.5020410
#> 25 4.637458 0.84322260 2.150297 2.443409 0.8478749
#> 26 6.596843 -0.55770997 1.416320 1.548425 -0.3290585
#> 27 7.077643 -0.39238593 1.648414 1.721522 -0.7830435
#> 28 6.889336 -0.50249372 1.520788 1.618739 -0.5905213
pred.w.plim <- predict(glm.spid.poiss, newdata, interval="prediction")
pred.w.clim <- predict(glm.spid.poiss, newdata, interval="confidence")