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. Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: maj at waikato.ac.nz Fax +64-7 838 4155 Phone +64-7 838 4773 home phone +64-7 856 6705 Mobile +64-21 139 5862 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Generating data from an ANOVA model
2 messages · Murray Jorgensen, Brian Ripley
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._