Last data update: 2014.03.03

R: The Standard Beta Distribution.
BetaR Documentation

The Standard Beta Distribution.

Description

Density, distribution, quantile, random number generation, and parameter estimation functions for the beta distribution with parameters shape1 and shape2. Parameter estimation can be based on a weighted or unweighted i.i.d. sample and can be carried out analytically or numerically.

Usage

dBeta(x, shape1 = 2, shape2 = 3, params = list(shape1, shape2), ...)

pBeta(q, shape1 = 2, shape2 = 3, params = list(shape1, shape2), ...)

qBeta(p, shape1 = 2, shape2 = 3, params = list(shape1, shape2), ...)

rBeta(n, shape1 = 2, shape2 = 3, params = list(shape1, shape2), ...)

eBeta(X, w, method = c("MOM", "numerical.MLE"), ...)

lBeta(X, w, shape1 = 2, shape2 = 3, params = list(shape1, shape2),
  logL = TRUE, ...)

sBeta(X, w, shape1 = 2, shape2 = 3, params = list(shape1, shape2), ...)

iBeta(X, w, shape1 = 2, shape2 = 3, params = list(shape1, shape2), ...)

Arguments

x,q

Vector of quantiles.

shape1,shape2

Shape parameters.

params

A list that includes all named parameters.

...

Additional parameters.

p

Vector of probabilities.

n

Number of observations.

X

Sample observations.

w

Optional vector of sample weights.

method

Parameter estimation method.

logL

logical, if TRUE lBeta gives the log-likelihood, otherwise the likelihood is given.

Details

The dBeta(), pBeta(), qBeta(),and rBeta() functions serve as wrappers of the standard dbeta, pbeta, qbeta, and rbeta functions in the stats package. They allow for the shape parameters to be declared not only as individual numerical values, but also as a list so parameter estimation can be carried out.

The beta distribution with parameters shape1=α and shape2=β is given by

f(x) = frac{x^{α-1} (1-x)^{β-1}}{B(α,β)}

where 0 ≤ x ≤ 1, α>0, β>0, and B is the beta function.

Analytical parameter estimation is conducted using the method of moments. The parameter estimates for α and β are as given in the Engineering Statistics Handbook.

The log-likelihood function of the beta distribution is given by

l(α, β | x) = (α-1)∑_{i} ln(x_i) + (β-1)∑_{i} ln(1-x_i) - ln B(α,β).

Aryal & Nadarajah (2004) derived the score function and Fisher's information matrix for the 4-parameter beta function, from which the 2-parameter cases can be obtained.

Value

dBeta gives the density, pBeta the distribution function, qBeta the quantile function, rBeta generates random deviates, and eBeta estimates the parameters. lBeta provides the log-likelihood function, sBeta the observed score function, and iBeta the observed information matrix.

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. (1995) Continuous Univariate Distributions, volume 2, chapter 25, Wiley, New York.

Engineering Statistics Handbook

Bury, K. (1999) Statistical Distributions in Engineering, Chapter 14, pp.253-255, Cambridge University Press.

Aryal, G. and Nadarajah, S. (2004) Information Matrix for Beta Distributions, Serdica Math. J. 30, 513-526.

See Also

ExtDist for other standard distributions.

Examples

# Parameter estimation for a distribution with known shape parameters
x <- rBeta(n=500, params=list(shape1=2, shape2=2))
est.par <- eBeta(x); est.par
plot(est.par)

# Fitted density curve and histogram
dens <- dBeta(x=seq(0,1,length=100), params=list(shape1=2, shape2=2))
hist(x, breaks=10, probability=TRUE, ylim = c(0,1.2*max(dens)))
lines(seq(0,1,length=100), dens, col="blue")
lines(density(x), lty=2)

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

# Parameter estimation for a distribution with unknown shape parameters
# Example from; Bury(1999) pp.253-255, parameter estimates as given by Bury are
# shape1 = 4.222 and shape2 = 6.317
data <- c(0.461, 0.432, 0.237, 0.113, 0.526, 0.278, 0.275, 0.309, 0.67, 0.428, 0.556,
0.402, 0.472, 0.226, 0.632, 0.533, 0.309, 0.417, 0.495, 0.241)
est.par <- eBeta(X=data, method="numerical.MLE"); est.par
plot(est.par)

# Log-likelihood, score function, and observed information matrix
lBeta(data, param=est.par)
sBeta(data, param=est.par)
iBeta(data, param=est.par)

# Evaluating the precision of parameter estimation by the Hessian matrix.
H <- attributes(est.par)$nll.hessian;H
var <- solve(H)
se <- sqrt(diag(var)); se

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/Beta.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Beta
> ### Title: The Standard Beta Distribution.
> ### Aliases: Beta dBeta eBeta iBeta lBeta pBeta qBeta rBeta sBeta
> 
> ### ** Examples
> 
> # Parameter estimation for a distribution with known shape parameters
> x <- rBeta(n=500, params=list(shape1=2, shape2=2))
> est.par <- eBeta(x); est.par

Parameters for the Beta distribution. 
(found using the  MOM method.)

 Parameter  Type Estimate
    shape1 shape 1.956440
    shape2 shape 1.914144


> plot(est.par)
> 
> # Fitted density curve and histogram
> dens <- dBeta(x=seq(0,1,length=100), params=list(shape1=2, shape2=2))
> hist(x, breaks=10, probability=TRUE, ylim = c(0,1.2*max(dens)))
> lines(seq(0,1,length=100), dens, col="blue")
> lines(density(x), lty=2)
> 
> # Extracting shape parameters
> est.par[attributes(est.par)$par.type=="shape"]
$shape1
[1] 1.95644

$shape2
[1] 1.914144

> 
> # Parameter estimation for a distribution with unknown shape parameters
> # Example from; Bury(1999) pp.253-255, parameter estimates as given by Bury are
> # shape1 = 4.222 and shape2 = 6.317
> data <- c(0.461, 0.432, 0.237, 0.113, 0.526, 0.278, 0.275, 0.309, 0.67, 0.428, 0.556,
+ 0.402, 0.472, 0.226, 0.632, 0.533, 0.309, 0.417, 0.495, 0.241)
> est.par <- eBeta(X=data, method="numerical.MLE"); est.par

Parameters for the Beta distribution. 
(found using the  numerical.MLE method.)

 Parameter  Type Estimate     S.E.
    shape1 shape 4.191737 1.283389
    shape2 shape 6.304651 1.969371


> plot(est.par)
> 
> # Log-likelihood, score function, and observed information matrix
> lBeta(data, param=est.par)
[1] 10.5777
> sBeta(data, param=est.par)
       shape1        shape2 
 3.857847e-07 -8.869954e-07 
> iBeta(data, param=est.par)
          shape1    shape2
shape1  3.386125 -1.999060
shape2 -1.999060  1.438018
> 
> # Evaluating the precision of parameter estimation by the Hessian matrix.
> H <- attributes(est.par)$nll.hessian;H
          shape1    shape2
shape1  3.386125 -1.999060
shape2 -1.999060  1.438018
> var <- solve(H)
> se <- sqrt(diag(var)); se
  shape1   shape2 
1.283389 1.969371 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>