是否有内置函数来计算 R 中的四参数 beta 分布?即,具有两个形状参数和两个边界参数的分布,因此它不是有界的[0,1]?
我自己做了,但很好奇这个功能是否已经存在。无需重新发明轮子。
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)