Beta: (Weighted) MLE of Beta Distribution

Description Usage Arguments Value Author(s) Examples

View source: R/Beta.R

Description

Beta distribution is characterized by the following probability density function,

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

where the domain is x \in [0,1] with two shape parameters α and β. B(α,β) is beta function.

Usage

1
Beta(x, weight = NULL)

Arguments

x

a length-n vector of values in [0,1].

weight

a length-n weight vector. If set as NULL, it gives an equal weight, leading to standard MLE.

Value

a named list containing (weighted) MLE of

alpha

shape parameter α.

beta

shape parameter β.

Author(s)

Kisung You

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## Beta(1,1) = Unif(0,1) : Can we find it ?
#  generate data
x = stats::runif(100)

#  fit unweighted
Beta(x)

## Not run: 
# put random weights to see effect of weights
niter = 1000
ndata = 200

# generate data as above and fit unweighted MLE
x    = stats::runif(ndata)
xmle = Beta(x)

# iterate
vec.alpha = rep(0,niter)
vec.beta  = rep(0,niter)
for (i in 1:niter){
  # random weight
  ww = abs(stats::rnorm(ndata))

  MLE = Beta(x, weight=ww)
  vec.alpha[i] = MLE$alpha
  vec.beta[i]  = MLE$beta
  if ((i%%10) == 0){
    print(paste0(" iteration ",i,"/",niter," complete.."))
  }
}

# distribution of weighted estimates + standard MLE
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
hist(vec.alpha, main="shape 'alpha'")
abline(v=xmle$alpha, lwd=2, col="red")
hist(vec.beta,  main="shape 'beta'")
abline(v=xmle$beta, lwd=2, col="blue")
par(opar)

## End(Not run) 

kyoustat/T4mle documentation built on March 26, 2020, 12:09 a.m.