Created
December 22, 2016 14:34
-
-
Save mikebirdgeneau/a61459aede3a29743c780548753b7fde to your computer and use it in GitHub Desktop.
Multivariate Beta Pert Distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Multivariate Beta PERT distributions | |
#' | |
#' @description Generates random deviates from correlated (modified) pert distributions. | |
#' this is performed by remapping correlated normal distributions to the beta pert | |
#' distributions using quantiles. | |
#' | |
#' @param n Number of observations. If length(n) > 1, the length is taken to be the number required. | |
#' @param min Vector of minima. | |
#' @param mode Vector of modes. | |
#' @param max Vector of maxima. | |
#' @param sigma covariance matrix, default is diag(ncol(x)). | |
#' | |
#' @return Returns a matrix of values of dimensions n x length(mode). | |
#' @export | |
#' | |
#' @examples | |
mvtbetapert <- function(n, min, mode, max, sigma = diag(length(mode))){ | |
# Generate correlated normal distributions: | |
mvn <- mvtnorm::rmvnorm(n, mean = rep(0, length(mode)), sigma = sigma) | |
# Convert to quantiles to be re-mapped to the betaPERT distribution: | |
for (j in 1:ncol(mvn)){ | |
mvn[, j] <- rank(mvn[, j]) / length(mvn[, j]) | |
} | |
# Convert quantiles desired betaPERT distributions | |
for (j in 1:ncol(mvn)){ | |
prt <- rpert(n, min = min[j], mode = mode[j], max = max[j]) | |
mvn[, j] <- quantile(prt, probs = mvn[, j]) | |
} | |
return(mvn) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment