Learn R Programming

prodlim (version 1.4.5)

model.design: Extract a design matrix and specials from a model.frame

Description

Extract design matrix and data specials from a model.frame

Usage

model.design(data, xlev, dropIntercept = FALSE, maxOrder = 1,
  unspecialsDesign = TRUE, specialsFactor = TRUE, specialsDesign = FALSE,
  stripSpecialNames = TRUE)

Arguments

data
A model.frame
xlev
Passed to model.matrix
dropIntercept
If TRUE drop intercept term from the design matrix
maxOrder
An error is produced if special variables are involved in interaction terms of order higher than max.order.
unspecialsDesign
A logical value: if TRUE apply model.matrix to unspecial covariates. If FALSE extract unspecial covariates from data.
specialsFactor
A character vector containing special variables which should be coerced into a single factor. If TRUE all specials are treated in this way.
specialsDesign
A character vector containing special variables which should be transformed into a design matrix via model.matrix. If TRUE all specials are treated in this way.
stripSpecialNames
If TRUE strip the special from variable name, i.e., use X instead of strata(X).

Value

  • A list which contains - the design matrix with the levels of the variables stored in attribute 'levels' - separate data.frames which contain the values of the special variables.

Details

The function untangle.specials of the survival function does a similar job.

See Also

EventHistory.frame model.frame terms model.matrix .getXlevels

Examples

Run this code
f <- formula(y~x+ID(z))
set.seed(8)
d <- data.frame(y=rnorm(5),x=factor(c("a","b","b","a","c")),z=c(2,2,7,7,7))
ID <- function(x)x
t <- terms(f,special="ID",data=d)
m <- model.frame(t,d)
md <- model.design(m,specialsFactor=TRUE)
md
md <- model.design(m,specialsFactor=TRUE,unspecialsDesign=FALSE)
md

# special function with argument
treat <- function(x,...) x
f2 <- formula(y~x+treat(z,arg=2)+treat(u,arg=-1))
set.seed(8)
d <- data.frame(y=rnorm(5),u=1:5,x=factor(c("a","b","b","a","c")),z=c(2,2,7,7,7))
t2 <- terms(f2,special="treat",data=d)
m2 <- model.frame(t2,d)
md2 <- model.design(m2,specialsFactor=TRUE)

library(survival)
data(pbc)
tt <- terms(Surv(time,status!=0)~factor(edema)*age+strata(I(log(bili)>1))+strata(sex)+cluster(id),
special=c("strata","cluster"),data=pbc[1:10,])
dd <- model.frame(tt,data=pbc[1:10,])
model.design(dd)
model.design(dd,dropIntercept=TRUE)

Run the code above in your browser using DataLab