# How to generated datasets for estimating risk differences in multiple groups using R? [closed]

I would like to generate datasets which has 3 treatment groups: A, B, and C based on 3 covariates: $x_{1}$, $x_{2}$ and $x_{3}$. The $x_{1}$ and $x_{2}$ are standard normally distributed and $x_{3}$ is Bernoulli (0.5) distributed. Besides these, assume risk difference between A & B = -0.36, A & C = -0.26 and B & C = 0.10. Can someone give me a hint how to generate these datasets in R? many thanks in advance

-
It is not clear to me whether you'd like to generate time-to-event data. If so, then you should have a look at this paper: onlinelibrary.wiley.com/doi/10.1002/sim.2059/abstract –  ocram Jul 11 '11 at 7:16
Hi, the purpose of this simulation study is to verify a proposed statistical method based on the generalized propensity score in observational studies. I would like to measure the bias and MSE in terms of true risk differences between treatment groups by comparing two methods. Before that, I need to generate datasets which have 3 treatment groups with 3 covariates. Thus, the outcome variable is 1/0. Such as A = 67/100, B = 35/74, & C = 77/341. RDab = 67/100 - 35/74, where 100 = $N_{A}$, 67 = number of 1 among the $N_{A}$. Hope this is clear. –  Tu.2 Jul 11 '11 at 15:12
@Tu What exactly do you mean by a "risk difference"? –  whuber Jul 11 '11 at 16:06
risk difference a.k.a "difference of proportions". It is so interesting in US, most of people prefer to use "difference of proportions" but in the Europe they prefer to use "risk difference". However, these two are exactly the same just different name. Thanks. –  Tu.2 Jul 11 '11 at 19:36

## closed as not a real question by Tu.2, whuber♦Aug 14 '12 at 12:20

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

I am not so sure to get what exactly the problem is. If my answer is not what you expect, then you should probably bring some precision...

Let $p_A$, $p_B$, and $p_C$ the proportions of patients receiving treatments $A$, $B$, and $C$, respectively. The constraints are:

$\left\{ \begin{array}{l} p_A - p_B = -0.36 \\ p_A - p_C = -0.26 \\ p_B - p_C = 0.10 \\ p_A + p_B + p_C = 1. \end{array} \right.$

Observe that equation 3 is a direct consequence of the first two.

This leads to $p_A = 0.126666$, $p_B = 0.486666$, and $p_C = 0.386666$.

Now, the multinom function in R can be used to generate treatment allocation.

Hope this helps...

Illustrative example in R that shows the use of the multinom function:

> pA <- 0.126667
> pB <- 0.486666
> pC <- 0.386667
>
> trt <- numeric(10000)
> for(i in 1:10000)
+ {
+   x <- rmultinom(n=1, size=1, prob=c(pA, pB, pC))
+   trt[i] <- which(x==1)
+ }
>
> table(trt) / 10000
trt
1      2      3
0.1260 0.4838 0.3902

-