# NOT RUN {
# (I) Illustrates smart prediction ,,,,,,,,,,,,,,,,,,,,,,,
pneumo <- transform(pneumo, let = log(exposure.time))
fit <- vglm(cbind(normal, mild, severe) ~
sm.poly(c(sm.scale(let)), 2),
multinomial, data = pneumo, trace = TRUE, x = FALSE)
class(fit)
fit@smart.prediction # Data-dependent parameters
fit@x # Not saved on the object
model.matrix(fit)
model.matrix(fit, linpred.index = 1, type = "lm")
model.matrix(fit, linpred.index = 2, type = "lm")
(Check1 <- head(model.matrix(fit, type = "lm")))
(Check2 <- model.matrix(fit, data = head(pneumo), type = "lm"))
all.equal(c(Check1), c(Check2)) # Should be TRUE
q0 <- head(predict(fit))
q1 <- head(predict(fit, newdata = pneumo))
q2 <- predict(fit, newdata = head(pneumo))
all.equal(q0, q1) # Should be TRUE
all.equal(q1, q2) # Should be TRUE
# (II) Attributes ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
fit2 <- vglm(cbind(normal, mild, severe) ~ let, # x = TRUE
multinomial, data = pneumo, trace = TRUE)
fit2@x # "lm"-type; saved on the object; note the attributes
model.matrix(fit2, type = "lm") # Note the attributes
model.matrix(fit2, type = "vlm") # Note the attributes
# }
Run the code above in your browser using DataLab