1

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)
r2evans
  • 141,215
  • 6
  • 77
  • 149
B. Smith
  • 11
  • 1
  • Tangent: don't use `require`, use `library`. Ref: https://stackoverflow.com/a/51263513/3358272 – r2evans Dec 30 '20 at 02:52
  • I get error for the line `fit1=cph(Surv(dt,e)~age,data)`. It returns `Error in Ops.units(time, origin) : both operands of the expression should be "units" objects` – Ronak Shah Dec 30 '20 at 06:10

0 Answers0