# \donttest{
library("curesurv")
library("survival")
testiscancer$age_crmin <- (testiscancer$age- min(testiscancer$age)) /
sd(testiscancer$age)
fit_m1_ad_tneh <- curesurv(Surv(time_obs, event) ~ z_tau(age_crmin) +
z_alpha(age_crmin),
pophaz = "ehazard",
cumpophaz = "cumehazard",
model = "nmixture", dist = "tneh",
link_tau = "linear",
data = testiscancer,
method_opt = "L-BFGS-B")
fit_m1_ad_tneh
#' #mean of age
newdata1 <- with(testiscancer,
expand.grid(event = 0, age_crmin = mean(age_crmin), time_obs = seq(0.001,10,0.1)))
pred_agemean <- predict(object = fit_m1_ad_tneh, newdata = newdata1)
#max of age
newdata2 <- with(testiscancer,
expand.grid(event = 0,
age_crmin = max(age_crmin),
time_obs = seq(0.001,10,0.1)))
pred_agemax <- predict(object = fit_m1_ad_tneh, newdata = newdata2)
# predictions at time 2 years and of age
newdata3 <- with(testiscancer,
expand.grid(event = 0,
age_crmin = seq(min(testiscancer$age_crmin),max(testiscancer$age_crmin), 0.1),
time_obs = 2))
pred_age_val <- predict(object = fit_m1_ad_tneh, newdata = newdata3)
#plot of 3 indicators for mean age
plot(pred_agemean, fun="all")
#plot of net survival for mean and maximum age (comparison)
oldpar <- par(no.readonly = TRUE)
par(mfrow = c(2, 2),
cex = 1.0)
plot(pred_agemax$time,
pred_agemax$ex_haz,
type = "l",
lty = 1,
lwd = 2,
xlab = "Time since diagnosis",
ylab = "excess hazard")
lines(pred_agemean$time,
pred_agemean$ex_haz,
type = "l",
lty = 2,
lwd = 2)
legend("topright",
horiz = FALSE,
legend = c("hE(t) age.max = 79.9", "hE(t) age.mean = 50.8"),
col = c("black", "black"),
lty = c(1, 2, 1, 1, 2, 2))
grid()
plot(pred_agemax$time,
pred_agemax$netsurv,
type = "l",
lty = 1,
lwd = 2,
ylim = c(0, 1),
xlab = "Time since diagnosis",
ylab = "net survival")
lines(pred_agemean$time,
pred_agemean$netsurv,
type = "l",
lty = 2,
lwd = 2)
legend("bottomleft",
horiz = FALSE,
legend = c("Sn(t) age.max = 79.9", "Sn(t) age.mean = 50.8"),
col = c("black", "black"),
lty = c(1, 2, 1, 1, 2, 2))
grid()
plot(pred_agemax$time,
pred_agemax$pt_cure,
type = "l",
lty = 1,
lwd = 2,
ylim = c(0, 1), xlim = c(0,30),
xlab = "Time since diagnosis",
ylab = "probability of being cured P(t)")
lines(pred_agemean$time,
pred_agemean$pt_cure,
type = "l",
lty = 2,
lwd = 2)
abline(v = pred_agemean$tau[1],
lty = 2,
lwd = 2,
col = "blue")
abline(v = pred_agemean$TTC[1],
lty = 2,
lwd = 2,
col = "red")
abline(v = pred_agemax$tau[1],
lty = 1,
lwd = 2,
col = "blue")
abline(v = pred_agemax$TTC[1],
lty = 1,
lwd = 2,
col = "red")
grid()
legend("bottomright",
horiz = FALSE,
legend = c("P(t) age.max = 79.9",
"P(t) age.mean = 50.8",
"TNEH age.max = 79.9",
"TTC age.max = 79.9",
"TNEH age.mean = 50.8",
"TTC age.mean = 50.8"),
col = c("black", "black", "blue", "red", "blue", "red"),
lty = c(1, 2, 1, 1, 2, 2))
val_age <- seq(min(testiscancer$age_crmin),
max(testiscancer$age_crmin), 0.1) * sd(testiscancer$age) +
min(testiscancer$age)
pred_age_val <- predict(object = fit_m1_ad_tneh, newdata = newdata3)
par(mfrow=c(2,2))
plot(val_age,
pred_age_val$ex_haz, type = "l",
lty=1, lwd=2,
xlab = "age",
ylab = "excess hazard")
grid()
plot(val_age,
pred_age_val$netsurv, type = "l", lty=1,
lwd=2, xlab = "age", ylab = "net survival")
grid()
plot(val_age,
pred_age_val$pt_cure, type = "l", lty=1, lwd=2,
xlab = "age",
ylab = "P(t)")
grid()
par(oldpar)
# }
Run the code above in your browser using DataLab