Package 'ald'

Title: The Asymmetric Laplace Distribution
Description: It provides the density, distribution function, quantile function, random number generator, likelihood function, moments and Maximum Likelihood estimators for a given sample, all this for the three parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999). This is a special case of the skewed family of distributions available in Galarza et.al. (2017) <doi:10.1002/sta4.140> useful for quantile regression.
Authors: Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>
Maintainer: Christian E. Galarza <[email protected]>
License: GPL (>= 2)
Version: 1.3.1
Built: 2025-01-29 05:38:36 UTC
Source: https://github.com/cran/ald

Help Index


The Asymmetric Laplace Distribution

Description

It provides the density, distribution function, quantile function, random number generator, likelihood function, moments and Maximum Likelihood estimators for a given sample, all this for the three parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression.

Details

Package: ald
Type: Package
Version: 1.0
Date: 2015-01-27
License: GPL (>=2)

Author(s)

Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>

References

Koenker, R., Machado, J. (1999). Goodness of fit and related inference processes for quantile regression. J. Amer. Statist. Assoc. 94(3):1296-1309.

Yu, K. & Moyeed, R. (2001). Bayesian quantile regression. Statistics & Probability Letters, 54(4), 437-447.

Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.

See Also

ALD,momentsALD,likALD,mleALD

Examples

## Let's plot an Asymmetric Laplace Distribution!

##Density
sseq = seq(-40,80,0.5)
dens = dALD(y=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,dens,type="l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")

## Distribution Function
df = pALD(q=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,df,type="l",lwd=2,col="blue",xlab="x",ylab="F(x)", main="ALD Distribution function")
abline(h=1,lty=2)

##Inverse Distribution Function
prob = seq(0,1,length.out = 1000)
idf = qALD(prob=prob,mu=50,sigma=3,p=0.75)
plot(prob,idf,type="l",lwd=2,col="gray30",xlab="x",ylab=expression(F^{-1}~(x)))
title(main="ALD Inverse Distribution function")
abline(v=c(0,1),lty=2)

#Random Sample Histogram
sample = rALD(n=10000,mu=50,sigma=3,p=0.75)
hist(sample,breaks = 70,freq = FALSE,ylim=c(0,max(dens)),main="")
title(main="Histogram and True density")
lines(sseq,dens,col="red",lwd=2)

## Let's compute the MLE's

param = c(-323,40,0.9)
y = rALD(10000,mu = param[1],sigma = param[2],p = param[3])  #A random sample
res = mleALD(y)

#Comparing
cbind(param,res$par)

#Let's plot

seqq = seq(min(y),max(y),length.out = 1000)
dens = dALD(y=seqq,mu=res$par[1],sigma=res$par[2],p=res$par[3])
hist(y,breaks=50,freq = FALSE,ylim=c(0,max(dens)))
lines(seqq,dens,type="l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")

The Asymmetric Laplace Distribution

Description

Density, distribution function, quantile function and random generation for a Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p This is a special case of the skewed family of distributions in Galarza (2016) available in lqr::SKD.

Usage

dALD(y, mu = 0, sigma = 1, p = 0.5)
pALD(q, mu = 0, sigma = 1, p = 0.5, lower.tail = TRUE)
qALD(prob, mu = 0, sigma = 1, p = 0.5, lower.tail = TRUE)
rALD(n, mu = 0, sigma = 1, p = 0.5)

Arguments

y, q

vector of quantiles.

prob

vector of probabilities.

n

number of observations.

mu

location parameter.

sigma

scale parameter.

p

skewness parameter.

lower.tail

logical; if TRUE (default), probabilities are P[X \le x] otherwise, P[X > x].

Details

If mu, sigma or p are not specified they assume the default values of 0, 1 and 0.5, respectively, belonging to the Symmetric Standard Laplace Distribution denoted by ALD(0,1,0.5)ALD(0,1,0.5).

As discussed in Koenker and Machado (1999) and Yu and Moyeed (2001) we say that a random variable Y is distributed as an ALD with location parameter μ\mu, scale parameter σ>0\sigma>0 and skewness parameter pp in (0,1), if its probability density function (pdf) is given by

f(yμ,σ,p)=p(1p)σexpρp(yμσ)f(y|\mu,\sigma,p)=\frac{p(1-p)}{\sigma}\exp {-\rho_{p}(\frac{y-\mu}{\sigma})}

where ρp(.)\rho_p(.) is the so called check (or loss) function defined by

ρp(u)=u(pIu<0)\rho_p(u)=u(p - I_{u<0})

, with I.I_{.} denoting the usual indicator function. This distribution is denoted by ALD(μ,σ,p)ALD(\mu,\sigma,p) and it's pp-th quantile is equal to μ\mu.

The scale parameter sigma must be positive and non zero. The skew parameter p must be between zero and one (0<p<1).

Value

dALD gives the density, pALD gives the distribution function, qALD gives the quantile function, and rALD generates a random sample.

The length of the result is determined by n for rALD, and is the maximum of the lengths of the numerical arguments for the other functions dALD, pALD and qALD.

Note

The numerical arguments other than n are recycled to the length of the result.

Author(s)

Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>

References

Galarza Morales, C., Lachos Davila, V., Barbosa Cabral, C., and Castro Cepero, L. (2017) Robust quantile regression using a generalized class of skewed distributions. Stat,6: 113-130 doi: 10.1002/sta4.140.

Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.

See Also

momentsALD,likALD,mleALD

Examples

## Let's plot an Asymmetric Laplace Distribution!

##Density
library(ald)
sseq = seq(-40,80,0.5)
dens = dALD(y=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,dens,type = "l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")

#Look that is a special case of the skewed family in Galarza (2017)
# available in lqr package, dSKD(...,sigma = 2*3,dist = "laplace")

## Distribution Function
df = pALD(q=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,df,type="l",lwd=2,col="blue",xlab="x",ylab="F(x)", main="ALD Distribution function")
abline(h=1,lty=2)

##Inverse Distribution Function
prob = seq(0,1,length.out = 1000)
idf = qALD(prob=prob,mu=50,sigma=3,p=0.75)
plot(prob,idf,type="l",lwd=2,col="gray30",xlab="x",ylab=expression(F^{-1}~(x)))
title(main="ALD Inverse Distribution function")
abline(v=c(0,1),lty=2)

#Random Sample Histogram
sample = rALD(n=10000,mu=50,sigma=3,p=0.75)
hist(sample,breaks = 70,freq = FALSE,ylim=c(0,max(dens)),main="")
title(main="Histogram and True density")
lines(sseq,dens,col="red",lwd=2)

Log-Likelihood function for the Asymmetric Laplace Distribution

Description

Log-Likelihood function for the Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p.

Usage

likALD(y, mu = 0, sigma = 1, p = 0.5, loglik = TRUE)

Arguments

y

observation vector.

mu

location parameter μ\mu.

sigma

scale parameter σ\sigma.

p

skewness parameter pp.

loglik

logical; if TRUE (default), the Log-likelihood is return, if not just the Likelihood.

Details

If mu, sigma or p are not specified they assume the default values of 0, 1 and 0.5, respectively, belonging to the Symmetric Standard Laplace Distribution denoted by ALD(0,1,0.5)ALD(0,1,0.5).

As discussed in Koenker and Machado (1999) and Yu and Moyeed (2001) we say that a random variable Y is distributed as an ALD with location parameter μ\mu, scale parameter σ>0\sigma>0 and skewness parameter pp in (0,1), if its probability density function (pdf) is given by

f(yμ,σ,p)=p(1p)σexpρp(yμσ)f(y|\mu,\sigma,p)=\frac{p(1-p)}{\sigma}\exp {-\rho_{p}(\frac{y-\mu}{\sigma})}

where ρp(.)\rho_p(.) is the so called check (or loss) function defined by

ρp(u)=u(pIu<0)\rho_p(u)=u(p - I_{u<0})

, with I.I_{.} denoting the usual indicator function. Then the Log-likelihood function is given by

i=1nlog(p(1p)σexpρp(yiμσ))\sum_{i=1}^{n}log(\frac{p(1-p)}{\sigma}\exp {-\rho_{p}(\frac{y_i-\mu}{\sigma})})

.

The scale parameter sigma must be positive and non zero. The skew parameter p must be between zero and one (0<p<1).

Value

likeALD returns the Log-likelihood by default and just the Likelihood if loglik = FALSE.

Author(s)

Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>

References

Koenker, R., Machado, J. (1999). Goodness of fit and related inference processes for quantile regression. J. Amer. Statist. Assoc. 94(3):1296-1309.

Yu, K. & Moyeed, R. (2001). Bayesian quantile regression. Statistics & Probability Letters, 54(4), 437-447.

Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.

See Also

ALD,momentsALD,mleALD

Examples

## Let's compute the log-likelihood for a given sample

y = rALD(n=1000)
loglik = likALD(y)

#Changing the true parameters the loglik must decrease
loglik2 = likALD(y,mu=10,sigma=2,p=0.3)

loglik;loglik2
if(loglik>loglik2){print("First parameters are Better")}

Maximum Likelihood Estimators (MLE) for the Asymmetric Laplace Distribution

Description

Maximum Likelihood Estimators (MLE) for the Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p.

Usage

mleALD(y, initial = NA)

Arguments

y

observation vector.

initial

optional vector of initial values c(μ,σ,p\mu,\sigma,p).

Details

The algorithm computes iteratevely the MLE's via the combination of the MLE expressions for μ\mu and σ\sigma, and then maximizing with rescpect to pp the Log-likelihood function (likALD) using the well known optimize R function. By default the tolerance is 10^-5 for all parameters.

Value

The function returns a list with two objects

iter

iterations to reach convergence.

par

vector of Maximum Likelihood Estimators.

Author(s)

Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>

References

Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.

See Also

ALD,momentsALD,likALD

Examples

## Let's try this function

param = c(-323,40,0.9)
y = rALD(10000,mu = param[1],sigma = param[2],p = param[3])  #A random sample
res = mleALD(y)

#Comparing
cbind(param,res$par)

#Let's plot

seqq = seq(min(y),max(y),length.out = 1000)
dens = dALD(y=seqq,mu=res$par[1],sigma=res$par[2],p=res$par[3])
hist(y,breaks=50,freq = FALSE,ylim=c(0,max(dens)))
lines(seqq,dens,type="l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")

Moments for the Asymmetric Laplace Distribution

Description

Mean, variance, skewness, kurtosis, central moments w.r.t mu and first absolute central moment for the Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p.

Usage

meanALD(mu=0,sigma=1,p=0.5)
varALD(mu=0,sigma=1,p=0.5)
skewALD(mu=0,sigma=1,p=0.5)
kurtALD(mu=0,sigma=1,p=0.5)
momentALD(k=1,mu=0,sigma=1,p=0.5)
absALD(sigma=1,p=0.5)

Arguments

k

moment number.

mu

location parameter μ\mu.

sigma

scale parameter σ\sigma.

p

skewness parameter pp.

Details

If mu, sigma or p are not specified they assume the default values of 0, 1 and 0.5, respectively, belonging to the Symmetric Standard Laplace Distribution denoted by ALD(0,1,0.5)ALD(0,1,0.5).

As discussed in Koenker and Machado (1999) and Yu and Moyeed (2001) we say that a random variable Y is distributed as an ALD with location parameter μ\mu, scale parameter σ>0\sigma>0 and skewness parameter pp in (0,1), if its probability density function (pdf) is given by

f(yμ,σ,p)=p(1p)σexpρp(yμσ)f(y|\mu,\sigma,p)=\frac{p(1-p)}{\sigma}\exp {-\rho_{p}(\frac{y-\mu}{\sigma})}

where ρp(.)\rho_p(.) is the so called check (or loss) function defined by

ρp(u)=u(pIu<0)\rho_p(u)=u(p - I_{u<0})

, with I.I_{.} denoting the usual indicator function. This distribution is denoted by ALD(μ,σ,p)ALD(\mu,\sigma,p) and it's ppth quantile is equal to μ\mu. The scale parameter sigma must be positive and non zero. The skew parameter p must be between zero and one (0<p<1).

Value

meanALD gives the mean, varALD gives the variance, skewALD gives the skewness, kurtALD gives the kurtosis, momentALD gives the kkth central moment, i.e., E(yμ)kE(y-\mu)^k and absALD gives the first absolute central moment denoted by EyμE|y-\mu|.

Author(s)

Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>

References

Koenker, R., Machado, J. (1999). Goodness of fit and related inference processes for quantile regression. J. Amer. Statist. Assoc. 94(3):1296-1309.

Yu, K. & Moyeed, R. (2001). Bayesian quantile regression. Statistics & Probability Letters, 54(4), 437-447.

Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.

See Also

ALD,likALD,mleALD

Examples

## Let's compute some moments for a Symmetric Standard Laplace Distribution.

#Third raw moment
momentALD(k=3,mu=0,sigma=1,p=0.5)

#The well known mean, variance, skewness and kurtosis
meanALD(mu=0,sigma=1,p=0.5)
varALD(mu=0,sigma=1,p=0.5)
skewALD(mu=0,sigma=1,p=0.5)
kurtALD(mu=0,sigma=1,p=0.5)

# and this guy
absALD(sigma=1,p=0.5)