The extract_* family of methods returns elements from a fit object (including fixed and estimated quantities, as well as internal elements of the fit object).

Arguments

fit

An object returned by either draw_samples or optimizing.

reduce

A function to be applied to all the samples generated by one chain for each parameters (i.e. "within chain"). Useful if only one or more summary measures of the generated samples is needed (e.g. the median of the generated sample). The function may return one of more elements. In the former case, the dimension is dropped in the returned object (read the Value section below). Note that the user needs to supply a function as an argument, and not a character string with the name of the function.

combine

A function applied to all the extracted quantities as an ensemble. In other words, instead of returning a named list where each element is one quantity, it returns the value returned by the function applied to the whole list (do.call). Useful when all the elements of the list have the same dimension, possibly because it is used in conjunction with the chain and reduce arguments.

chain

Either "all" or any integer number between 1 and the number of chains M.

...

Arguments to be passed to rstan's extract if the object fit was returned by fit or draw_samples.

Details

The extract_* family is the safest way to access the generated samples (filtered probability alpha, smoothed probability gamma, most likely hidden path zstar, observation samples from the posterior predictive density ypred, hidden path samples from the posterior predictive density zpred, simulated observations ysim), the fixed pre-specified quantities (observations y, time series length T, number of hidden states K, dimension of the observation vector R), Markov-chain Monte Carlo specific information (convergence and posterior predictive diagnostics diagnostics, number of chains n_chains, total iterations n_iterations, warm-up iterations n_warmup, thinning n_thin, sample size sample_size), and other internal elements stored in a fit object (Specification object spec, dataset in list format data, date date, time elapsed for fitting time, seed seed, path to the underlying Stan file filename). Except for MCMC-specific functions, these all work interchangeably with both Markov-chain Monte Carlo samples returned by draw_samples and maximum a posteriori estimates returned by optimizing.

See also

The arguments reduce, combine, and chain are very convenient tools to minimize the amount of data management in your code. See extract_quantity for an in-depth explanation on how these work.

Other extract: extract_K, extract_R, extract_T, extract_alpha, extract_data, extract_filename, extract_gamma, extract_model, extract_obs_parameters, extract_parameters, extract_spec, extract_ypred, extract_ysim, extract_y, extract_zpred, extract_zsim, extract_zstar