## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 6, fig.height = 4)
library(gcemod)

## ----data---------------------------------------------------------------------
data(hn)
table(hn$status)

## ----cox----------------------------------------------------------------------
fit <- gcecox(Surv(time, status) ~ age + smoker + t_cat + n_cat + p16,
              data = hn, t = 5)
fit

## ----summary------------------------------------------------------------------
s <- summary(fit)
s

## ----extract------------------------------------------------------------------
coef(fit)
confint(fit, exponentiate = TRUE)

## ----fg, eval = FALSE---------------------------------------------------------
# fit_fg <- gcefg(Surv(time, status) ~ age + smoker + t_cat + n_cat + p16,
#                 data = hn, t = 5)
# summary(fit_fg)

## ----rs-----------------------------------------------------------------------
new <- hn[1:3, ]
predict(fit, new, type = "lp")
predict(fit, new, type = "ratio", times = c(2, 5))   # omega+(t)
predict(fit, new, type = "share")                    # omega at t = 5

## ----cut----------------------------------------------------------------------
cuts <- gce_cutpoints(fit, groups = 2, method = "optimal")
cuts

## ----alligator, fig.height=4--------------------------------------------------
plot(gce_alligator(fit, groups = cuts))

## ----calib--------------------------------------------------------------------
cal <- gce_calibration(fit, which = "omegaplus", groups = 5)
cal
plot(cal)

## ----omegatime----------------------------------------------------------------
plot(gce_omegatime(fit, which = "omegaplus", groups = cuts, xmax = 10))

## ----perf---------------------------------------------------------------------
gce_performance(fit)

## ----prostate, eval = FALSE---------------------------------------------------
# data(prostate)
# fit_p <- gcecox(Surv(time, status) ~ age + psa + gleason + t2b + comorbidity,
#                 data = prostate, t = 5)
# summary(fit_p)
# plot(fit_p, which = "alligator", groups = 2)

## ----legacy-------------------------------------------------------------------
Ind <- data.frame(event     = as.integer(hn$status == 1),
                  competing = as.integer(hn$status == 2))
Cov <- hn[, c("age", "smoker", "t_cat", "n_cat", "p16")]
fit_m <- gcecox(hn$time, Ind, Cov, t = 5)
all.equal(coef(fit_m), coef(fit))

