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, ...)

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.

References

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

Author

Thomas W. Yee

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.

Examples

# Categorical regression example 1
pneumo <- transform(pneumo, let = log(exposure.time))
(fit1 <- vglm(cbind(normal, mild, severe) ~ let, propodds, pneumo))
#> 
#> Call:
#> vglm(formula = cbind(normal, mild, severe) ~ let, family = propodds, 
#>     data = pneumo)
#> 
#> 
#> Coefficients:
#> (Intercept):1 (Intercept):2           let 
#>     -9.676093    -10.581725      2.596807 
#> 
#> Degrees of Freedom: 16 Total; 13 Residual
#> Residual deviance: 5.026826 
#> Log-likelihood: -25.09026 
fitted(fit1)
#>      normal        mild      severe
#> 1 0.9940077 0.003560995 0.002431267
#> 2 0.9336285 0.038433830 0.027937700
#> 3 0.8467004 0.085093969 0.068205607
#> 4 0.7445575 0.133635126 0.121807334
#> 5 0.6358250 0.176154091 0.188020946
#> 6 0.5323177 0.205582603 0.262099709
#> 7 0.4338530 0.220783923 0.345363119
#> 8 0.3636788 0.222017003 0.414304232

# LMS quantile regression example 2
fit2 <- vgam(BMI ~ s(age, df = c(4, 2)),
             lms.bcn(zero = 1), data = bmi.nz, trace = TRUE)
#> VGAM  s.vam  loop  1 :  loglikelihood = -6429.7568
#> VGAM  s.vam  loop  2 :  loglikelihood = -6327.3502
#> VGAM  s.vam  loop  3 :  loglikelihood = -6313.2224
#> VGAM  s.vam  loop  4 :  loglikelihood = -6312.8069
#> VGAM  s.vam  loop  5 :  loglikelihood = -6312.8166
#> VGAM  s.vam  loop  6 :  loglikelihood = -6312.8032
#> VGAM  s.vam  loop  7 :  loglikelihood = -6312.8088
#> VGAM  s.vam  loop  8 :  loglikelihood = -6312.8062
#> VGAM  s.vam  loop  9 :  loglikelihood = -6312.8074
#> VGAM  s.vam  loop  10 :  loglikelihood = -6312.8068
#> VGAM  s.vam  loop  11 :  loglikelihood = -6312.8071
#> VGAM  s.vam  loop  12 :  loglikelihood = -6312.807
head(predict(fit2, type = "response"))  # Equals to both these:
#>        25%      50%      75%
#> 1 23.00836 25.48922 28.44767
#> 2 23.65211 26.19783 29.23269
#> 3 24.07328 26.66334 29.75085
#> 4 23.25503 25.75937 28.74518
#> 5 24.53531 27.17650 30.32525
#> 6 23.63164 26.17517 29.20742
head(fitted(fit2))
#>        25%      50%      75%
#> 1 23.00836 25.48922 28.44767
#> 2 23.65211 26.19783 29.23269
#> 3 24.07328 26.66334 29.75085
#> 4 23.25503 25.75937 28.74518
#> 5 24.53531 27.17650 30.32525
#> 6 23.63164 26.17517 29.20742
predict(fit2, type = "response", newdata = head(bmi.nz))
#>        25%      50%      75%
#> 1 23.00853 25.48943 28.44792
#> 2 23.65207 26.19779 29.23264
#> 3 24.07313 26.66317 29.75064
#> 4 23.25511 25.75947 28.74530
#> 5 24.53487 27.17599 30.32464
#> 6 23.63160 26.17513 29.20738

# 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)
#> Iteration 1: loglikelihood = -1414.8385
#> Iteration 2: loglikelihood = -1396.4301
#> Iteration 3: loglikelihood = -1395.4193
#> Iteration 4: loglikelihood = -1395.4127
#> Iteration 5: loglikelihood = -1395.4127
head(fitted(fit3, type.fitted = "mean" ))  # E(Y) (the default)
#>        [,1]
#> 1 1.9440657
#> 2 1.9119640
#> 3 0.5408033
#> 4 0.9011257
#> 5 0.9424658
#> 6 2.1448683
head(fitted(fit3, type.fitted = "pobs0"))  # Pr(Y = 0)
#>        [,1]
#> 1 0.4063808
#> 2 0.4081623
#> 3 0.6464555
#> 4 0.5331919
#> 5 0.5237346
#> 6 0.3967527
head(fitted(fit3, type.fitted = "pstr0"))  # Prob of a structural 0
#>        [,1]
#> 1 0.3793010
#> 2 0.3797245
#> 3 0.4122719
#> 4 0.3990160
#> 5 0.3978574
#> 6 0.3768047
head(fitted(fit3, type.fitted = "onempstr0"))  # 1 - Pr(structural 0)
#>        [,1]
#> 1 0.6206990
#> 2 0.6202755
#> 3 0.5877281
#> 4 0.6009840
#> 5 0.6021426
#> 6 0.6231953