I am new to R syntax and trying to use the CsChange package to generate the difference in the c-statistic between two logistic regression models. I am using the example in the CsChange package but get the error
Error in `[.data.frame`(data, , all) : undefined columns selected"
when I attempt to apply this data to lrm
.
library(rms)
library(CsChange)
require("rms")
set.seed(123)
n=50
age=50+12*rnorm(n)
sex=factor(sample(c('Male','Female'), n,rep=TRUE, prob=c(.6, .4)))
cens=15*runif(n)
h=.02*exp(.04*(age-50)+.8*(sex=='Female'))
dt=-log(runif(n))/h
e=ifelse(dt <= cens,1,0)
dt=pmin(dt, cens)
units(dt)="Year"
data=data.frame(dt=dt,e=e,dt1=dt,dt2=dt,e1=e,e2=e,age,sex)
dd=datadist(age, sex)
options(datadist='dd')
#for 'cph' model
fit1=cph(Surv(dt,e)~age,data)
fit2=cph(Surv(dt,e)~age+sex,data)
CsChange(fit1,fit2,data=data,nb=20)
#for 'coxph' model
fit1=coxph(Surv(dt,e)~age,data)
fit2=coxph(Surv(dt,e)~age+sex,data)
CsChange(fit1,fit2,data=data,nb=20)
fit1<-lrm(e~age,data, x=T, y=T)
fit2<-lrm(e~age+sex,data, x=T, y=T)
CsChange(fit1,fit2,data=data,nb=20)