if (FALSE) { # require("mstate")
data("prothr", package = "mstate")
prothr <- prothr |>
mutate(transition = as.factor(paste0(from, "->", to))
, treat = as.factor(treat)) |>
filter(Tstart != Tstop, id <= 100) |> select(-trans)
ped <- as_ped(data= prothr, formula= Surv(Tstart, Tstop, status)~ .,
transition = "transition", id= "id", timescale = "calendar")
pam <- mgcv::bam(ped_status ~ s(tend, by=transition) + transition * treat,
data = ped, family = poisson(), offset = offset,
method = "fREML", discrete = TRUE)
ndf <- make_newdata(ped, tend = unique(tend),
treat = unique(treat),
transition = unique(transition)) |>
group_by(treat, transition) |> # important!
arrange(treat, transition, tend) |>
add_trans_prob(pam)
}
Run the code above in your browser using DataLab