rtnorm: Random Generation for Truncated Univariate Normal

View source: R/rtnorm.R

rtnormR Documentation

Random Generation for Truncated Univariate Normal

Description

Draws from truncated univariate normal distribution within an interval.

Usage

rtnorm(mean, sd = 1, lower, upper, n = NULL)

Arguments

mean

vector of means. The length is the number of observations.

sd

standard deviation. Defaults to 1.

lower

a scalar of lower bound for truncation, or a vector of lower bounds with the same length as mean.

upper

a scalar of upper bound for truncation, or a vector of upper bounds with the same length as mean.

n

number of random samples when mean is a scalar.

Value

Returns a vector of random numbers following the specified truncated univariate normal distribution.

Examples

set.seed(1203)
x = rtnorm(mean=rep(1,1000), sd=2, lower=-2, upper=3)
summary(x)

# use the alternative form of input
set.seed(1203)
x = rtnorm(mean=1, sd=2, lower=-2, upper=3, n=1000)
summary(x)


tmvtnsim documentation built on Oct. 10, 2022, 1:06 a.m.