0

I recently use the R "sim.survdata" function in "coxed" package to simulate survival data. I did 2k simulations with one covariate and coefficient = 1. Each time I fitted a Cox regression and recorded the estimated beta and 95% CI. However the mean(betahat) doesn't equal to 1, and CIs do not cover 1 at 95% times. Please see the codes I used below. I wonder the reasons, any input is welcomed. Thank you in advance.

bhat=NULL
lb=NULL
ub=NULL
for(i in 1:2000){
set.seed(20110312+i)
simdata <- sim.survdata(N=2633, T=200, xvars=1, censor=.85, num.data.frames = 1, beta = 1)
simdata$data$event=as.numeric(simdata$data$failed)
fit=coxph(Surv(y,event==1)~X,data=simdata$data)
bhat=c(bhat,summary(fit)$coefficients[1])
lb=c(lb,log(summary(fit)$conf.int[3]))
ub=c(ub,log(summary(fit)$conf.int[4]))
}

> mean(bhat)
[1] 0.9408025
> mean(lb<=1 & ub>=1)
[1] 0.904
Weiyu Qiu
  • 11
  • 1
  • Please include toy data so that others can test your code and alternative code. Please see here for how to create a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – Josh Mar 18 '21 at 22:24
  • Thank you for your comment. This is simulation data with set seeds, so you can run the codes and get identical results as I did without any input data. I realize 2000 iteration may take relatively long time to run, but if you try e.g. 500 iterations (i=1:500) you will still find mean(bhat) not equal to 1, and mean(lb<=1 & ub>=1) not equal to 95%. – Weiyu Qiu Mar 19 '21 at 02:41
  • Looks good. Please add `library(coxed)` to your code or change `sim.survdata` to `coxed::sim.survdata`; as currently written, your code gives the error `could not find function "sim.survdata"` when run in a new R session. – Josh Mar 20 '21 at 03:16

0 Answers0