tnorm: Generate truncated normal random variables

Description Usage Arguments Value Examples

Description

This function generates truncated normal random variables

Usage

1
tnorm(n, lo, hi, mu, sig)

Arguments

n

number of random variables

lo

lower truncation value. If none, just put -Inf

hi

upper truncation value. If none, just put Inf

mu

the mean of the untruncated normal distribution

sig

the standard deviation of the untruncated normal distribution

Value

A vector of numbers

Examples

1
2
3
4
5
6
7
mean1=3; sd1=2; lo1=0; hi1=Inf
z=tnorm(n=10000,lo=lo1,hi=hi1,mu=mean1,sig=sd1)
tmp=density(z,from=lo1)
plot(tmp$x,tmp$y,type='l')
x=seq(from=lo1,to=max(z),length.out=1000)
y=dnorm(x,mean=mean1,sd=sd1)/(1-pnorm(lo1,mean=mean1,sd=sd1))
lines(x,y,col='red')

drvalle1/myfirstpackage1 documentation built on May 12, 2019, 5:24 p.m.