model.matrix.jmdem {jmdem} | R Documentation |
Construct Design Matrices
Description
model.matrix
creates a design (or model) matrix, e.g., by expanding factors to a set of dummy variables (depending on the contrasts) and expanding interactions similarly.
Usage
## S3 method for class 'jmdem'
model.matrix(object, submodel = c("both", "mean", "dispersion"), ...)
Arguments
object |
the function family accesses the family objects which are stored within objects created by |
submodel |
character. The family of the specified submodel. For |
... |
further arguments passed to or from other methods. |
Details
model.matrix
creates a design matrix from the description given in terms(object)
, using the data in data
which must supply variables with the same names as would be created by a call to model.frame(object)
or, more precisely, by evaluating attr(terms(object), "variables")
.
Value
The design matrix for a regression-like model with the specified formula and data.
There is an attribute "assign
", an integer vector with an entry for each column in the matrix giving the term in the formula which gave rise to the column. Value 0
corresponds to the intercept (if any), and positive values to terms in the order given by the term.labels
attribute of the terms
structure corresponding to object.
If there are any factors in terms in the model, there is an attribute "contrasts
", a named list with an entry for each factor. This specifies the contrasts that would be used in terms in which the factor is coded by contrasts (in some terms dummy coding may be used), either as a character vector naming a function or as a numeric matrix.
Author(s)
Karl Wu Ka Yui (karlwuky@suss.edu.sg)
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.
See Also
model.frame
, model.extract
, terms
Examples
## Example in jmdem(...)
MyData <- simdata.jmdem.sim(mformula = y ~ x, dformula = ~ z,
mfamily = poisson(),
dfamily = Gamma(link = "log"),
beta.true = c(0.5, 4),
lambda.true = c(2.5, 3), n = 100)
fit <- jmdem(mformula = y ~ x, dformula = ~ z, data = MyData,
mfamily = poisson, dfamily = Gamma(link = "log"),
dev.type = "deviance", method = "CG")
## Extract the design matrix of the mean submodel
model.matrix(fit, submodel = "mean")