model.matrixvlm {VGAM} | R Documentation

## Construct the Design Matrix of a VLM Object

### Description

Creates a design matrix. Two types can be returned: a large one (class `"vlm"` or one that inherits from this such as `"vglm"`) or a small one (such as returned if it were of class `"lm"`).

### Usage

    model.matrixvlm(object, type = c("vlm", "lm", "lm2", "bothlmlm2"),
                    linpred.index = NULL, ...)

### Arguments

`object` | an object of a class that inherits from the vector linear model (VLM).
`type` | Type of design matrix returned. The first is the default. The value `"vlm"` is the VLM model matrix corresponding to the `formula` argument. The value `"lm"` is the LM model matrix corresponding to the `formula` argument. The value `"lm2"` is the second (LM) model matrix corresponding to the `form2` argument. The value `"bothlmlm2"` means both LM and VLM model matrices.
`linpred.index` | Single integer. The index for a linear/additive predictor, it must have a value from the set `1:M`, and `type = "lm"` must be assigned. Then it returns a subset of the VLM matrix corresponding to the `linpred.index`th linear/additive predictor; this is a LM-type matrix.
`...` | further arguments passed to or from other methods. These include `data` (which is a data frame created with `model.framevlm`), `contrasts.arg`, and `xlev`. See `model.matrix` for more information.

### Details

This function creates a design matrix from `object`. This can be a small LM object or a big VLM object (default). The latter is constructed from the former and the constraint matrices.

This code implements smart prediction (see `smartpred`).

### Value

The design matrix for a regression model with the specified formula and data. If `type = "bothlmlm2"` then a list is returned with components `"X"` and `"Xm2"`.

### References

Yee, T. W. and Hastie, T. J. (2003) Reduced-rank vector generalized linear models. Statistical Modelling, 3, 15–41.

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.

### See Also

`model.matrix`, `model.framevlm`, `predictvglm`, `smartpred`.

### Examples

    # Illustrates smart prediction
    pneumo <- transform(pneumo, let = log(exposure.time))
    fit <- vglm(cbind(normal, mild, severe) ~ poly(c(scale(let)), 2),
                multinomial, data = pneumo, trace = TRUE, x = FALSE)
    class(fit)
    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))

    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

[Package VGAM version 1.0-3 Index]