# How to generate correlated test data that has Bernoulli, categorical, and continuous vectors (in R)?

I'm looking to generate a set of 5 random variables and enforce a dependence structure between them and onto a dependent variable $Y$. I understand how to generate correlated random variables for multivariate normal, but not when mixing different types. Below is a little more than I need, but I'm hoping someone can give me a general way of solving this problem...

• $X_1$ and $X_2$ need to be highly correlated Bernoulli variables.
• $X_3$ needs to take one of 5 categorical values, call them "A"..."E".
• $X_4$ needs to be normal, and negatively correlated with $X_1$, $X_2$.
• $X_5$ needs to approximate test scores from $0$ to $100$ with a high skew, so gamma probably. $X_5$ needs to be positively correlated with $X_1$, $X_2$, $X_4$.

Each of these variables must impact a "success/occurrence" Bernoulli distributed variable $Y$.

How would I begin? I would like to enforce correlation both between the values of $X$, and also between each $X$ and $Y$. (The categorical correlations seem particularly confusing to me.)

Using copulas is one way of generating dependent or (rank) correlated data from multivariable distributions that are not necessarily normal. Here is a simple example of doing this in Matlab: Simulating Dependent Random Variables Using Copulas. I am not sure if this can handle categorical variables though.

• For R there are the packages copula and CDVine – Felix S Feb 15 '12 at 8:06
• Thanks, that helped. I realized how to turn copulas into what I needed. It required binning the correlated Uniforms into categories. – Mittenchops Feb 15 '12 at 21:36
• Mittenchops, I am trying to do something similar to what you have described above. I have used copulas to generate correlated binary and continuous data. However, I'm having a little trouble figuring out how to generate correalted data for one multinomial (or categorical) variable and one binary variable. I've attempted to bin the generated uniform data, however with little success in recapturing the correlation specified to generate the data. Can you explain further how you went about this? In relation to your original question, I am wanting to generate X1 and X3. – user7295 Feb 22 '12 at 10:09