rtnorm: Function rtnorm

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/normal.R

Description

Returns random samples from a truncated normal distribution.

Usage

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

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.

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.

Value

Returns 'N' random draws.

Author(s)

Michael S. Pratte

See Also

hbmem

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)

hbmem documentation built on April 7, 2018, 1:03 a.m.