fittedvlm: Fitted Values of a VLM object

View source: R/fittedvlm.R

fittedvlmR Documentation

Fitted Values of a VLM object

Description

Extractor function for the fitted values of a model object that inherits from a vector linear model (VLM), e.g., a model of class "vglm".

Usage

fittedvlm(object, drop = FALSE, type.fitted = NULL,
          percentiles = NULL, ...)

Arguments

object

a model object that inherits from a VLM.

drop

Logical. If FALSE then the answer is a matrix. If TRUE then the answer is a vector.

type.fitted

Character. Some VGAM family functions have a type.fitted argument. If so then a different type of fitted value can be returned. It is recomputed from the model after convergence. Note: this is an experimental feature and not all VGAM family functions have this implemented yet. See CommonVGAMffArguments for more details.

percentiles

See CommonVGAMffArguments for details.

...

Currently unused.

Details

The “fitted values” usually corresponds to the mean response, however, because the VGAM package fits so many models, this sometimes refers to quantities such as quantiles. The mean may even not exist, e.g., for a Cauchy distribution.

Note that the fitted value is output from the @linkinv slot of the VGAM family function, where the eta argument is the n \times M matrix of linear predictors.

Value

The fitted values evaluated at the final IRLS iteration.

Note

This function is one of several extractor functions for the VGAM package. Others include coef, deviance, weights and constraints etc. This function is equivalent to the methods function for the generic function fitted.values.

If fit is a VLM or VGLM then fitted(fit) and predict(fit, type = "response") should be equivalent (see predictvglm). The latter has the advantage in that it handles a newdata argument so that the fitted values can be computed for a different data set.

Author(s)

Thomas W. Yee

References

Chambers, J. M. and T. J. Hastie (eds) (1992). Statistical Models in S. Wadsworth & Brooks/Cole.

See Also

fitted, predictvglm, vglmff-class.

Examples

# Categorical regression example 1
pneumo <- transform(pneumo, let = log(exposure.time))
(fit1 <- vglm(cbind(normal, mild, severe) ~ let, propodds, pneumo))
fitted(fit1)

# LMS quantile regression example 2
fit2 <- vgam(BMI ~ s(age, df = c(4, 2)),
             lms.bcn(zero = 1), data = bmi.nz, trace = TRUE)
head(predict(fit2, type = "response"))  # Equals to both these:
head(fitted(fit2))
predict(fit2, type = "response", newdata = head(bmi.nz))

# Zero-inflated example 3
zdata <- data.frame(x2 = runif(nn <- 1000))
zdata <- transform(zdata,
                   pstr0.3  = logitlink(-0.5       , inverse = TRUE),
                   lambda.3 =   loglink(-0.5 + 2*x2, inverse = TRUE))
zdata <- transform(zdata,
         y1 = rzipois(nn, lambda = lambda.3, pstr0 = pstr0.3))
fit3 <- vglm(y1 ~ x2, zipoisson(zero = NULL), zdata, trace = TRUE)
head(fitted(fit3, type.fitted = "mean" ))  # E(Y) (the default)
head(fitted(fit3, type.fitted = "pobs0"))  # Pr(Y = 0)
head(fitted(fit3, type.fitted = "pstr0"))  # Prob of a structural 0
head(fitted(fit3, type.fitted = "onempstr0"))  # 1 - Pr(structural 0)

VGAM documentation built on Sept. 18, 2024, 9:09 a.m.