Strategy:
- Draw $X_1, ..., X_5$ from a uniform LHS
- Transform $X_1, X_2, X_3$ such that $X_1+X_2+X_3=1$ using the strategy I explained
previously for R. The basic idea is to transform the marginal draws using the quantiles of gamma functions, then normalize those gamma quantiles. The result is a distribution like a Dirichlet distribution (although not exactly).
- Drop $X_3$ since it is not necessary. If $X_1+X_2+X_3=1$ and $X_i > 0$ then $X_1 + X_2 < 1$.
- Transform $X_4$ and $X_5$ to the desired distribution
require(lhs)
qdirichlet <- function(X, alpha)
{
qdirichlet is not an exact quantile function since the quantile of a
multivariate distribtion is not unique
qdirichlet is also not the quantiles of the marginal distributions since
those quantiles do not sum to one
qdirichlet is the quantile of the underlying gamma functions, normalized
This has been tested to show that qdirichlet approximates the dirichlet
distribution well and creates the correct marginal means and variances
when using a latin hypercube sample
lena <- length(alpha)
stopifnot(is.matrix(X))
sims <- dim(X)[1]
stopifnot(dim(X)[2] == lena)
if(any(is.na(alpha)) || any(is.na(X)))
stop("NA values not allowed in qdirichlet")
Y <- matrix(0, nrow=sims, ncol=lena)
ind <- which(alpha != 0)
for(i in ind)
{
Y[,i] <- qgamma(X[,i], alpha[i], 1)
}
Y <- Y / rowSums(Y)
return(Y)
}
set.seed(19753)
X <- randomLHS(500, 5)
Y <- X
transform X1, X2, X3 such that X1 + X2 + X3 =1
change the alpha parameter to change the mean of X1 and X2
Y[,1:3] <- qdirichlet(X[,1:3], rep(2,3))
transform parameter 4 and 5
Y[,4] <- qnorm(X[,4], 2, 1)
Y[,5] <- qunif(X[,5], 1, 3)
drop the unncessary X3
Y <- Y[,-3]
check that X1 + X2 < 1
stopifnot(all(Y[,1] + Y[,2] < 1.0))
plots
par(mfrow = c(2,2))
for (i in c(1,2,4,5))
hist(X[,i], breaks = 20, main = i, xlab = "")
par(mfrow = c(2,2))
for (i in 1:4)
hist(Y[,i], breaks = 20, main = i, xlab = "")