Learn R Programming

tcensReg (version 0.1.7)

rtnorm: Simulate Random Left-Truncated Normal Distribution

Description

This function is used to generate random samples from left-truncated normal distribution with specified mean and variance.

Usage

rtnorm(n, mu, sd, a)

Arguments

n

Numeric scalar representing the number of observations. Must be greater than or equal to 1.

mu

Mean value of the underlying normal random variable

sd

Standard deviation of underlying normal random variable

a

Numeric vector indicating the left-truncation value.

Value

Returns a vector of samples drawn from the left truncated normal distribution equal to length n.

Details

Our goal is to draw samples from the left truncated normal random variable \(Y_{i}^{*}\). We define this distribution as $$Y_{i}^{*}\sim TN(\mu, \sigma^{2}, a)$$

Sampling is performed by first drawing from a random variable \(Z\) with a uniform distribution on the interval \([0, 1]\) to generate cumulative density probabilities, \(p\). Then the inverse density function of the truncated normal random variable is applied to generate our desired truncated normal observations.

This inverse truncated normal function is shown below: $$Y_{i}^{*}=\Phi^{-1}\Bigg\{p\times\bigg[1-\Phi\big(\frac{a-\mu}{\sigma}\big)\bigg] + \Phi\big(\frac{a-\mu}{\sigma}\big)\Bigg\}\times\sigma+\mu,$$ where \(p\) represents the probabilities sampled from the uniform distribution.

Notes

  • If the mean, mu, is specified as a vector then the standard deviation, sigma, must have either:

    1. same length as mu

    2. be a scalar, indicating that all samples have constant standard deviation

Examples

Run this code
# NOT RUN {
#zero truncated normal data with mean 0.5 and standard deviation 1
y_star <- rtnorm(n = 100, mu = 0.5, sd = 1, a = 0)

# }

Run the code above in your browser using DataLab