% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stats_model_helpers.R
\name{.r2}
\alias{.r2}
\title{\eqn{R^2} and \eqn{Q^2} Calculation for OPLS Models}
\usage{
.r2(Y, Yhat, ytss = NULL)
}
\arguments{
\item{Y}{Numeric matrix. True response values. For classification, this should be a dummy matrix.}

\item{Yhat}{Numeric matrix. Predicted response values from the model.}

\item{ytss}{Numeric (optional). Total sum of squares of \code{Y}. If not provided, it will be computed internally.}
}
\value{
A single numeric value representing \eqn{R^2} or \eqn{Q^2}.
}
\description{
Computes the coefficient of determination (\eqn{R^2} or \eqn{Q^2}) for OPLS regression models using the formula:
\deqn{R^2 = 1 - \frac{PRESS}{TSS}}, where PRESS is the prediction error sum of squares,
and TSS is the total sum of squares. If \code{ytss} is not provided, it is computed directly from \code{Y}.

This function supports matrix inputs (e.g., for multi-class outcomes) and averages across columns
to return a single summary \eqn{R^2}/\eqn{Q^2} value.
}
\keyword{internal}
