Learn R Programming

survival (version 2.36-5)

model.matrix.coxph: Model.matrix method for coxph models

Description

Reconstruct the model matrix for a cox model.

Usage

## S3 method for class 'coxph':
model.matrix(object, data, contrast.arg =
 object$contrasts, mf, ...)

Arguments

object
the result of a coxph model
data
optional, a data frame from which to obtain the data
contrast.arg
optional, a contrasts object describing how factors should be coded
mf
an optional model frame. Used interally when programs have already obtained a model frame.
...
other possible argument to model.frame

Value

  • The model matrix for the fit

Details

When there is a data argument this function differs from most of the other model.matrix methods in that the response variable for the original formual is not required to be in the data.

See Also

model.matrix

Examples

Run this code
fit1 <- coxph(Surv(time, status) ~ age + factor(ph.ecog), data=lung)
xfit <- model.matrix(fit1)

fit2 <- coxph(Surv(time, status) ~ age + factor(ph.ecog), data=lung,
                                 x=TRUE)
all.equal(model.matrix(fit1), fit2$x)

Run the code above in your browser using DataLab