Learn R Programming

ExtDist (version 0.3.3)

Normal_sym_trunc_ab: The symmetric truncated normal distribution.

Description

Density, distribution function, quantile function, random generation function and parameter estimation function (based on weighted or unweighted i.i.d. sample) for the symmetric truncated normal distribution

Usage

dNormal_sym_trunc_ab(x, sigma = 0.3, a = 0, b = 1, params = list(sigma,
  a, b))

pNormal_sym_trunc_ab(q, sigma = 0.3, a = 0, b = 1, params = list(mu = 2, sigma = 5, a = 0, b = 1))

qNormal_sym_trunc_ab(p, sigma = 0.3, a = 0, b = 1, params = list(mu = 2, sigma = 5, a = 0, b = 1))

rNormal_sym_trunc_ab(n, mu = 2, sigma = 3, a = 0, b = 1, params = list(sigma, a, b))

eNormal_sym_trunc_ab(X, w, method = "numerical.MLE")

lNormal_sym_trunc_ab(X, w, mu = 2, sigma = 3, a = 0, b = 1, params = list(sigma, a, b), logL = TRUE)

Arguments

x,q
vector of quantiles.
a,b
boundary parameters.
params
a list includes all parameters
p
vector of probabilities.
n
number of observations.
mu,sigma
shape parameters.
X
sample observations.
w
weights of sample.
method
parameter estimation method.
logL
logical; if TRUE, lNormal_sym_trunc_ab gives log likelihood.
...
other parameters

Value

  • dNormal_sym_trunc_ab gives the density; pNormal_sym_trunc_ab gives the distribution function; qNormal_sym_trunc_ab gives the quantile function; rNormal_sym_trunc_ab generates random variables; eNormal_sym_trunc_ab estimate the parameters

Details

symmetric truncated normal Distribution

See ../doc/Distributions-Truncted-Normal.html{Distributions-Truncted-Normal}

Examples

Run this code
# Parameter estimation
n <- 500
a <- 0; b <- 1; sigma <- 0.3
X <- rNormal_sym_trunc_ab(n, sigma, a, b)
(est.par <- eNormal_sym_trunc_ab(X))

# Histogram and fitted density
den.x <- seq(min(X),max(X),length=100)
den.y <- dNormal_sym_trunc_ab(den.x,params = est.par)
hist(X, breaks=10, col="red", probability=TRUE, ylim = c(0,1.1*max(den.y)))
lines(den.x, den.y, col="blue", lwd=2)

# Q-Q plot and P-P plot
plot(qNormal_sym_trunc_ab((1:n-0.5)/n, params=est.par), sort(X), main="Q-Q Plot",
xlab="Theoretical Quantiles", ylab="Sample Quantiles", xlim = c(a,b), ylim = c(a,b))
abline(0,1)

plot((1:n-0.5)/n, pNormal_sym_trunc_ab(sort(X), params=est.par), main="P-P Plot",
xlab="Theoretical Percentile", ylab="Sample Percentile", xlim = c(0,1), ylim = c(0,1))
abline(0,1)

# A weighted parameter estimation example
n <- 10
par <- list(sigma=0.3, a= 0, b=1)
X <- rNormal_sym_trunc_ab(n, params=par)
w <- c(0.13, 0.06, 0.16, 0.07, 0.2, 0.01, 0.06, 0.09, 0.1, 0.12)
eNormal_sym_trunc_ab(X,w) # estimated parameters of weighted sample
eNormal_sym_trunc_ab(X) # estimated parameters of unweighted sample

# Extracting boundary and shape parameters
est.par[attributes(est.par)$par.type=="boundary"]
est.par[attributes(est.par)$par.type=="shape"]

# evaluate the performance of the parameter estimation function by simulation
eval.estimation(rdist=rNormal_sym_trunc_ab,edist=eNormal_sym_trunc_ab,n = 1000, rep.num = 1e3,
params = list(mu=2, sigma=5, a=0, b=1), method ="numerical.MLE")

# evaluate the precision of estimation by Hessian matrix
X <- rNormal_sym_trunc_ab(1000, sigma, a, b)
(est.par <- eNormal_sym_trunc_ab(X))
H <- attributes(eNormal_sym_trunc_ab(X, method = "numerical.MLE"))$nll.hessian
fisher_info <- solve(H)
sqrt(diag(fisher_info))

# log-likelihood, score vector and observed information matrix
lNormal_sym_trunc_ab(X,param = est.par)
lNormal_sym_trunc_ab(X,param = est.par, logL=FALSE)

Run the code above in your browser using DataLab