rnorm_bounded: Random draw from a truncated normal distribution

Description Usage Arguments Value Examples

View source: R/utilities_math.R

Description

rnorm_bounded generates random numbers from a normal distribution using rnorm(), but forced to remain within the specified low/high bounds. All proposals outside the boundaries (exclusive) are discarded, and the sampling is repeated until there are enough values within the specified range. Fully vectorized.

Usage

1
2
rnorm_bounded(n = 1, mean = 0, sd = 1, low = NULL, high = NULL,
  roundToInteger = FALSE)

Arguments

n

the number of values to return

mean

the mean of the normal distribution from which values are generated (vector of length 1 or n)

sd

the standard deviation of the normal distribution from which values are generated (vector of length 1 or n)

low, high

exclusive lower and upper bounds ((vectors of length 1 or n))

roundToInteger

boolean vector of length 1 or n. If TRUE, the corresponding value is rounded to the nearest integer.

Value

A vector of length n.

Examples

1
2
3
4
soundgen:::rnorm_bounded(n = 3, mean = 10, sd = 5, low = 7, high = NULL,
  roundToInteger = c(TRUE, FALSE, FALSE))
soundgen:::rnorm_bounded(n = 3, mean = c(10, 50, 100), sd = c(5, 0, 20),
  roundToInteger = TRUE) # vectorized

tatters/soundgen_beta documentation built on May 14, 2019, 9 a.m.