Draw random numbers from unusual distributions, such as on the unit or non-negative real line with known means and standard deviations.

rmultiunit(
  n,
  mean,
  sd,
  Sigma = NULL,
  Omega = NULL,
  perfect_correlation = FALSE
)

rmultiunit_from_real(
  n,
  mean_real,
  sd_real = NULL,
  Sigma_chol = NULL,
  perfect_correlation = FALSE
)

runit_from_real(n, mean_real, sd_real)

runit(n, mean, sd)

unit_to_real(unit_mean, unit_sd)

Arguments

n

number of random draws to simulate. Each draw is a vector of values with length equal to length(mean) and length(sd) and the resulting output has n rows and length(mean) columns

mean

vector of mean values on the unit scale

sd

vector of positive standard deviations

Sigma

optional covariance matrix with dimensions of length(mean) by length(mean) defining covariances between each pair of values in mean. Note that only the correlation structure is retained from Sigma, so that standard deviations are still required

Omega

optional correlation matrix with dimensions of length(mean) by length(mean) defining correlations between each pair of values in mean

perfect_correlation

logical, if TRUE and Sigma and Omega are NULL, then all values in each replicate (row) are perfectly correlated with known mean and standard deviation. If FALSE, then all values in each replicate are completely uncorrelated

mean_real

vector of mean values converted to real-line equivalents

sd_real

vector of standard deviations converted to real-line equivalents

Sigma_chol

Cholesky decomposition of covariance matrix converted to real-line equivalent

unit_mean

vector of mean values on the unit interval

unit_sd

vector of standard deviations on the unit interval

Details

The r*unit family of functions support simulation of values on the unit interval based on a known mean, sd, and correlation structure. runit and runit_from_real are vectorised univariate functions, and rmultiunit and rmultiunit_from_real are multivariate versions of these same functions. runit and rmultiunit provide simulated values on the unit line with specified means, standard deviations, and correlation/covariance structure (in the case of rmultiunit).

The *_from_real versions of these functions are helpers that use pre-transformed estimates of parameters on the real line, calculated with unit_to_real. These functions are exported because unit_to_real, called within runit and rmultiunit, is slow. Separating this into a separate step allows less frequent calculations of this transformation using function or dynamic versions of args in simulate.

unit_to_real converts means and standard deviations from their values on the unit line to their equivalent values on the real line.

The use of the different versions of these functions is illustrated in the Macquarie perch example on the package [website](https://aae-stats.github.io/aae.pop/).

Examples

# rmultiunit generates multivariate draws constrained to
#   the unit interval, with known mean, standard deviation,
#   and (optionally) covariance/correlation structure
rmultiunit(n = 10, mean = c(0.25, 0.5, 0.75), sd = c(0.1, 0.4, 0.25))
#>            [,1]         [,2]      [,3]
#>  [1,] 0.3913312 0.8967120724 0.5251920
#>  [2,] 0.2627124 0.0210964696 0.6988087
#>  [3,] 0.2946292 0.9810610591 0.9535728
#>  [4,] 0.3279317 0.7477435199 0.4582237
#>  [5,] 0.2337661 0.0002655617 0.9493458
#>  [6,] 0.2134636 0.9157487816 0.6829384
#>  [7,] 0.1900636 0.9940835701 0.4050700
#>  [8,] 0.1778885 0.9775295742 0.8532240
#>  [9,] 0.2431005 0.5722960618 0.7541516
#> [10,] 0.2760783 0.9671427349 0.7984281

if (FALSE) {
# add in a correlation structure
omega_set <- cbind(
  c(1, 0.25, 0.01),
  c(0.25, 1, 0.5),
  c(0.01, 0.5, 1)
)
rmultiunit(
  n = 10,
  mean = c(0.25, 0.5, 0.75),
  sd = c(0.1, 0.4, 0.25),
  Omega = omega_set
)
}