% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calc_eig.R
\name{calc_eig}
\alias{calc_eig}
\title{Leading eigenvalues for the delta test covariance}
\usage{
calc_eig(df, n_eig = 10, ngame, nsamp, grid = "grid", cent = FALSE)
}
\arguments{
\item{df}{Data frame containing \code{grid} and a column \code{diff_cent} or
\code{diff_non_cent} (vector differences of forecasts across games, aligned
within each time point).}

\item{n_eig}{Number of leading eigenvalues to extract (dimension D in the
paper).}

\item{ngame}{Number of independent games (used for scaling inner products).}

\item{nsamp}{Number of time grid points.}

\item{grid}{Name of the time grid column.}

\item{cent}{If \code{TRUE}, use \code{diff_cent} (centered differences); if \code{FALSE},
use \code{diff_non_cent}.}
}
\value{
A numeric vector of length \code{n_eig} of eigenvalues (descending).
}
\description{
Forms the empirical covariance matrix of either centered or non-centered
forecast differences across time points (see \code{diff_cent} vs \code{diff_non_cent}
in the paper), and returns the leading eigenvalues scaled by one over
\code{nsamp}, for use with \code{\link[=calc_pval]{calc_pval()}}. This matches the construction in the
replication \code{utility.R} (\code{calc_p_val} / \code{eigs_sym}).
}
\examples{
library(dplyr)
library(rtForecastEval)
ngame <- 8L
nsamp <- 6L
gr <- seq(0, 1, length.out = nsamp)
df <- tidyr::expand_grid(grid = gr, game = seq_len(ngame)) \%>\%
  mutate(
    phat_A = stats::runif(dplyr::n()),
    phat_B = stats::runif(dplyr::n()),
    diff_non_cent = phat_A - phat_B
  )
calc_eig(df, n_eig = 4L, ngame = ngame, nsamp = nsamp, cent = FALSE)

}
\references{
Yeh, C.-K., Rice, G., & Dubin, J. A. (2022). \emph{The American Statistician},
\emph{76}, 214--223. \doi{10.1080/00031305.2021.1967781}

Preprint: \url{https://arxiv.org/abs/2010.00781}
}
