% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cSu_wrapper.R
\name{closedSu}
\alias{closedSu}
\title{Closed Su procedure for simultaneous FDR control}
\usage{
closedSu(p, set = NULL, alpha = 0.05, approximate = FALSE)
}
\arguments{
\item{p}{Numeric vector of p-values, one per hypothesis.}

\item{set}{Optional subsetting vector for \code{p} (logical, positive index, or
negative index). If \code{NULL} (the default), returns the size of the largest
closed-Su-significant set.}

\item{alpha}{Numeric scalar in \eqn{[0, 1]}. FDR level. Default \code{0.05}.}

\item{approximate}{Logical. If \code{FALSE} (the default), uses an exact algorithm
that checks every set size from largest to smallest and is guaranteed to
find the largest closed-Su-significant set. If \code{TRUE}, uses a faster
bisection strategy seeded by the Su lower bound (BH at
\eqn{\alpha/\ell_\alpha}). The approximate method may occasionally
underestimate the largest significant set, but is recommended for
exploratory analyses or large inputs where computation time is a concern.}
}
\value{
\itemize{
\item If \code{set} is supplied: a single logical (\code{TRUE}/\code{FALSE}).
\item If \code{set = NULL}: a single non-negative integer \eqn{r} (0 = no rejection).
}
}
\description{
Applies the closed testing improvement of the Su (2018) procedure. The
standard Su procedure controls the false discovery rate (FDR) at level
\eqn{\alpha} under the PRDN assumption but only provides a single set of
rejections. The closed Su procedure provides simultaneous FDR control:
for every set of hypotheses, it determines whether that set can be reported
as discoveries while maintaining FDR control at level \eqn{\alpha},
regardless of which other sets are inspected.
}
\details{
A set \eqn{R} of hypotheses is closed-Su-significant — and therefore a
valid simultaneous rejection — if and only if, for every
\eqn{1 \le u \le |R|} and \eqn{0 \le v \le m - |R|}, the combined sorted
vector \eqn{t_1 \ge \cdots \ge t_{u+v}} of the \eqn{u} largest p-values
in \eqn{R} and the \eqn{v} largest p-values outside \eqn{R} satisfies
\deqn{
  \min_i \left\{ t_i \cdot (u+v) - c \cdot (u+v-i+1) \right\} \le 0,
  \quad c = \frac{|R|\alpha}{u \cdot \ell_\alpha},
}
where \eqn{\ell_\alpha = -W_{-1}(-\alpha/e)} is the Lambert W correction
factor (Xu et al., 2025, Section 6.2).

The function has two modes:
\itemize{
\item \strong{Set-checking mode} (when \code{set} is supplied): Returns \code{TRUE} if the
specified set is closed-Su-significant, and \code{FALSE} otherwise.
\item \strong{Discovery mode} (when \code{set = NULL}): Returns the size \eqn{r} of the
largest closed-Su-significant set consisting of the \eqn{r} smallest
p-values.
}
}
\examples{
set.seed(42)
p <- c(runif(20), rbeta(10, 0.1, 1))

# Discovery mode
r <- closedSu(p, alpha = 0.05)

# Set-checking mode
closedSu(p, set = p < 0.01, alpha = 0.05)

}
\references{
Su, W. J. (2018). The FDR-Linking Theorem. arXiv:1812.08965.

Xu, Z., Solari, A., Fischer, L., de Heide, R., Ramdas, A., & Goeman, J.
(2025). Bringing closure to false discovery rate control.
arXiv:2509.02517.
}
\seealso{
\code{\link[=closedBY]{closedBY()}}, \code{\link[=closedeBH]{closedeBH()}}
}
