View source: R/add-functions.R
| add_trans_prob | R Documentation |
add_trans_prob adds transition probabilities on the provided data set and model.
Optionally, confidence intervals (CI) are added if ci=TRUE.
The function builds on cumulative hazards cumu_hazard and mgcv::gam models.
add_trans_prob(
newdata,
object,
overwrite = FALSE,
ci = FALSE,
alpha = 0.05,
nsim = 100L,
time_var = NULL,
interval_length = "intlen",
...
)
newdata |
A data frame or list containing the values of the model covariates at which predictions are required. If this is not provided then predictions corresponding to the original data are returned. If newdata is provided then it should contain all the variables needed for prediction: a warning is generated if not. See details for use with linear.functional.terms. |
object |
A fitted |
overwrite |
Should transition probability columns be overwritten if
already present in the data set? Defaults to |
ci |
|
alpha |
Sets the confidence intervals' |
nsim |
Sets the number of iterations for simulated confidence intervals.
Defaults to |
time_var |
Name of the variable used for the baseline hazard. If
not given, defaults to |
interval_length |
|
... |
Further arguments passed to underlying methods. |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.