# [R] Random draws from an ANOVA-like design with given population effect sizes

Patrick S Forscher schnarrenber at wisc.edu
Mon Feb 6 20:31:39 CET 2012

```Hi all,

Let's say that you have a 3-group categorical predictor x that has the
orthogonal contrasts c1 and c2. I am trying to create a function that,
given x, c1, and c2, creates a normally-distributed y such that c1 and
c2 have effect sizes r1 and r2 specified by the user.

For example, let's say that x, c1, c2, r1, and r2 were created like
the following:

x <- factor(rep(c(1, 2, 3), 100))
(contrasts(x) <- matrix(c(0, -.5, .5, -2/3, 1/3, 1/3), nrow = 3, ncol
= 2, dimnames = list(c("1", "2", "3"), c("c1", "c2"))))

r1 <- .09
r2 <- 0

I'd like to create a function create.y(x, r1, r2) that returns a
vector y of identical length to x such that the effect size (delta
R^2) of c1 = r1 = .09 and the effect size (delta R^2) of c2 = r2 = 0.

Does anybody on the list have any advice about how to do this?  I know
that I should be using the rnorm function, but I'm stuck on which
population means / sds rnorm should use when it does its sampling.