| Title: | Moments of Truncated Multivariate Normal Distribution |
|---|---|
| Description: | Computes the product moments of the truncated multivariate normal distribution, particularly for cases involving patterned variance-covariance matrices. It also has the capability to calculate these moments with arbitrary positive-definite matrices, although performance may degrade for high-dimensional variables. |
| Authors: | Seung-Chun Lee [aut, cre] |
| Maintainer: | Seung-Chun Lee <[email protected]> |
| License: | GPL-2 |
| Version: | 1.0.0 |
| Built: | 2026-06-04 07:00:48 UTC |
| Source: | https://github.com/cran/trunmnt |
Based on the algorithm given by Lee (2021), it computes the product moment of a truncated multivariate normal distribution using the multivariate Gaussian quadrature.
Use mtrunmnt to generate a S3 objective and then use
prodmnt to compute arbitrary order of moments. It can also
calculate the mean and variance-covariance matrix of a truncated
multivariate normal distribution by meanvar. See also
probntrun and utrunmnt for computing the
probability of multivariate normal distribution for given limits,
and the moment of truncated univariate normal distribution.
The 'trunmnt' package computes the product moments of the Truncated multivariate normal distribution by implementing the algorithm proposed by Lee (2020). This approach relies on multivariate Gaussian quadrature for numerical integration.
**Limitations:** While the package supports arbitrary positive-definite matrices, the computational complexity scales poorly with the dimension of the vector. For dimensions $D > 5$, using the pattern-specific functions or considering approximation methods is highly recommended.
Seung-Chun Lee, [email protected]
Burkardt, J. (2014). The truncated normal distribution, Online document, Available from: https://people.sc.fsu.edu/~jburkardt/presentations/truncated_normal.pdf.
Jaeckel, P. (2005). A note on multivariate Gauss-Hermite quadrature. London: ABN-Amro. Avaiable from: http://www.jaeckel.org/ANoteOnMultivariateGaussHermiteQuadrature.pdf.
Lee, S.-C. (2021). Moments Calculation for Truncated Multivariate Normal in Nonlinear Generalized Mixed Models. Communications for Statistical Applications and Methods, 27, 377–383.
set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) S <- matrix(sigma2a, ncol = n, nrow = n) + diag(sigma2e, n) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj1 <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) obj2 <- mtrunmnt(mu, lower = a, upper = b, Sigma = S) probntrun(obj1) probntrun(obj2) prodmnt(obj1, c(2,2,0,0,0)) prodmnt(obj2, c(2,2,0,0,0)) meanvar(obj1) meanvar(obj2)set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) S <- matrix(sigma2a, ncol = n, nrow = n) + diag(sigma2e, n) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj1 <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) obj2 <- mtrunmnt(mu, lower = a, upper = b, Sigma = S) probntrun(obj1) probntrun(obj2) prodmnt(obj1, c(2,2,0,0,0)) prodmnt(obj2, c(2,2,0,0,0)) meanvar(obj1) meanvar(obj2)
meanvar is a S3 generic function of the class mtrunmnt.
Using the prodmnt, it compute the mean and
variance-covariance matrix for a truncated multivariate normal
distribution.
meanvar(Obj)meanvar(Obj)
Obj |
An mtrunmnt object created by the |
A list with the mean and variance-covariance matrix.
mtrunmnt, meanvarTMD,
mtmvnorm and prodmnt.
### A simple example #### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) meanvar(obj)### A simple example #### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) meanvar(obj)
mtrunmnt creates an S3 object designed to compute the product moment
for a truncated multivariate normal distribution, utilizing the algorithm
by Lee (2020). Key attributes of this object are the nodes and weights of
the multivariate Gaussian quadrature and the probability of the
truncation interval
mtrunmnt( mu, lower = -Inf, upper = Inf, Sigma = 1, Sigmae = 1, Z = matrix(rep(1, length(mu)), ncol = 1), D = matrix(1, ncol = 1, nrow = 1), nGH = 35 )mtrunmnt( mu, lower = -Inf, upper = Inf, Sigma = 1, Sigmae = 1, Z = matrix(rep(1, length(mu)), ncol = 1), D = matrix(1, ncol = 1, nrow = 1), nGH = 35 )
mu |
**(Required)** Mean vector of the parent multivariate normal distribution. |
lower |
vector of lower limits. If the lower limits are the same, a scalar value can be given. Defaults to -Inf. |
upper |
Vector of upper limits. If the upper limits are the same, a scalar value can be given. Defaults to Inf. |
Sigma |
The variance-covariance matrix of the parent multivariate normal distribution. It must be given a symmetric positive definite matrix, if Sigmae, D and Z are not specified. |
Sigmae |
Vector of variances of error terms. If the variances are the same, a scalar value can be given. Defaults to 1. |
Z |
Design matrix for the random components. Defaults to
|
D |
Variance-covariance matrix of |
nGH |
Number of quadrature points. Defaults to 35. |
Assume the parent multivariate normal distribution comes from a mixed-effects linear model:
where and are design matrices
corresponding to and representing
fixed and random effects, respectively, and is
the vector of errors. It is assumed that the random effects
follows a multivariate normal distribution with mean
, and symmetric positive definite variance-covariance
matrix . As usual, the distribution of
is assumed to be a multivariate normal with
mean and variance-covariance matrix
, but for more flexibility, it can be
assumed that the error terms are independent, but do not have equal
variance. That is, **we assume** where is a diagonal matrix.
Then,
where .
The variance-covariance structure in mtrunmnt can thus be specified
either by providing the individual components ,
and , or by directly supplying the resulting overall
variance-covariance matrix .
A mtrunmnt object
Lee, S.-C. (2020). Moments calculation for truncated multivariate normal in nonlinear generalized mixed models. Communications for Statistical Applications and Methods, Vol. 27, No. 3, 377–383.
### Create a mtrunmnt objective ### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) S <- matrix(sigma2a, ncol = n, nrow = n) + diag(sigma2e, n) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj1 <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) obj2 <- mtrunmnt(mu, lower = a, upper = b, Sigma = S) probntrun(obj1) probntrun(obj2) prodmnt(obj1, c(2,2,0,0,0)) prodmnt(obj2, c(2,2,0,0,0)) meanvar(obj1) meanvar(obj2)### Create a mtrunmnt objective ### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) S <- matrix(sigma2a, ncol = n, nrow = n) + diag(sigma2e, n) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj1 <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) obj2 <- mtrunmnt(mu, lower = a, upper = b, Sigma = S) probntrun(obj1) probntrun(obj2) prodmnt(obj1, c(2,2,0,0,0)) prodmnt(obj2, c(2,2,0,0,0)) meanvar(obj1) meanvar(obj2)
Compute the probability for the truncation interval
.
probntrun(Obj)probntrun(Obj)
Obj |
An mtrunmnt object created by the |
probntrun is a S3 generic function of the class
mtrunmnt. Using the multivariate Gaussian quadrature, it
computes the probability of truncation interval
.
a numeric value.
### A simple example #### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) probntrun(obj)### A simple example #### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) probntrun(obj)
It computes the kappa-th order product moment for a truncated multivariate normal distribution.
prodmnt(Obj, kappa)prodmnt(Obj, kappa)
Obj |
mtrunmnt object created by the |
kappa |
Vector of orders of length equal to mu. |
prodmnt is a S3 generic function of the class
mtrunmnt. Using the multivariate Gaussian quadrature, it
computes the product moment
,
where .
a numeric value.
### A simple example #### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) prodmnt(obj, c(2,2,0,0,0))### A simple example #### set.seed(123) sigma2e <- 1 sigma2a <- 2 n <- 5 mu <- seq(-1,1, length.out = n) y <- mu + rnorm(1, sd = sqrt(sigma2a)) + rnorm(n, sd = sqrt(sigma2e)) a <- rep(-Inf, n) b <- rep(Inf, n) a[y >= 0] <- 0 b[y < 0] <- 0 obj <- mtrunmnt(mu, lower = a, upper = b, Sigmae = sigma2e, D = sigma2a) prodmnt(obj, c(2,2,0,0,0))
-th order moment for an univariate truncated normal
distribution.The utrunmnt function uses the moment generating function to compute
any order of moment for the truncated normal distribution.
utrunmnt(k, mu = 0, lower = -Inf, upper = Inf, sd = 1)utrunmnt(k, mu = 0, lower = -Inf, upper = Inf, sd = 1)
k |
Order of moment. It must be a non-negative integer. |
mu |
Mean of parent normal distribution. Defaults to 0. |
lower |
Lower limit. Defaults to -Inf. |
upper |
Upper limit. Defaults to Inf. |
sd |
Standard deviation of parent normal distribution. Defaults to 1. |
a numeric value.
Burkardt, J. (2014). The truncated normal distribution, Online document, Available from: https://people.sc.fsu.edu/~jburkardt/presentations/truncated_normal.pdf.
utrunmnt(4, mu = 5, upper = 10) utrunmnt(1, mu = 5, lower = -3, upper = 4, sd = 2)utrunmnt(4, mu = 5, upper = 10) utrunmnt(1, mu = 5, lower = -3, upper = 4, sd = 2)