# NOT RUN {
set.seed(34)
sim_data <- sim_data_nll_basic(
a1 = 2.5, b1 = 0.9, n1 = 100, d1 = "Weibull",
a2 = 2.0, b2 = 0.5, n2 = 100, d2 = "Weibull",
t_censor = 14)
head(sim_data, 10)
sim_data$time[sim_data$infected_treatment == 0]
sim_data$time[sim_data$infected_treatment == 1]
# plot histogram for ages at death in infected population
hist(
sim_data$time[(sim_data$infected_treatment == 1 & sim_data$censor == 0)],
breaks = seq(0, 14, 1),
xlim = c(0, 15),
main = 'infected, died',
xlab = 'time of death',
xaxt = 'n')
axis(side = 1, tick = TRUE, at = seq(0, 14, 1))
# estimate location and scale parameters of simulated data with nll_basic
m01_prep_function <- function(a1, b1, a2, b2){
nll_basic(a1, b1, a2, b2,
data = sim_data,
time = time,
censor = censor,
infected_treatment = infected_treatment,
d1 = 'Weibull', d2 = 'Weibull'
)}
m01 <- mle2(m01_prep_function,
start = list(a1 = 2, b1 = 1, a2 = 2, b2 = 1)
)
confint(m01)
# estimate using 'mid_time' instead of 'time'
m02_prep_function <- function(a1, b1, a2, b2){
nll_basic(a1, b1, a2, b2,
data = sim_data,
time = mid_time,
censor = censor,
infected_treatment = infected_treatment,
d1 = 'Weibull', d2 = 'Weibull'
)}
m02 <- mle2(m02_prep_function,
start = list(a1 = 2, b1 = 1, a2 = 2, b2 = 1)
)
confint(m02)
# compare estimates
AICc(m01, m02, nobs = 200)
# for these data, m02 based on 'mid-time' provides a better
# description of the data
# }
Run the code above in your browser using DataLab