[R] Generating data from an ANOVA model

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Aug 21 08:22:11 CEST 2001


On Tue, 21 Aug 2001, Murray Jorgensen wrote:

> In my teaching I like to try to get across the meaning of the linear models
> assumed in ANOVA by generating artificial data from these models.
>
> When using Minitab I would set up columns of indicator variables for the
> factors and any interactions included and add random normal error to a
> column of means formed as a linear combination of the indicator columns.
>
> I now want to do something similar in R. I am not looking for the shortest
> possible code to do this, but a solution that will make it as obvious as
> possible to the students exactly what is going on.

model.matrix sets up the design matrix, and the rest is straightforward.
E.g. for an n x n Latin square

latin <- expand.grid(rows=1:n, cols=1:n)
latin$treats <- your choice
coefs <- your choice
Y <- model.matrix(~ rows + cols + treats, data=latin) %*% coefs + rnorm(n*n)


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list