Construct the Model Frame of a VLM Object
model.framevlm.RdThis function returns a data.frame with the
variables. It is applied to an object which inherits from
class "vlm" (e.g., a fitted model of class "vglm").
Arguments
- object
a model object from the VGAM R package that inherits from a vector linear model (VLM), e.g., a model of class
"vglm".- ...
further arguments such as
data,na.action,subset. Seemodel.framefor more information on these.- setupsmart, wrapupsmart
Logical. Arguments to determine whether to use smart prediction.
Details
Since object is
an object which inherits from class "vlm" (e.g.,
a fitted model of class "vglm"),
the method will either returned the saved model frame
used when fitting the model (if any, selected by argument
model = TRUE) or pass the call used when fitting on to
the default method.
This code implements smart prediction
(see smartpred).
Value
A data.frame containing the variables used in
the object plus those specified in ....
References
Chambers, J. M. (1992). Data for models. Chapter 3 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Examples
# Illustrates smart prediction
pneumo <- transform(pneumo, let = log(exposure.time))
fit <- vglm(cbind(normal,mild, severe) ~ poly(c(scale(let)), 2),
multinomial, pneumo, trace = TRUE, x = FALSE)
#> Iteration 1: deviance = 3.716285
#> Iteration 2: deviance = 3.499289
#> Iteration 3: deviance = 3.487318
#> Iteration 4: deviance = 3.487262
#> Iteration 5: deviance = 3.487262
class(fit)
#> [1] "vglm"
#> attr(,"package")
#> [1] "VGAM"
check1 <- head(model.frame(fit))
check1
#> cbind(normal, mild, severe).normal cbind(normal, mild, severe).mild
#> 1 98 0
#> 2 51 2
#> 3 34 6
#> 4 35 5
#> 5 32 10
#> 6 23 7
#> cbind(normal, mild, severe).severe poly(c(scale(let)), 2).1
#> 1 0 -0.77195016
#> 2 1 -0.27226249
#> 3 3 -0.08294405
#> 4 8 0.04649255
#> 5 9 0.15028005
#> 6 8 0.23692162
#> poly(c(scale(let)), 2).2
#> 1 0.50285988
#> 2 -0.43378435
#> 3 -0.42122091
#> 4 -0.29641247
#> 5 -0.12815229
#> 6 0.05878623
check2 <- model.frame(fit, data = head(pneumo))
check2
#> cbind(normal, mild, severe).normal cbind(normal, mild, severe).mild
#> 1 98 0
#> 2 51 2
#> 3 34 6
#> 4 35 5
#> 5 32 10
#> 6 23 7
#> cbind(normal, mild, severe).severe poly(c(scale(let)), 2).1
#> 1 0 -0.79735249
#> 2 1 -0.19033917
#> 3 3 0.03964213
#> 4 8 0.19687984
#> 5 9 0.32295938
#> 6 8 0.42821031
#> poly(c(scale(let)), 2).2
#> 1 0.43043654
#> 2 -0.57044185
#> 3 -0.41509933
#> 4 -0.13981459
#> 5 0.18011485
#> 6 0.51480438
all.equal(unlist(check1), unlist(check2)) # Should be TRUE
#> [1] "Mean relative difference: 0.5527089"
q0 <- head(predict(fit))
q1 <- head(predict(fit, newdata = pneumo))
q2 <- predict(fit, newdata = head(pneumo))
all.equal(q0, q1) # Should be TRUE
#> [1] TRUE
all.equal(q1, q2) # Should be TRUE
#> [1] "Mean relative difference: 0.2835235"