sample_posterior {oncomsm}R Documentation

Sample parameters from a model

Description

sample_posterior() draws samples from the posterior distribution of the specified model given a data set with visit data.

sample_prior() draws samples from the prior distribution of the specified model object.

Usage

sample_posterior(
  model,
  data,
  now = NULL,
  nsim = 2000L,
  seed = NULL,
  warmup = 500L,
  nuts_control = list(),
  acceptable_divergent_transition_fraction = 0.1,
  ...
)

sample_prior(
  model,
  nsim = 2000L,
  seed = NULL,
  warmup = 500L,
  nuts_control = list(),
  ...
)

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".

now

numeric, time from first visit in data if different form last recorded visit

nsim

integer, number of samples to draw

seed

integer, fixed random seed; NULL for no fixed seed

warmup

integer, number of warm-up samples for the MCMC sampler before retaining samples; see warmup parameter in rstan::stan().

nuts_control

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

acceptable_divergent_transition_fraction

numeric between 0 and 1 giving the acceptable fraction of divergent transitions before throwing an error

...

further arguments passed to method implementations

Value

A rstan::stanfit object with posterior samples.

See Also

rstan::stan() parameter_sample_to_tibble() sample_predictive() impute()

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", "response")
)
sample_posterior(mdl, tbl, seed = 42L)

sample_prior(mdl, seed = 42L)


[Package oncomsm version 0.1.4 Index]