% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calc_pval.R
\name{calc_pval}
\alias{calc_pval}
\title{Monte Carlo p-value and quantiles for the delta test}
\usage{
calc_pval(Z, eig, quan, n_MC = 5000)
}
\arguments{
\item{Z}{Observed test statistic from \code{\link[=calc_Z]{calc_Z()}}.}

\item{eig}{Numeric vector of leading eigenvalues (length \code{n_eig}).}

\item{quan}{Probabilities for which to return quantiles of the simulated null
statistic (e.g. \code{c(0.90, 0.95, 0.99)}).}

\item{n_MC}{Number of Monte Carlo draws (default \code{5000}).}
}
\value{
A list with \code{p_val} (one-sided p-value) and \code{quantile} (named
vector of quantiles at \code{quan}).
}
\description{
Given leading eigenvalues of the covariance operator used in the delta test
(from \code{\link[=calc_eig]{calc_eig()}}) and the observed statistic \(Z\) (from \code{\link[=calc_Z]{calc_Z()}}),
draws a Monte Carlo sample from the weighted sum of chi-square(1) variables
and returns the right-tail \emph{p}-value and quantiles of the null distribution
(as in the paper’s replication code).
}
\details{
Monte Carlo draws use R's current random-number stream. The function does
not call \code{\link[base]{set.seed}}; call it yourself beforehand if you
need reproducible \code{p_val} and quantiles.
}
\examples{
\donttest{
if (requireNamespace("sde", quietly = TRUE)) {
  library(dplyr)
  nsamp <- 20L
  ngame <- 25L
  df <- df_gen(N = nsamp, Ngame = ngame) \%>\%
    dplyr::group_by(grid) \%>\%
    dplyr::mutate(
      p_bar_12 = mean(phat_A - phat_B),
      diff_non_cent = phat_A - phat_B,
      diff_cent = phat_A - phat_B - p_bar_12
    ) \%>\%
    dplyr::ungroup()
  Z <- calc_Z(df, "phat_A", "phat_B", "Y", "grid", nsamp, ngame)
  eig <- calc_eig(df, n_eig = 5L, ngame = ngame, nsamp = nsamp, cent = FALSE)
  set.seed(1)
  calc_pval(Z, eig, quan = c(0.9, 0.95), n_MC = 300L)
}
}

}
\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}
}
