-1
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ 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 $\endgroup$
    – ocram
    Commented Jul 11, 2011 at 7:16
  • $\begingroup$ 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. $\endgroup$
    – Tu.2
    Commented Jul 11, 2011 at 15:12
  • $\begingroup$ @Tu What exactly do you mean by a "risk difference"? $\endgroup$
    – whuber
    Commented Jul 11, 2011 at 16:06
  • $\begingroup$ 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. $\endgroup$
    – Tu.2
    Commented Jul 11, 2011 at 19:36

1 Answer 1

1
$\begingroup$

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 
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.