# NOT RUN {
# Load Carpenter (2002) data
data("CarpenterFdaData")
# Load survival package
library(survival)
# Run basic model
M1 <- coxph(Surv(acttime, censor) ~ lethal*prevgenx,
data = CarpenterFdaData)
# Simulate Marginal Effect of lethal for multiple values of prevgenx
Sim1 <- coxsimInteract(M1, b1 = "lethal", b2 = "prevgenx",
X2 = seq(2, 115, by = 2), nsim = 100)
# Plot quantities of interest
simGG(Sim1)
simGG(Sim1, rug_position = 'jitter')
# }
# NOT RUN {
# Change the order of the covariates to make a more easily
# interpretable hazard ratio graph.
M2 <- coxph(Surv(acttime, censor) ~ prevgenx*lethal,
data = CarpenterFdaData)
# Simulate Hazard Ratio of lethal for multiple values of prevgenx
Sim2 <- coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = seq(2, 115, by = 2),
X2 = c(0, 1),
qi = "Hazard Ratio", ci = 0.9)
# Simulate First Difference
Sim3 <- coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = seq(2, 115, by = 2),
X2 = c(0, 1),
qi = "First Difference", spin = TRUE)
# Simulate Hazard Rate
Sim4 <- coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = 100, X2 = 1, qi = "Hazard Rate")
# Plot quantities of interest
simGG(Sim1, xlab = "\nprevgenx",
ylab = "Marginal Effect of lethal\n")
simGG(Sim2, type = 'ribbons', rug_position = 'jitter')
simGG(Sim3)
simGG(Sim4, to = 150, type = 'lines', legend = FALSE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab