Skip to contents

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

Usage

XBeta(mu = numeric(), phi = numeric(), nu = NULL)

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. Exceedence parameter for the support of the underlying beta distribution on [-nu, 1 + nu] that is censored to [0, 1]. By default nu = 0 is used.

Details

In order to obtain an extended-support beta distribution on [0, 1] an additional exceedence parameter nu is introduced. If nu > 0, this scales the underlying beta distribution to the interval [-nu, 1 + nu] where the tails are subsequently censored to the unit interval [0, 1] with point masses on the boundaries 0 and 1. Thus, nu controls how likely boundary observations are and for nu = 0 (the default), the distribution reduces to the classic beta distribution (in regression parameterization) without boundary observations.

Value

A XBeta distribution object.

See also

Examples

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

## three beta distributions
X <- XBeta(
  mu  = c(0.25, 0.50, 0.75),
  phi = c(1, 1, 2),
  nu = c(0, 0.1, 0.2)
)
# \donttest{
X
#> [1] "XBeta(mu = 0.25, phi = 1, nu = 0.0)" "XBeta(mu = 0.50, phi = 1, nu = 0.1)"
#> [3] "XBeta(mu = 0.75, phi = 2, nu = 0.2)"

## compute moments of the distribution
mean(X)
#> [1] 0.2500 0.5000 0.7887
variance(X)
#> [1] 0.09375 0.15331 0.08617

## 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.00000 0.18643 0.02398
cdf(X, 1, lower.tail = FALSE)
#> [1] 0.0000 0.1864 0.4695

## simulate random variables
random(X, 5)
#>         r_1    r_2     r_3     r_4    r_5
#> [1,] 0.7497 0.8386 0.03197 0.91883 0.5454
#> [2,] 0.1264 1.0000 0.00000 0.07152 0.0000
#> [3,] 1.0000 1.0000 0.86031 1.00000 0.9764

## 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.6841 0.5305 0.6607
pdf(X, x, log = TRUE)
#> [1] -0.3797 -0.6339 -0.4144
log_pdf(X, x)
#> [1] -0.3797 -0.6339 -0.4144

## cumulative distribution function (CDF)
cdf(X, x)
#> [1] 0.6454 0.5000 0.3189

## quantiles
quantile(X, 0.5)
#> [1] 0.09331 0.50000 0.97153

## 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.513e-06 0.09331 0.9118
#> [2,] 0.000e+00 0.50000 1.0000
#> [3,] 1.199e-01 0.97153 1.0000
quantile(X, p, elementwise = TRUE)
#> [1] 9.513e-06 5.000e-01 1.000e+00
quantile(X, p, elementwise = TRUE, drop = FALSE)
#>       quantile
#> [1,] 9.513e-06
#> [2,] 5.000e-01
#> [3,] 1.000e+00

## compare theoretical and empirical mean from 1,000 simulated observations
cbind(
  "theoretical" = mean(X),
  "empirical" = rowMeans(random(X, 1000))
)
#>      theoretical empirical
#> [1,]      0.2500    0.2465
#> [2,]      0.5000    0.4949
#> [3,]      0.7887    0.7956
# }