% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mvnormr.R
\name{pmvnormr}
\alias{pmvnormr}
\title{Multivariate Normal Probabilities over a Hyperrectangle}
\usage{
pmvnormr(
  lower = NULL,
  upper = NULL,
  mean = NULL,
  sigma,
  n0 = 1024,
  n_max = 16384,
  R = 8,
  abseps = 1e-04,
  releps = 0,
  seed = 0,
  parallel = TRUE,
  nthreads = 0
)
}
\arguments{
\item{lower}{A numeric vector of lower integration limits.}

\item{upper}{A numeric vector of upper integration limits.}

\item{mean}{The mean vector. If \code{NULL} (default), a zero vector of
appropriate length is used.}

\item{sigma}{The covariance (or correlation) matrix of the distribution.}

\item{n0}{Initial number of samples per replication for the Monte Carlo
integration.}

\item{n_max}{Maximum number of samples allowed per replication.}

\item{R}{Number of independent replications used to estimate the error.}

\item{abseps}{Absolute error tolerance for the probability calculation.}

\item{releps}{Relative error tolerance for the probability calculation.}

\item{seed}{Random seed for reproducibility. If 0, a seed is generated
from the computer clock.}

\item{parallel}{Logical; if \code{TRUE}, computations are performed in parallel.}

\item{nthreads}{Number of threads for parallel execution. If 0, the
default RcppParallel behavior is used.}
}
\value{
The estimated probability with the following attributes:
\itemize{
\item \code{method}: \code{"exact"} for analytic methods or \code{"qmc"} for
the Monte Carlo approach.
\item \code{error}: The estimated error (half-width of 95\% confidence interval).
\item \code{nsamples}: The total number of samples used across all replications.
}
}
\description{
Computes the probability that a multivariate normal random
vector falls within a rectangular region defined by lower and upper bounds.
}
\details{
The function automatically selects the most efficient computation method
based on the input:
\itemize{
\item Analytic Methods: Used for univariate cases or multivariate distributions
with a compound symmetry correlation structure and non-negative
correlations.
\item Monte Carlo Estimation: Used for all other cases. The algorithm employs
a randomized quasi-Monte Carlo (QMC) approach using generalized Halton
sequences.
}

To improve efficiency and accuracy, the QMC approach incorporates:
\itemize{
\item Sequential Conditioning: Mimics the standardization and transformation
approach used in \code{mvtnorm::lpmvnorm}, reducing the \eqn{J}-dimensional
integral to a \eqn{(J-1)}-dimensional problem over a hypercube.
\item Adaptive Sampling: The number of samples per replication increases
dynamically until the estimated error falls below \code{abseps} or
\code{releps}, or until \code{n_max} is reached.
}

The standard error is derived from \eqn{R} independent replications.
For high-dimensional problems, computations can be accelerated by
setting \code{parallel = TRUE}, which distributes the replications across
multiple CPU threads via \code{nthreads}.
}
\examples{

# Example 1: Compound symmetry covariance structure and analytic method
n <- 5
mean <- rep(0, n)
lower <- rep(-1, n)
upper <- rep(3, n)
sigma <- matrix(0.5, n, n)
diag(sigma) <- 1
pmvnormr(lower, upper, mean, sigma)

# Example 2: General covariance structure and Monte Carlo method
n <- 5
mean <- rep(0, n)
lower <- rep(-1, n)
upper <- rep(3, n)
sigma <- matrix(c(1, 0.5, 0.3, 0.2, 0.1,
                  0.5, 1, 0.4, 0.3, 0.2,
                  0.3, 0.4, 1, 0.5, 0.3,
                  0.2, 0.3, 0.5, 1, 0.4,
                  0.1, 0.2, 0.3, 0.4, 1), nrow = n)
pmvnormr(lower, upper, mean, sigma, seed = 314159)

}
\author{
Kaifeng Lu, \email{kaifenglu@gmail.com}
}
