Density, distribution, quantile, random number
generation and parameter estimation functions for the truncated normal distribution with parameters mean, sd and
a and b which represent the lower and upper truncation points respectively.
Parameter estimation can be based on a weighted or unweighted i.i.d. sample and is performed numerically.
Usage
dNormal_trunc_ab(x, mu = 0, sigma = 1, a = 0, b = 1, params = list(mu,
sigma, a, b), ...)
pNormal_trunc_ab(q, mu = 0, sigma = 1, a = 0, b = 1, params = list(mu
= 2, sigma = 5, a = 0, b = 1), ...)
qNormal_trunc_ab(p, mu = 0, sigma = 1, a = 0, b = 1, params = list(mu
= 2, sigma = 5, a = 0, b = 1), ...)
rNormal_trunc_ab(n, mu = 0, sigma = 1, a = 0, b = 1, params = list(mu,
sigma, a, b), ...)
eNormal_trunc_ab(X, w, method = "numerical.MLE", ...)
lNormal_trunc_ab(X, w, mu = 0, sigma = 1, a = 0, b = 1,
params = list(mu, sigma, a, b), logL = TRUE, ...)
Arguments
x,q
A vector of quantiles.
mu,sigma
Shape parameters.
a,b
Boundary parameters.
params
A list that includes all named parameters.
...
Additional parameters.
p
A vector of probabilities.
n
Number of observations.
X
Sample observations.
w
An optional vector of sample weights.
method
Parameter estimation method.
logL
logical;if TRUE, lNormal_trunc_ab gives the log-likelihood, otherwise the likelihood is given.
Details
If the mean, sd, a or b are not specified they assume the default values of 0, 1, 0, 1 respectively.
The dNormal_trunc_ab(), pNormal_trunc_ab(), qNormal_trunc_ab(),and rNormal_trunc_ab() functions serve
as wrappers of the dtrunc, ptrunc, qtrunc, and
rtrunc functions in the truncdist package. They allow for the parameters to be declared not only as
individual numerical values, but also as a list so parameter estimation can be carried out.
The probability density function of the doubly truncated normal distribution is given by
f(x) = σ^{-1} Z(x-μ/σ)[Φ(b-μ/σ) - Φ(a-μ/σ)]^{-1}
where ∞ <a ≤ x ≤ b < ∞. The degrees of truncation are Φ((a-μ)/σ) from below and 1-Φ((a-μ)/σ)
from above. If a is replaced by -∞, or b by ∞, the distribution is singly truncated, (Johnson et.al, p.156).
The upper and lower limits of truncation a and b are normally known
parameters whereas μ and σ may be unknown. Crain (1979) discusses parameter estimation for the truncated normal
distribution and the method of numerical maximum likelihood estimation is used for parameter estimation in eNormal_trunc_ab.
Value
dNormal_trunc_ab gives the density, pNormal_trunc_ab the distribution function,
qNormal_trunc_ab the quantile function, rNormal_trunc_ab generates random variables, and
eNormal_trunc_ab estimates the parameters. lNormal_trunc_ab provides the log-likelihood function.
Author(s)
Haizhen Wu and A. Jonathan R. Godfrey.
Updates and bug fixes by Sarah Pirikahu.
References
Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions,
volume 1, chapter 13, Wiley, New York.
Crain, B.R (1979). Estimating the parameters of a truncated normal distribution, Applied Mathematics and Computation,
vol 4, pp. 149-156
See Also
ExtDist for other standard distributions.
Examples
# Parameter estimation for a distribution with known shape parameters
X <- rNormal_trunc_ab(n= 500, mu= 2, sigma = 5, a = 1, b = 2)
est.par <- eNormal_trunc_ab(X); est.par
plot(est.par)
# Fitted density curve and histogram
den.x <- seq(min(X),max(X),length=100)
den.y <- dNormal_trunc_ab(den.x,params = est.par)
hist(X, breaks=10, probability=TRUE, ylim = c(0,1.2*max(den.y)))
lines(den.x, den.y, col="blue")
lines(density(X), lty = 2)
# Extracting boundary and shape parameters
est.par[attributes(est.par)$par.type=="boundary"]
est.par[attributes(est.par)$par.type=="shape"]
# log-likelihood function
lNormal_trunc_ab(X,param = est.par)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(ExtDist)
Attaching package: 'ExtDist'
The following object is masked from 'package:stats':
BIC
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ExtDist/Normal_trunc_ab.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Normal_trunc_ab
> ### Title: The truncated normal distribution.
> ### Aliases: Normal_trunc_ab dNormal_trunc_ab eNormal_trunc_ab
> ### lNormal_trunc_ab pNormal_trunc_ab qNormal_trunc_ab rNormal_trunc_ab
>
> ### ** Examples
>
> # Parameter estimation for a distribution with known shape parameters
> X <- rNormal_trunc_ab(n= 500, mu= 2, sigma = 5, a = 1, b = 2)
> est.par <- eNormal_trunc_ab(X); est.par
Parameters for the Normal_trunc_ab distribution.
(found using the numerical.MLE method.)
Parameter Type Estimate
mu shape 1.189181
sigma shape 1.774684
a boundary 1.005581
b boundary 1.999281
> plot(est.par)
>
> # Fitted density curve and histogram
> den.x <- seq(min(X),max(X),length=100)
> den.y <- dNormal_trunc_ab(den.x,params = est.par)
> hist(X, breaks=10, probability=TRUE, ylim = c(0,1.2*max(den.y)))
> lines(den.x, den.y, col="blue")
> lines(density(X), lty = 2)
>
> # Extracting boundary and shape parameters
> est.par[attributes(est.par)$par.type=="boundary"]
$a
[1] 1.005581
$b
[1] 1.999281
> est.par[attributes(est.par)$par.type=="shape"]
$mu
[1] 1.189181
$sigma
[1] 1.774684
>
> # log-likelihood function
> lNormal_trunc_ab(X,param = est.par)
[1] 3.393316
>
>
>
>
>
> dev.off()
null device
1
>