rmvnormlim | R Documentation |
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.
rmvnormlim(n, sigma, min = -Inf, max = Inf)
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) |
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.
A matrix of random numbers from the multivariate normal distribution, where all values fall between min and max
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.