% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lfo.R
\name{lfo}
\alias{lfo}
\alias{lfo.dynamitefit}
\title{Approximate Leave-Future-Out (LFO) Cross-validation}
\usage{
lfo(x, ...)

\method{lfo}{dynamitefit}(x, L, verbose = TRUE, k_threshold = 0.7, ...)
}
\arguments{
\item{x}{[\code{dynamitefit}]\cr The model fit object.}

\item{...}{Additional arguments passed to \code{\link[rstan:stanmodel-method-sampling]{rstan::sampling()}} or the
\verb{$sample()} method of the \code{CmdStanModel} object, such as \code{chains} and
\code{cores} (\code{parallel_chains} in \code{cmdstanr}).}

\item{L}{[\code{integer(1)}]\cr Positive integer defining how many time points
should be used for the initial fit.}

\item{verbose}{[\code{logical(1)}]\cr If \code{TRUE} (default), print the progress of
the LFO computations to the console.}

\item{k_threshold}{[\code{numeric(1)}]\cr Threshold for the Pareto k estimate
triggering refit. Default is 0.7.}
}
\value{
An \code{lfo} object which is a \code{list} with the following components:
\itemize{
\item \code{ELPD}\cr Expected log predictive density estimate.
\item \code{ELPD_SE}\cr Standard error of ELPD. This is a crude approximation which
does not take into account potential serial correlations.
\item \code{pareto_k}\cr Pareto k values.
\item \code{refits}\cr Time points where model was re-estimated.
\item \code{L}\cr L value used in the LFO estimation.
\item \code{k_threshold}\cr Threshold used in the LFO estimation.
}
}
\description{
Estimates the leave-future-out (LFO) information criterion for \code{dynamite}
models using Pareto smoothed importance sampling.
}
\details{
For multichannel models, the log-likelihoods of all channels are combined.
For models with groups, expected log predictive densities (ELPDs) are
computed independently for each group, but the re-estimation of the model
is triggered if Pareto k values of any group exceeds the threshold.
}
\examples{
data.table::setDTthreads(1) # For CRAN
\donttest{
# Please update your rstan and StanHeaders installation before running
# on Windows
if (!identical(.Platform$OS.type, "windows")) {
  # this gives warnings due to the small number of iterations
  out <- suppressWarnings(
    lfo(gaussian_example_fit, L = 20, chains = 1, cores = 1)
  )
  out$ELPD
  out$ELPD_SE
  plot(out)
}
}

}
\references{
Paul-Christian Bürkner, Jonah Gabry, and Aki Vehtari (2020).
Approximate leave-future-out cross-validation for Bayesian time series
models, Journal of Statistical Computation and Simulation, 90:14, 2499-2523.
}
\seealso{
Model diagnostics
\code{\link{hmc_diagnostics}()},
\code{\link{loo.dynamitefit}()},
\code{\link{mcmc_diagnostics}()}
}
\concept{diagnostics}
