% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/extract.R
\name{extract}
\alias{extract}
\title{Extract quantities from a model fitted with BayesHMM.}
\arguments{
\item{fit}{An object returned by either \code{\link{draw_samples}} or \code{\link{optimizing}}.}

\item{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 \emph{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.}

\item{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 (\code{\link{do.call}}). Useful when all the elements of the list have the same dimension, possibly because it is used in conjunction with the \emph{chain} and \emph{reduce} arguments.}

\item{chain}{Either "all" or any integer number between 1 and the number of chains M.}

\item{...}{Arguments to be passed to rstan's \code{\link[rstan]{extract}} if the object \emph{fit} was returned by \code{\link{fit}} or \code{\link{draw_samples}}.}
}
\description{
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).
}
\details{
The extract_* family is the safest way to access the generated samples (filtered probability \emph{alpha}, smoothed probability \emph{gamma}, most likely hidden path \emph{zstar}, observation samples from the posterior predictive density \emph{ypred}, hidden path samples from the posterior predictive density \emph{zpred}, simulated observations \emph{ysim}), the fixed pre-specified quantities (observations \emph{y}, time series length \emph{T}, number of hidden states \emph{K}, dimension of the observation vector \emph{R}), Markov-chain Monte Carlo specific information (convergence and posterior predictive diagnostics \emph{diagnostics}, number of chains \emph{n_chains}, total iterations \emph{n_iterations}, warm-up iterations \emph{n_warmup}, thinning \emph{n_thin}, sample size \emph{sample_size}), and other internal elements stored in a fit object (\code{\link{Specification}} object \emph{spec}, dataset in list format \emph{data}, date \emph{date}, time elapsed for fitting \emph{time}, seed \emph{seed}, path to the underlying Stan file \emph{filename}). Except for MCMC-specific functions, these all work interchangeably with both Markov-chain Monte Carlo samples returned by \code{\link{draw_samples}} and maximum a posteriori estimates returned by \code{\link{optimizing}}.
}
\seealso{
The arguments \emph{reduce}, \emph{combine}, and \emph{chain} are very convenient tools to minimize the amount of data management in your code. See \code{\link{extract_quantity}} for an in-depth explanation on how these work.

Other extract: \code{\link{extract_K}},
  \code{\link{extract_R}}, \code{\link{extract_T}},
  \code{\link{extract_alpha}}, \code{\link{extract_data}},
  \code{\link{extract_filename}},
  \code{\link{extract_gamma}}, \code{\link{extract_model}},
  \code{\link{extract_obs_parameters}},
  \code{\link{extract_parameters}},
  \code{\link{extract_spec}}, \code{\link{extract_ypred}},
  \code{\link{extract_ysim}}, \code{\link{extract_y}},
  \code{\link{extract_zpred}}, \code{\link{extract_zsim}},
  \code{\link{extract_zstar}}
}
\concept{extract}
