extract_zsim: Extract the simulated sample of the state variable (zsim).

Description Usage Arguments Value See Also

Description

If the fit object was created via the sim method, this function returns a sample of the state variable from the prior predictive densitiy (i.e. using random values of the parameters). If a dataset was provided when fitting the model instead, the sample is simulated from the posterior predictive density. In the latter case, calling either extract_zsim and extract_zpred are equivalent.

Usage

1
2
extract_zsim(fit, n = NULL, reduce = NULL, combine = NULL,
  chain = "all", ...)

Arguments

fit

An object returned by either draw_samples or optimizing.

n

(optional) An integer number indicating the number of the iteration that should be returned.

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.

Value

A numeric array with three dimensions [N, M, T]: number of iterations N, number of chains M, length of the time series T, the dimension of the observation vector R. If the argument chain was set, the chain dimension is dropped and the function returns a two-dimensional numeric array [N, T]. If the argument reduce was set to a function returning a vector of size n, the returned array has dimension [n, M, T]. When n is simply one (e.g. median), the number-of-iterations dimension is dropped and the function returns a two-dimensional numeric array [M, T].

See Also

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_zstar, extract


luisdamiano/BayesHMM documentation built on May 20, 2019, 2:59 p.m.