Function generator for sampling from a mvn (multivariate normal) object.

# S3 method for class 'mvn'
sampler(x, ...)

Arguments

x

The mvn object to sample from

...

Additional arguments to pass to the generated function that will be fixed during all calls.

Value

A function that samples from the mvn distribution. It accepts as input: - n: number of samples to generate. Defaults to 1. - mu: a vector denoting the population mean. Defaults to the mean of x (an mvn object) - sigma: a matrix denoting the covariance of observations. Defaults to the variance-covariance of x. - p: probability region to sample from. Defaults to 1, which corresponds to the entire distribution. sample_mvn_region method. It's used when p is less than 1. - ...: any additional parameters to pass to rmvnorm or sample_mvn_region which can be different during each call.

Examples

X <- mvn(c(0, 0), diag(2))
s <- sampler(X)
set.seed(42)
s(3)
#>           [,1]       [,2]
#> [1,] 1.3709584 -0.5646982
#> [2,] 0.3631284  0.6328626
#> [3,] 0.4042683 -0.1061245