I have the written the following code in R with an aim to generate correlated random variables which follow the beta distribution
#objective is to generated correlated #beta distributed data library(MASS) library(faux) generate.beta.parameters <- function(x, v) { alpha = ((1 - x) / v - 1/ x) * x^2 beta = alpha * (1 / x - 1) return (c(alpha, beta)) } x1 <- 0.896 v1 <- 0.001 x2 <- 0.206 v2 <- 0.004 b1 <- generate.beta.parameters(x1, v1) b2 <- generate.beta.parameters(x2, v2) alpha1 <- b1[1] beta1 <- b1[2] alpha2 <- b2[1] beta2 <- b2[2] #create mean vector mu = c(0, 0) #create variance covariance matrix sigma <- rbind(c(1, 0.2), c(0.2, 1)) #generate 1000 random numbers df <- mvrnorm(n = 1000, mu = mu, Sigma = sigma) df.beta <- matrix(nrow = nrow(df), ncol = ncol(df)) #normal to uniform df.beta[,1] = norm2beta(df[,1], alpha1, beta1) df.beta[,2] = norm2beta(df[,2], alpha2, beta2) df.beta <- as.data.frame(df.beta) cor(df.beta) However, on running this code, the correlation outputs are not the same as expected. Here is the output on my machine:
V1 V2 V1 1.0000000 0.1549214 V2 0.1549214 1.0000000 Could you throw some light on this?
I do have this link, where random numbers have been generated, but it is in a different software i.e. SAS.
