
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"
.
fittedvlm(object, drop = FALSE, type.fitted = NULL,
percentiles = NULL, ...)
a model object that inherits from a VLM.
Logical.
If FALSE
then the answer is a matrix.
If TRUE
then the answer is a vector.
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.
See CommonVGAMffArguments
for details.
Currently unused.
The fitted values evaluated at the final IRLS iteration.
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
Chambers, J. M. and T. J. Hastie (eds) (1992). Statistical Models in S. Wadsworth & Brooks/Cole.
# NOT RUN {
# Categorical regression example 1
pneumo <- transform(pneumo, let = log(exposure.time))
(fit1 <- vglm(cbind(normal, mild, severe) ~ let, propodds, data = 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")) # Equal to the the following two:
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), data = zdata, trace = TRUE)
head(fitted(fit3, type.fitted = "mean" )) # E(Y), which is the default
head(fitted(fit3, type.fitted = "pobs0")) # P(Y = 0)
head(fitted(fit3, type.fitted = "pstr0")) # Prob of a structural 0
head(fitted(fit3, type.fitted = "onempstr0")) # 1 - prob of a structural 0
# }
Run the code above in your browser using DataLab