rmvnormlim: Generate Multivariate Normal Random Numbers with Limits

View source: R/rmvnormlim.r

rmvnormlimR Documentation

Generate Multivariate Normal Random Numbers with Limits

Description

Generates random numbers from a multivariate normal distribution with specified covariance matrix, constrained between minimum and maximum values. Any generated values outside the limits are resampled until they fall within bounds.

Usage

rmvnormlim(n, sigma, min = -Inf, max = Inf)

Arguments

n

Integer. Number of random vectors to generate

sigma

Numeric matrix. The covariance matrix

min

Numeric. Lower bound for generated values (default = -Inf)

max

Numeric. Upper bound for generated values (default = Inf)

Details

The function uses mvtnorm::rmvnorm() to generate the random numbers. If any generated values fall outside the specified limits, those specific values are resampled until they fall within bounds. This ensures the returned matrix contains only values between min and max while maintaining the specified covariance structure as much as possible.

Value

A matrix of random numbers from the multivariate normal distribution, where all values fall between min and max

Examples

# Generate 100 random vectors with correlation 0.5
sigma <- matrix(c(1, 0.5, 0.5, 1), 2, 2)
x <- rmvnormlim(100, sigma, min=-2, max=2)



ccamp83/mu documentation built on Nov. 7, 2024, 5:17 p.m.