Applied to an object of type stansim_simulation, extract_data() will return the object's simulation data as a dataframe, subject to the filtering specified by the function arguments.

# S3 method for stansim_simulation
extract_data(object, datasets = "all",
  parameters = "all", estimates = "all", values = NULL,
  param_expand = TRUE, ...)

Arguments

object

An object of S3 class stansim_simulation.

datasets

Either a character vector containing the names of datasets (as provided to the original fit_models() call) fitted, or the string "all". The former will only return values for the corresponding datasets, the latter applies no filtering on datasets

parameters

Either a character vector containing the names of stan model parameters present in the fitted stan models, or the string "all". The former will only return values for the corresponding parameters, the latter applies no filtering on parameters. See also the effect of the param_expand argument.

estimates

Either a character vector containing the names of parameter estimates calculated (e.g. c("2.5 "all". The former will only return values for the corresponding estimates, the latter applies no filtering on estimates

values

Either a function taking a single numeric argument that returns a Boolean value, or NULL. The former will only return values for which the provided function is TRUE, the latter applies no filtering on values.

param_expand

If TRUE then any provided parameters arguments, without specified dimension, will be expanded to capture all dimensions of that parameter. For example, "eta" becomes c("eta[1]", "eta[2]", "eta[3]", ...). Expansion isn't carried out if a parameters dimension is specified (e.g. parameters = "eta[1]") or if param_expand = FALSE.

...

other arguments not used by this method

Value

A dataframe containing the specified data.

Examples

# NOT RUN {
# extract full dataset
extract_data(simulation)

# extract all parameter means, 2.5% & 97.5% percentiles
extract_data(simulation, estimates = c("2.5%", "mean", "97.5%"))

# extract all Rhat estimates greater than 1.1
extract_data(simulation, estimates = "Rhat",
             values = function(x) x > 1.1)

# extract all "eta" parameters
extract_data(simulation, parameters = "eta")

# extract all "eta[1]" parameters
extract_data(simulation, parameters = "eta[1]",
             param_expand = FALSE)

# extract all rows for dataset "data_file-12.rds"
extract_data(simulation, datasets = "data_file-12.rds")
# }