require(survival)
set.seed(2100)
##Generating covariates
n=20
x<-runif(n, max=10)
lambda<-exp(1.2-0.5*x)
sigma<-1.5
##Drawing T from Weibull model and fixing censoring at 1.5
T<-rweibull(n, shape=1/sigma, scale=lambda)
L<-rep(1.5, n)
##Defining the observed times and indicators of failure
t<-pmin(T,L)
delta<-ifelse(T<=L, 1, 0)
data=data.frame(t=t, delta=delta, x=x)
##Fitting for Weibull regression model
##Traditional MLE with corrected variance
ex1=weibfit(Surv(t,delta)~x, data=data, L=L, estimator="MLE",
corrected.var=TRUE)
summary(ex1)
##BCE without corrected variance
ex2=weibfit(Surv(t,delta)~x, data=data, L=L, estimator="Firth",
corrected.var=FALSE)
summary(ex2)
##BCE with corrected variance
ex3=weibfit(Surv(t,delta)~x, data=data, L=L, estimator="BCE",
corrected.var=TRUE)
summary(ex3)
##Firth's correction without corrected variance
ex4=weibfit(Surv(t,delta)~x, data=data, L=L, estimator="BCE",
corrected.var=FALSE)
summary(ex4)
Run the code above in your browser using DataLab