Create an Extended-Support Beta Mixture Distribution

Description

Class and methods for extended-support beta distributions using the workflow from the distributions3 package.

Usage

XBetaX(mu, phi, nu = 0)

Arguments

mu numeric. The mean of the underlying beta distribution on [-nu, 1 + nu].
phi numeric. The precision parameter of the underlying beta distribution on [-nu, 1 + nu].
nu numeric. Mean of the exponentially-distributed exceedence parameter for the underlying beta distribution on [-nu, 1 + nu] that is censored to [0, 1].

Details

The extended-support beta mixture distribution is a continuous mixture of extended-support beta distributions on [0, 1] where the underlying exceedence parameter is exponentially distributed with mean nu. Thus, if nu > 0, the resulting distribution has point masses on the boundaries 0 and 1 with larger values of nu leading to higher boundary probabilities. For nu = 0 (the default), the distribution reduces to the classic beta distribution (in regression parameterization) without boundary observations.

Value

A XBetaX distribution object.

See Also

dxbetax, XBeta

Examples

library("betareg")


## package and random seed
library("distributions3")
set.seed(6020)

## three beta distributions
X <- XBetaX(
  mu  = c(0.25, 0.50, 0.75),
  phi = c(1, 1, 2),
  nu = c(0, 0.1, 0.2)
)

X
[1] "XBetaX distribution (mu = 0.25, phi = 1, nu = 0.0)"
[2] "XBetaX distribution (mu = 0.50, phi = 1, nu = 0.1)"
[3] "XBetaX distribution (mu = 0.75, phi = 2, nu = 0.2)"
## compute moments of the distribution
mean(X)
[1] 0.2500000 0.5000000 0.7812779
[1] 0.09375000 0.14932803 0.08290156
## support interval (minimum and maximum)
support(X)
     min max
[1,]   0   1
[2,]   0   1
[3,]   0   1
## it is only continuous when there are no point masses on the boundary
is_continuous(X)
[1]  TRUE FALSE FALSE
cdf(X, 0)
[1] 0.00000000 0.16127596 0.02230181
cdf(X, 1, lower.tail = FALSE)
[1] 0.0000000 0.1612760 0.4004398
## simulate random variables
random(X, 5)
            r_1        r_2         r_3       r_4        r_5
[1,] 0.01770077 0.03196796 0.009185013 0.3511111 0.03417845
[2,] 0.03065274 0.00000000 0.159692910 0.4697419 0.62766314
[3,] 0.40195437 1.00000000 0.675081997 0.9255527 1.00000000
## histograms of 1,000 simulated observations
x <- random(X, 1000)
hist(x[1, ])

hist(x[2, ])

hist(x[3, ])

## probability density function (PDF) and log-density (or log-likelihood)
x <- c(0.25, 0.5, 0.75)
pdf(X, x)
[1] 0.6840925 0.5424706 0.7405552
pdf(X, x, log = TRUE)
[1] -0.3796622 -0.6116213 -0.3003551
log_pdf(X, x)
[1] -0.3796622 -0.6116213 -0.3003551
## cumulative distribution function (CDF)
cdf(X, x)
[1] 0.6453748 0.5000000 0.3312063
## quantiles
quantile(X, 0.5)
[1] 0.09331223 0.50000000 0.93231291
## cdf() and quantile() are inverses (except at censoring points)
cdf(X, quantile(X, 0.5))
[1] 0.5 0.5 0.5
quantile(X, cdf(X, 1))
[1] 1 1 1
## all methods above can either be applied elementwise or for
## all combinations of X and x, if length(X) = length(x),
## also the result can be assured to be a matrix via drop = FALSE
p <- c(0.05, 0.5, 0.95)
quantile(X, p, elementwise = FALSE)
           q_0.05      q_0.5    q_0.95
[1,] 9.512588e-06 0.09331223 0.9118445
[2,] 0.000000e+00 0.50000000 1.0000000
[3,] 1.353857e-01 0.93231291 1.0000000
quantile(X, p, elementwise = TRUE)
[1] 9.512588e-06 5.000000e-01 1.000000e+00
quantile(X, p, elementwise = TRUE, drop = FALSE)
         quantile
[1,] 9.512588e-06
[2,] 5.000000e-01
[3,] 1.000000e+00
## compare theoretical and empirical mean from 1,000 simulated observations
cbind(
  "theoretical" = mean(X),
  "empirical" = rowMeans(random(X, 1000))
)
     theoretical empirical
[1,]   0.2500000 0.2403159
[2,]   0.5000000 0.4935615
[3,]   0.7812779 0.7936076