% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tscv.R
\name{CVar}
\alias{CVar}
\alias{print.CVar}
\title{k-fold Cross-Validation applied to an autoregressive model}
\usage{
CVar(
  y,
  k = 10,
  FUN = nnetar,
  cvtrace = FALSE,
  blocked = FALSE,
  LBlags = 24,
  ...
)
}
\arguments{
\item{y}{Univariate time series}

\item{k}{Number of folds to use for cross-validation.}

\item{FUN}{Function to fit an autoregressive model. Currently, it only works
with the \code{\link[=nnetar]{nnetar()}} function.}

\item{cvtrace}{Provide progress information.}

\item{blocked}{choose folds randomly or as blocks?}

\item{LBlags}{lags for the Ljung-Box test, defaults to 24, for yearly series can be set to 20}

\item{...}{Other arguments are passed to \code{FUN}.}
}
\value{
A list containing information about the model and accuracy for each
fold, plus other summary information computed across folds.
}
\description{
\code{CVar} computes the errors obtained by applying an autoregressive
modelling function to subsets of the time series \code{y} using k-fold
cross-validation as described in Bergmeir, Hyndman and Koo (2015). It also
applies a Ljung-Box test to the residuals. If this test is significant
(see returned pvalue), there is serial correlation in the residuals and the
model can be considered to be underfitting the data. In this case, the
cross-validated errors can underestimate the generalization error and should
not be used.
}
\examples{

modelcv <- CVar(lynx, k = 5, lambda = 0.15)
print(modelcv)
print(modelcv$fold1)

library(ggplot2)
autoplot(lynx, series = "Data") +
  autolayer(modelcv$testfit, series = "Fits") +
  autolayer(modelcv$residuals, series = "Residuals")
ggAcf(modelcv$residuals)

}
\references{
Bergmeir, C., Hyndman, R.J., Koo, B. (2018) A note on the
validity of cross-validation for evaluating time series prediction.
\emph{Computational Statistics & Data Analysis}, \bold{120}, 70-83.
\url{https://robjhyndman.com/publications/cv-time-series/}.
}
\seealso{
\code{\link[=CV]{CV()}}, \code{\link[=tsCV]{tsCV()}}.
}
\author{
Gabriel Caceres and Rob J Hyndman
}
\keyword{ts}
