I want to generate three correlated outcomes for 20 studies. Each study has 3 groups (control, treat1, and treat2). For the control group, my generating values are: mean=0, sd=1; for both treatment groups, my generating values are: mean=0.40, sd=1. Two things that I want to accomplish (which I’m having trouble doing):
1) Condition 1: I want to generate correlated outcome so that there are different correlations between each of the pairs of outcomes. The correlation should be sampled from the vector of correlations, rho=c(0.6, 0.7, 0.8); and
2) Condition 2: I want to generate correlated outcomes so that a subset of the studies (half) will be sample from a vector of correlations, rho1=c(0.6, 0.7, 0.8), and the other subset(remaining half) will be sampled from a vector of correlations, rho2=c(0.3, 0.4, 0.5)
I’m using the “mvtnorm” package to generate the outcomes for each of the groups. Here’s my code (please pardon my very basic knowledge of simulation and R):
library(“mvtnorm”)
set.seed(0307)
mean_c = c(0, 0, 0)
mean_t1 = c(0.4, 0.4, 0.4)
mean_t2 = c(0.4. 0.4, 0.4)
k <- 20 # no. of studies
n <- 50 # sample size
rho <- # the value is sampled from a vector of correlations
for (i in 1:k) {
Yc <-rmvnorm(n=n, mean=mean_c, sigma=rho)
Yt1<-rmvnorm(n=n, mean=mean_t1, sigma=rho)
Yt2 <-rmvnorm(n=n, mean=mean_t2, sigma=rho)
}
I appreciate any inputs from our programming experts here. Thanks!