NormalTrunc: The Truncated Normal Distribution

NormalTruncR Documentation

The Truncated Normal Distribution

Description

Density, distribution function, quantile function, and random generation for the truncated normal distribution with parameters mean, sd, min, and max.

Usage

  dnormTrunc(x, mean = 0, sd = 1, min = -Inf, max = Inf)
  pnormTrunc(q, mean = 0, sd = 1, min = -Inf, max = Inf)
  qnormTrunc(p, mean = 0, sd = 1, min = -Inf, max = Inf)
  rnormTrunc(n, mean = 0, sd = 1, min = -Inf, max = Inf)

Arguments

x

vector of quantiles.

q

vector of quantiles.

p

vector of probabilities between 0 and 1.

n

sample size. If length(n) is larger than 1, then length(n) random values are returned.

mean

vector of means of the distribution of the non-truncated random variable. The default is mean=0.

sd

vector of (positive) standard deviations of the non-truncated random variable. The default is sd=1.

min

vector of minimum values for truncation on the left. The default value is min=-Inf.

max

vector of maximum values for truncation on the right. The default value is max=Inf.

Details

See the help file for the normal distribution for information about the density and cdf of a normal distribution.

Probability Density and Cumulative Distribution Function
Let X denote a random variable with density function f(x) and cumulative distribution function F(x), and let Y denote the truncated version of X where Y is truncated below at min=A and above atmax=B. Then the density function of Y, denoted g(y), is given by:

g(y) = frac{f(y)}{F(B) - F(A)}, A \le y \le B

and the cdf of Y, denoted G(y), is given by:

G(y) = 0 for y < A
\frac{F(y) - F(A)}{F(B) - F(A)} for A \le y \le B
1 for y > B

Quantiles
The p^{th} quantile y_p of Y is given by:

y_p = A for p = 0
F^{-1}\{p[F(B) - F(A)] + F(A)\} for 0 < p < 1
B for p = 1

Random Numbers
Random numbers are generated using the inverse transformation method:

y = G^{-1}(u)

where u is a random deviate from a uniform [0, 1] distribution.

Mean and Variance
The expected value of a truncated normal random variable with parameters mean=\mu, sd=\sigma, min=A, and max=B is given by:

E(Y) = \mu + \sigma^2 \frac{f(A) - f(B)}{F(B) - F(A)}

(Johnson et al., 1994, p.156; Schneider, 1986, p.17).

The variance of this random variable is given by:

\sigma^2 + \sigma^3 \{z_A f(A) - z_B f(B) - \sigma[f(A) - f(B)]^2 \}

where

z_A = \frac{A - \mu}{\sigma}; \, z_B = \frac{B - \mu}{\sigma}

(Johnson et al., 1994, p.158; Schneider, 1986, p.17).

Value

dnormTrunc gives the density, pnormTrunc gives the distribution function, qnormTrunc gives the quantile function, and rnormTrunc generates random deviates.

Note

A truncated normal distribution is sometimes used as an input distribution for probabilistic risk assessment.

Author(s)

Steven P. Millard (EnvStats@ProbStatInfo.com)

References

Forbes, C., M. Evans, N. Hastings, and B. Peacock. (2011). Statistical Distributions. Fourth Edition. John Wiley and Sons, Hoboken, NJ.

Johnson, N. L., S. Kotz, and N. Balakrishnan. (1994). Continuous Univariate Distributions, Volume 1. Second Edition. John Wiley and Sons, New York.

Schneider, H. (1986). Truncated and Censored Samples from Normal Populations. Marcel Dekker, New York, Chapter 2.

See Also

Normal, Probability Distributions and Random Numbers.

Examples

  # Density of a truncated normal distribution with parameters 
  # mean=10, sd=2, min=8, max=13, evaluated at 10 and 11.5:

  dnormTrunc(c(10, 11.5), 10, 2, 8, 13) 
  #[1] 0.2575358 0.1943982

  #----------

  # The cdf of a truncated normal distribution with parameters 
  # mean=10, sd=2, min=8, max=13, evaluated at 10 and 11.5:

  pnormTrunc(c(10, 11.5), 10, 2, 8, 13) 
  #[1] 0.4407078 0.7936573

  #----------

  # The median of a truncated normal distribution with parameters 
  # mean=10, sd=2, min=8, max=13:

  qnormTrunc(.5, 10, 2, 8, 13) 
  #[1] 10.23074

  #----------

  # A random sample of 3 observations from a truncated normal distribution 
  # with parameters mean=10, sd=2, min=8, max=13. 
  # (Note: the call to set.seed simply allows you to reproduce this example.)

  set.seed(20) 
  rnormTrunc(3, 10, 2, 8, 13) 
  #[1] 11.975223 11.373711  9.361258

EnvStats documentation built on Aug. 22, 2023, 5:09 p.m.