rbeta-distribution

four parameter beta distribution in R


Is there a built-in function to calculate a four parameter beta distribution in R? I.e., the distribution with two shape parameters and two boundary parameters so that it's not bounded [0,1]?

I made my own but curious if this functionality exists already. No need to reinvent the wheel.

shp1 <- 20
shp2 <- 5
X <- seq(0,1,length.out = 100)
Y <- dbeta(x = X,shape1 = shp1, shape2 = shp2)
plot(X,Y)
# scaled between two boundaries
dbeta4param <- function(x,shp1,shp2,bnd1,bnd2){
  mask = (x>=bnd1 & x<=bnd2)
  xScale = (x-bnd1)/(bnd2-bnd1)
  mask * dbeta(xScale,shape1=shp1,shape2=shp2)/(bnd2-bnd1)
}
bnd1 <- 2
bnd2 <- 4
X2 <- seq(bnd1,bnd2,length.out = 100)
Y2 <- dbeta4param(x=X2, shp1 = shp1, shp2 = shp2, bnd1 = bnd1, bnd2 = bnd2)
plot(X2,Y2)

Solution

  • CRAN Task View: Probability Distributions is always a good resource about where to find various R probability distributions. According to it, you should use the extraDistr package (extraDistr::rnsbeta for example).