#' Beta-PERT
#'
#' https://reference.wolfram.com/language/ref/PERTDistribution.html
#'
#' @param n Sample size
#' @param x.min Lower limit
#' @param x.max Upper limit
#' @param x.mode Mode
#' @param lambda Shape parameter
#'
#' @return sampled value
#'
rpert <- function( n, x.min, x.max, x.mode, lambda = 4 ){
if( x.min > x.max || x.mode > x.max || x.mode < x.min ) stop( "invalid parameters" )
x.range <- x.max - x.min
if( x.range == 0 ) return( rep( x.min, n ))
mu <- ( x.min + x.max + lambda * x.mode ) / ( lambda + 2 )
# special case if mu == mode
if( mu == x.mode ){
v <- ( lambda / 2 ) + 1
}
else {
v <- (( mu - x.min ) * ( 2 * x.mode - x.min - x.max )) /
(( x.mode - mu ) * ( x.max - x.min ));
}
w <- ( v * ( x.max - mu )) / ( mu - x.min )
return ( rbeta( n, v, w ) * x.range + x.min )
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.