Creates a stacked area plot of state occupation probabilities over time, computed from transition probability matrices stored as an attribute of the input data. Optionally facets by a grouping variable.
gg_state_occupation(
newdata,
init_state,
group_var = NULL,
time_var = "tend",
ncol = NULL
)A data frame with an attribute matrix containing
a data frame with a column trans_prob_matrix. Each element of
trans_prob_matrix should be a 3-dimensional array of dimensions
n_states x n_states x n_timepoints.
A numeric vector specifying the initial state distribution.
Should sum to 1 and have length equal to the number of states. For example,
c(0, 1, 0, 0) places all subjects in state 2 at baseline.
A character string giving the name of the column in
newdata to facet by (e.g., "treat"). If NULL
(default), no faceting is applied.
A character string giving the name of the time variable in
newdata. Defaults to "tend".
An integer specifying the number of columns in the facet wrap.
If NULL (default), defaults to the number of unique groups.
A ggplot object showing stacked-area state occupation
probabilities over time, optionally faceted by group_var.