Learn R Programming

mvrtn (version 1.0)

rtn: random variates from truncated normal distribution

Description

Random variates from the left or right truncated normal distribution are generated. An efficient algorithm based on the inverse CDF method is used. This algorithm can be used to verify empirically the correcntess of the mean and variance computation done by the other function in this package, mvtn.

Usage

rtn(n, zmu = 0, zsig = 1, c = 1.96, side = c("left", "right"))

Arguments

n
number of random variables
zmu
mean parameter for normal distribution
zsig
standard deviation parameter
c
truncation point
side
either left or right

Value

the random variates, vector of length n

Details

The inverse cdf method is used in the case of the right truncated normal distribution. In the left truncated case, the negative of the corresponding right truncated distribution is used.

References

For further details see the vignette.

See Also

mvtn

Examples

Run this code
#Empirical validation
z<-rtn(10^4, 100, 15, c=120, side="left")
c(mean(z), var(z))
mvtn(100, 15, c=120, side="left")

Run the code above in your browser using DataLab