model.matrix.tramME {tramME}R Documentation

Model matrices for tramME models

Description

Model matrix for fixed effects, random effects, and baseline transformations (with interacting terms if present).

Usage

## S3 method for class 'tramME'
model.matrix(
  object,
  data = model.frame(object),
  type = c("Y", "X", "Zt"),
  drop_unused_groups = FALSE,
  keep_sign = TRUE,
  simplify = FALSE,
  ...
)

Arguments

object

A tramME object.

data

A data.frame containing the variable values.

type

"X": Fixed effects model matrix. "Zt": Random effects model matrix (transposed). "Y": Model matrices for the baseline transfromations.

drop_unused_groups

Logical; remove unused levels of the random effects. (see drop.unused.levels argument of mkReTrms)

keep_sign

Logical; the terms will have the same sign as in the tramME model if TRUE.

simplify

Logical; Remove empty Y matrices.

...

Optional arguments.

Details

Creates model matrices for fixed effects (type = "X") and random effects (type = "Zt") and baseline transfromation (type = "Y"), by evaluating the respective basis functions given a new dataset.

The response values may be exact, censored (left, right, interval) and truncated (left, right, interval), and the function returns several, potentially empty, model matrices:

for the baseline transfromations (unless simplify = TRUE).

Value

List of requested model matrices.

Note

The model matrix of the random effects is a sparse matrix and it is transposed to be directly used with Matrix::crossprod which is faster than transposing and multiplying ("Zt" instead of "Z").

Examples

library("survival")
rats$litter <- factor(rats$litter)
m <- CoxphME(Surv(time, status) ~ rx + (1 | litter), data = rats,
             log_first = TRUE, nofit = TRUE)
mm <- model.matrix(m)
nd <- model.frame(m)[rep(1, 100), ]
nd[[1]] <- seq(1, 120, length.out = 100)
mm2 <- model.matrix(m, data = nd, simplify = TRUE)
mm3 <- model.matrix(m, data = nd, simplify = TRUE, drop_unused_groups = TRUE)
## compare mm2$Zt & mm3$Zt

[Package tramME version 1.0.5 Index]