% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nl_r2.R
\name{nl_r2}
\alias{nl_r2}
\title{Multilevel R-squared decomposition for nl_fit models}
\usage{
nl_r2(object, digits = 4L)
}
\arguments{
\item{object}{An \code{nl_fit} object returned by \code{\link{nl_fit}}.}

\item{digits}{Integer; decimal places for display. Default \code{4}.}
}
\value{
A list of class \code{"nl_r2"} returned invisibly and
pretty-printed automatically. It contains \code{type} (one of
\code{"OLS"}, \code{"GAM"}, \code{"LMM"}, or \code{"GLMM"}),
\code{r2} (a named numeric vector: \code{R2} and \code{R2_adj} for OLS;
\code{R2_dev} for GAM; \code{R2m} and \code{R2c} for LMM/GLMM), and
\code{variance_partition} (a data frame with columns \code{component},
\code{variance}, and \code{proportion} for multilevel models, or
\code{NULL} for single-level models).
}
\description{
Computes a suite of R-squared statistics for models fitted by
\code{\link{nl_fit}}.
For single-level models the standard R-squared and adjusted R-squared are
returned. For multilevel models (lmerMod / glmerMod) two quantities are
reported: the Nakagawa-Schielzeth marginal R-squared (variance explained by
fixed effects only) and the conditional R-squared (fixed plus all random
effects), together with a level-specific variance partition table analogous
to the r2_mlm / Raudenbush-Bryk approach.
}
\details{
Marginal and conditional R-squared for LMMs follow the Nakagawa and
Schielzeth (2013) formulae extended to multiple random effects by Nakagawa,
Johnson and Schielzeth (2017). The fixed-effects variance
\eqn{\sigma^2_f} is computed as the variance of the linear predictor
from fixed effects only (\eqn{\hat{\mu} = X\hat{\beta}}).

The level-specific variance partition (r2_mlm-style) decomposes the total
modelled variance (\eqn{\sigma^2_f + \sum \sigma^2_j + \sigma^2_\epsilon})
to show how much each source contributes, printed as a breakdown table.
}
\references{
Nakagawa, S., & Schielzeth, H. (2013). A general and simple method for
obtaining R-squared from generalized linear mixed-effects models.
Methods in Ecology and Evolution, 4(2), 133--142.

Nakagawa, S., Johnson, P. C. D., & Schielzeth, H. (2017). The coefficient
of determination R-squared and intra-class correlation coefficient from
generalized linear mixed-effects models revisited and expanded.
Journal of the Royal Society Interface, 14(134), 20170213.

Rights, J. D., & Sterba, S. K. (2019). Quantifying explained variance in
multilevel models: An integrative framework for defining R-squared measures.
Psychological Methods, 24(3), 309--338.
}
\seealso{
\code{\link{nl_fit}}, \code{\link{nl_icc}}
}
