Learn R Programming

hbmem (version 0.3-3)

rtnorm: Function rtnorm

Description

Returns random samples from a truncated normal distribution.

Usage

rtnorm(N,mu,sigma,a,b)

Value

Returns 'N' random draws.

Arguments

N

Number of samples to return.

mu

A vector of length N that contains distribution means for each draw.

sigma

A vector of length N that contains distribution standard deviations for each draw.

a

Vector of length N of lower truncation points; may be -Inf.

b

Vector of length N of upper truncation point; may be Inf.

Author

Michael S. Pratte

Details

This function is currently unstable for drawing from regions with extremely low probabilities. If this happens is should print a warning, and return a draw from a uniform distribution between a and b. See example below for how to break it.

See Also

hbmem

Examples

Run this code
library(hbmem)
#Draw one
rtnorm(1,0,1,0,.2)

#Draw 50
N=500
mu=rep(0,N)
sigma=rep(1,N)
a=rep(1,N)
b=rep(2,N)
x=rtnorm(N,mu,sigma,a,b)
hist(x)

#Break it
rtnorm(1,0,1,1000,1001)

Run the code above in your browser using DataLab