% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tree_explainer.R
\name{qshap_rsq}
\alias{qshap_rsq}
\title{Calculate Feature-Specific R-Squared Values}
\usage{
qshap_rsq(
  explainer,
  x,
  y,
  local = FALSE,
  nsample = NULL,
  sd_out = TRUE,
  ci_out = TRUE,
  level = 0.95,
  nfrac = NULL,
  random_state = 42,
  ncore = 1L
)
}
\arguments{
\item{explainer}{A qshap_tree_explainer object created by \code{gazer()}}

\item{x}{Feature matrix or data frame with n samples and p features}

\item{y}{Response vector of length n}

\item{local}{Logical; if TRUE, returns both R-squared values and loss matrix}

\item{nsample}{Optional integer; number of samples to use (random subsample if less than nrow(x))}

\item{sd_out}{Logical; if TRUE, returns standard deviations of R-squared estimates}

\item{ci_out}{Logical; if TRUE, returns Wald-style confidence intervals for each feature's R-squared (normal approximation using sd_rsq)}

\item{level}{Confidence level for the intervals (default 0.95)}

\item{nfrac}{Optional numeric in (0,1); fraction of samples to use (alternative to nsample)}

\item{random_state}{Integer seed for reproducible sampling}

\item{ncore}{Number of cores for parallel processing. Use -1 for all available cores, 
or a positive integer. Default is 1 (no parallelization)}
}
\value{
If \code{local=FALSE} (default), returns a numeric vector of length p 
  containing feature-specific R-squared values. If \code{local=TRUE}, returns 
  a list with components \code{rsq} (the R-squared vector) and \code{loss} 
  (an n x p matrix of loss contributions). When \code{ci_out=TRUE}, the returned list
  also contains \code{ci_lower} and \code{ci_upper} vectors representing Wald-style confidence intervals.
}
\description{
Computes feature-specific R-squared values using Q-SHAP decomposition.
Supports parallel processing and sampling for large datasets.
}
\examples{
library(xgboost)
set.seed(42)
n <- 100
p <- 100
X <- matrix(rnorm(n * p), nrow = n, ncol = p)
y <- X[, 1] - X[, 2] + rnorm(n, sd = 0.2)
model <- xgboost(X, y, nrounds = 15, max_depth = 2, verbose = 0)
explainer <- gazer(model)
phi_rsq <- qshap(explainer, X, y)
print(phi_rsq)

}
\keyword{internal}
