Skip to contents

impute() samples visits for individuals in data and potentially missing individuals up to a maximum of n_per_group from the posterior predictive distribution of the given model.

sample_predictive() draws samples from the predictive distribution of a model given a parameter sample.

Usage

impute(
  model,
  data,
  nsim,
  n_per_group = NULL,
  sample = NULL,
  p = NULL,
  shape = NULL,
  scale = NULL,
  now = NULL,
  seed = NULL,
  nsim_parameters = 1000L,
  warmup_parameters = 250L,
  nuts_control = list(),
  as_mstate = FALSE,
  ...
)

sample_predictive(
  model,
  nsim,
  n_per_group,
  sample = NULL,
  p = NULL,
  shape = NULL,
  scale = NULL,
  seed = NULL,
  nsim_parameters = 1000L,
  warmup_parameters = 250,
  nuts_control = list(),
  as_mstate = FALSE,
  ...
)

Arguments

model

an object of class srpmodel containing prior information

data

a data frame with variables subject_id<chr> (subject identifier), group_id<chr> (group identifier), t<dbl> (time of visit, relative to first visit in study), state<chr> (state recorded at visit). Allowed states are "stable", "response", "progression" (or death), and "EOF" (end of follow-up). The EOF state marks the end of an individual's follow-up before the absorbing state "progression".

nsim

integer, number of samples to draw

n_per_group

integer vector with number of individuals per group.

sample

a stanfit object with samples from the respective model.

p

numeric, vector of optional fixed response probabilities to use for sampling

shape

numeric, matrix of optional fixed Weibull shape parameters to use for sampling must be a matrix of dim c(n_groups, 3) where the second dimension corresponds to the transitions between s->r, s->p, r->p

scale

numeric, matrix of optional fixed Weibull scale parameters to use for sampling must be a matrix of dim c(n_groups, 3) where the second dimension corresponds to the transitions between s->r, s->p, r->p

now

numeric, time since first visit in data if not last recorded visit time

seed

integer, fixed random seed; NULL for no fixed seed

nsim_parameters

integer, number of parameter samples

warmup_parameters

integer, number of warmup samples for the rstan sampler before retaining samples of the parameters.

nuts_control

list, parameters for NUTS algorithm see control argument inrstan::stan()

as_mstate

logical, return data in mstate format?

...

further arguments passed to method implementations

Value

a data frame with variables subject_id<chr> (subject identifier), group_id<chr> (group identifier), t<dbl> (time of visit, relative to first visit in study), state<chr> (state recorded at visit) iter<int> (re-sample indicator). Allowed states are "stable", "response", "progression" (or death), and "EOF" (end of follow-up). The EOF state marks the end of an individual's follow-up before the absorbing state "progression".

Examples

mdl <- create_srpmodel(A = define_srp_prior())
tbl <- tibble::tibble(
  subject_id = c("A1", "A1"),
  group_id = c("A", "A"),
  t = c(0, 1.5),
  state = c("stable", "stable")
)
impute(mdl, tbl, 1L, seed = 38L)
#> # A tibble: 16 × 5
#>    subject_id group_id     t state        iter
#>    <chr>      <chr>    <dbl> <chr>       <int>
#>  1 A1         A          0   stable          1
#>  2 A1         A          1.5 stable          1
#>  3 A1         A          2.5 stable          1
#>  4 A1         A          3.5 stable          1
#>  5 A1         A          4.5 stable          1
#>  6 A1         A          5.5 stable          1
#>  7 A1         A          6.5 stable          1
#>  8 A1         A          7.5 stable          1
#>  9 A1         A          8.5 response        1
#> 10 A1         A          9.5 response        1
#> 11 A1         A         10.5 response        1
#> 12 A1         A         11.5 response        1
#> 13 A1         A         12.5 response        1
#> 14 A1         A         13.5 response        1
#> 15 A1         A         14.5 response        1
#> 16 A1         A         15.5 progression     1

sample_predictive(mdl, 1L, 20L, seed = 38L)
#> # A tibble: 1,507 × 5
#>    subject_id group_id     t state   iter
#>    <chr>      <chr>    <dbl> <chr>  <int>
#>  1 ID00969187 A         26.7 stable     1
#>  2 ID00969187 A         27.7 stable     1
#>  3 ID00969187 A         28.7 stable     1
#>  4 ID00969187 A         29.7 stable     1
#>  5 ID00969187 A         30.7 stable     1
#>  6 ID00969187 A         31.7 stable     1
#>  7 ID00969187 A         32.7 stable     1
#>  8 ID00969187 A         33.7 stable     1
#>  9 ID00969187 A         34.7 stable     1
#> 10 ID00969187 A         35.7 stable     1
#> # ℹ 1,497 more rows