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