# NOT RUN {
mv.surv <- Surv(martinvanberg$formdur, event = rep(1, nrow(martinvanberg)))
mv.cox <- coxph(mv.surv ~ postel + prevdef + cont + ident + rgovm + pgovno +
tpgovno + minority, method = "breslow", data = martinvanberg)
summary(mv.cox)
# NPSF method
ed1 <- coxed(mv.cox, method="npsf")
ed1$baseline.functions
ed1$exp.dur
summary(ed1, stat="mean")
summary(ed1, stat="median")
# }
# NOT RUN {
ed1 <- coxed(mv.cox, method="npsf", bootstrap = TRUE)
ed1$exp.dur
summary(ed1, stat="mean")
summary(ed1, stat="median")
# }
# NOT RUN {
me <- coxed(mv.cox, method="npsf", bootstrap = FALSE,
newdata = dplyr::mutate(martinvanberg, pgovno=1),
newdata2 = dplyr::mutate(martinvanberg, pgovno=6))
summary(me, stat="mean")
# GAM method
ed2 <- coxed(mv.cox, method="gam")
summary(ed2$gam.data)
summary(ed2$gam.model)
ed2$exp.dur
summary(ed2, stat="mean")
# }
# NOT RUN {
me <- coxed(mv.cox, method="gam", bootstrap = TRUE,
newdata = dplyr::mutate(martinvanberg, pgovno=1),
newdata2 = dplyr::mutate(martinvanberg, pgovno=6))
summary(me, stat="mean")
summary(me, stat="median")
# }
# NOT RUN {
#Plotting the GAM fit
# }
# NOT RUN {
ggplot(ed2$gam.data, aes(x=rank.xb, y=y)) +
geom_point() +
geom_line(aes(x=rank.xb, y=gam_fit)) +
geom_ribbon(aes(ymin=gam_fit_95lb, ymax=gam_fit_95ub), alpha=.5) +
xlab("Cox model LP rank (smallest to largest)") +
ylab("Duration")
# }
# NOT RUN {
#Time-varying covariates
bs.surv <- Surv(time = boxsteffensmeier$start, time2 = boxsteffensmeier$te,
event = boxsteffensmeier$cut_hi)
bs.cox <- coxph(bs.surv ~ ec + dem + south + iv, data = boxsteffensmeier, method = "breslow")
summary(bs.cox)
ed1 <- coxed(bs.cox, method="npsf", id=boxsteffensmeier$caseid)
ed1$exp.dur
summary(ed1, stat="mean")
# }
Run the code above in your browser using DataLab