[R] simulate data with binary outcome and correlated predictors
Greg.Snow at imail.org
Tue Nov 11 18:50:16 CET 2008
You could generate all the data as continuous using the idea below, then use the cut function to change some of the normal continuous variables into binary or ordinal variables. It is less clear exactly what the correlation means in this case, but the variables would still have a relationship.
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Delphine COURVOISIER
> Sent: Tuesday, November 11, 2008 7:18 AM
> To: r-help at r-project.org
> Subject: [R] simulate data with binary outcome and correlated
> I would like to simulate data with a binary outcome and a set of
> predictors that are correlated. I want to be able to fix the number of
> event (Y=1) vs. non-event (Y=0). Thus, I fix this and then simulate the
> predictors. I have 2 questions:
> 1. When the predictors are continuous, I can use mvrnorm(). However, if
> I have continuous, ordinal and binary predictors, I'm not sure how to
> simulate accurately the relationships between predictors.
> 2. To specify the coefficients of the regression of Y on predictors, I
> must specify separately the predictors for Y=1 and Y=0, I can vary the
> mean and the variance/covariances of the predictors. However, with this
> approach, it is harder to determine precisely the coefficients of the
> predictors. Any help on how to be as precise as possible on the betas
> would be nice.
> Here is the code I wrote where all predictors are continuous with
> variance =1 and correlations between predictors vary for each condition
> of Y.
> thanks in advance for any suggestions,
> Delphine Courvoisier
> Clinical Epidemiology Division
> University of Geneva Hospital
> +4122 37 29029
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help