# NOT RUN {
# }
# NOT RUN {
library(PermAlgo)
library(survival)
library(ggplot2)
pcoxtheme()
set.seed(123407)
# Simulate with default values
df <- simtdc()
head(df$data)
# Simulate for a number of times to check stability of the estimates
nrep <- 500
betas <- log(runif(6, 0, 2))
beta_list <- list()
true_list <- list()
for (i in 1:nrep){
sim <- simtdc(pfixed = 3, ptdc = 2, pbin = 1, betas = betas)
df <- sim$data
vnames <- colnames(df)[!colnames(df) %in% c("Id", "Fup")]
df <- df[ ,vnames]
# Estimate coefficients using coxph
mod <- coxph(Surv(Start, Stop, Event) ~ ., df)
beta_list[[i]] <- coef(mod)
true_list[[i]] <- sim$betas
}
beta_df <- data.frame(do.call("rbind", beta_list))
beta_df <- stack(beta_df)
true_df <- data.frame(ind = names(true_list[[1]]), values = true_list[[1]])
p1 <- (ggplot(beta_df, aes(x = values))
+ geom_histogram(alpha = 0.3)
+ geom_vline(data = true_df, aes(xintercept = values), col = "blue")
+ facet_wrap(~ind, scales = "free")
+ labs(x = "Beta estimate", y = "")
)
print(p1)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab