model.matrix.tramME: Model matrices for 'tramME' models

View source: R/terms.R

model.matrix.tramMER 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:

  • Ye: Exact observations.

  • Yeprime: The model matrix corresponding to the first derivative of the baseline transformation, evaluated at exact observations.

  • Yl: Left-censored observations.

  • Yr: Rigt-censored observations.

  • Yil and Yir: Interval-censored observations evaluated at the left and right bounds of the interval.

  • Ytl: Left-truncated observations.

  • Ytr: Rigt-truncated observations.

  • Ytil and Ytir: Interval-truncated observations evaluated at the left and right bounds of the interval.

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

tramME documentation built on July 9, 2023, 7:10 p.m.