Beta4 | R Documentation |
Class and methods for 4-parameter beta distributions in regression specification using the workflow from the distributions3 package.
Beta4(mu, phi, theta1 = 0, theta2 = 1 - theta1)
mu |
numeric. The mean of the beta distribution that is extended to support [theta1, theta2]. |
phi |
numeric. The precision parameter of the beta distribution that is extended to support [theta1, theta2]. |
theta1 , theta2 |
numeric. The minimum and maximum, respectively,
of the 4-parameter beta distribution. By default a symmetric support is
chosen by |
The distribution is obtained by a linear transformation of a beta-distributed
random variable with intercept theta1
and slope theta2 - theta1
.
A Beta4
distribution object.
dbeta4
, BetaR
## package and random seed
library("distributions3")
set.seed(6020)
## three beta distributions
X <- Beta4(
mu = c(0.25, 0.50, 0.75),
phi = c(1, 1, 2),
theta1 = c(0, -0.1, -0.1),
theta2 = c(1, 1.1, 1.5)
)
X
## compute moments of the distribution
mean(X)
variance(X)
## support interval (minimum and maximum)
support(X)
## simulate random variables
random(X, 5)
## 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)
pdf(X, x, log = TRUE)
log_pdf(X, x)
## cumulative distribution function (CDF)
cdf(X, x)
## quantiles
quantile(X, 0.5)
## cdf() and quantile() are inverses
cdf(X, quantile(X, 0.5))
quantile(X, cdf(X, 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)
quantile(X, p, elementwise = TRUE)
quantile(X, p, elementwise = TRUE, drop = FALSE)
## compare theoretical and empirical mean from 1,000 simulated observations
cbind(
"theoretical" = mean(X),
"empirical" = rowMeans(random(X, 1000))
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.