% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stats_model_cvanova.R
\name{cv_anova}
\alias{cv_anova}
\title{Cross-validated ANOVA for O-PLS models}
\usage{
cv_anova(smod)
}
\arguments{
\item{smod}{An object of class \code{m8_model}, generated by function \pkg{opls} in the \pkg{metabom8} package.}
}
\value{
A \code{data.frame} containing:
\itemize{
\item \code{SS} - Sum of Squares
\item \code{DF} - Degrees of Freedom
\item \code{MS} - Mean Squares
\item \code{F_value} - F statistic
\item \code{p_value} - P-value from the F-test
}
}
\description{
Performs a cross-validated ANOVA (CV-ANOVA) test for OPLS models. The function compares residuals from a null model and a model using cross-validated predictive scores to assess the significance of the OPLS model.
}
\details{
\strong{Interpretation of the CV-ANOVA table}

The CV-ANOVA compares two nested linear models:
\itemize{
\item \emph{Null model}: \eqn{Y = \beta_0 + \epsilon}
\item \emph{Full model}: \eqn{Y = \beta_0 + \beta_1 t_{\text{pred,cv}} + \epsilon}
}

where \eqn{t_{\text{pred,cv}}} represents the cross-validated predictive component
score(s) obtained from the OPLS model.

The ANOVA table contains:
\itemize{
\item \strong{SS} – Sum of Squares
\item \strong{DF} – Degrees of Freedom
\item \strong{MS} – Mean Squares (SS / DF)
\item \strong{F_value} – F statistic comparing model vs. null
\item \strong{p_value} – P-value from the F-test
}

The \emph{Regression} row quantifies the reduction in residual variance
achieved by including the cross-validated predictive score(s).
The \emph{Residual} row represents the unexplained variance of the full model.

The F-statistic is computed as:
\deqn{
F = \frac{(RSS_0 - RSS_1) / df_{reg}}{RSS_1 / df_{res}}
}
where \eqn{RSS_0} and \eqn{RSS_1} are the residual sums of squares of the
null and full models, respectively.

\strong{Predictive interpretation}

A small p-value (typically < 0.05) indicates that the cross-validated
predictive score(s) significantly reduce residual variance compared to an
intercept-only model. This suggests that the OPLS model captures
statistically meaningful predictive structure in \eqn{Y}.

A large p-value indicates that the predictive component does not explain
\eqn{Y} significantly better than chance, implying weak or unstable
predictive performance.

Importantly, CV-ANOVA evaluates the \emph{linear explanatory power of the
cross-validated predictive scores}, not the descriptive separation of the
latent space. A model may show visual class separation or moderate R\eqn{^2}
yet fail CV-ANOVA if predictive performance is weak.

Sample size strongly affects statistical power. With small \eqn{n}, even
models with moderate predictive strength may not reach statistical
significance.

CV-ANOVA is intended for continuous response (regression) models.
}
\examples{
data("covid")

X <- covid$X
Y <- as.numeric(factor(covid$an$type)) - 1

scaling <- uv_scaling(center=TRUE)
cv <- balanced_mc(10, split=2/3, type='R', probs = c(0, 0.5, 1))
mod <- opls(X, Y, scaling, cv)

cv_anova(mod)

}
\references{
Eriksson, L., et al. (2008). CV-ANOVA for significance testing of PLS and OPLS models. \emph{Journal of Chemometrics}, 22(11-12), 594–600.
}
\seealso{
Other model_validation: 
\code{\link{dmodx}()},
\code{\link{opls_perm}()}
}
\concept{model_validation}
