I have been trying to figure out how to run a simple simulation of the ANOVA and I'm coming up just a bit short. The code I've got is: cohen.f = .25 groups = 4 between.var = 19 within.var = between.var / cohen.f ^ 2 n = 500 sim.means = rnorm(n = groups, mean = 0, sd = sqrt(between.var)) sim.data = lapply(sim.means, function(mean) rnorm(n = n, mean = mean, sd sqrt(within.var))) sim.anova = ? I'm pretty sure I've got data with the between group and within group variances that I want. I don't really know how to run an ANOVA on it though. All the examples I've been able to find (with aov and anova) require an explicit model. The ANOVA just tests the equivalence of means for a set of groups, right? Can I not just tell it to give me the likelihood the means are equal for all the columns without writing an explicit model. Any help would be appreciated, Will [[alternative HTML version deleted]]
On Mar 5, 2008, at 12:03 AM, Will Holcomb wrote:> I have been trying to figure out how to run a simple simulation of > the ANOVA > and I'm coming up just a bit short. The code I've got is: > > cohen.f = .25 > groups = 4 > between.var = 19 > within.var = between.var / cohen.f ^ 2 > n = 500 > sim.means = rnorm(n = groups, mean = 0, sd = sqrt(between.var)) > sim.data = lapply(sim.means, function(mean) rnorm(n = n, mean = > mean, sd > sqrt(within.var))) > sim.anova = ? > > I'm pretty sure I've got data with the between group and within group > variances that I want. I don't really know how to run an ANOVA on > it though. > All the examples I've been able to find (with aov and anova) > require an > explicit model. The ANOVA just tests the equivalence of means for a > set of > groups, right? Can I not just tell it to give me the likelihood the > means > are equal for all the columns without writing an explicit model.I don't know if you can without writing an explicit model or not, but writing the model isn't that hard: simdata2 <- do.call(data.frame, sim.data) names(simdata2) <- LETTERS[1:4] simdata3 <- stack(simdata2) fit <- lm(values~ind, data=simdata3) summary(fit) anova(fit) Unless I misunderstood what you wanted to do.> Any help would be appreciated, > WillHaris Skiadas Department of Mathematics and Computer Science Hanover College
Here is one possible way of proceeding: cohen.f <- 0.25 groups <- 4 between.var <- 19 within.var <- between.var/cohen.f^2 n <- 500 N <- groups*n sim.means <- rnorm(n = groups, mean = 0, sd = sqrt(between.var)) sim.data <- data.frame(group = gl(groups, 1, length = N), response = rnorm(N, sim.means, sqrt(within.var))) sim.anova <- aov(response ~ group, sim.data) ## sim.data <- lapply(sim.means, function(mean) rnorm(n = n, mean mean, sd ## sqrt(within.var))) ## sim.anova <- ? to see the anova table, use summary(sim.anova), for example. Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:Bill.Venables at csiro.au http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Will Holcomb Sent: Wednesday, 5 March 2008 3:03 PM To: r-help Subject: [R] simulating the anova I have been trying to figure out how to run a simple simulation of the ANOVA and I'm coming up just a bit short. The code I've got is: cohen.f = .25 groups = 4 between.var = 19 within.var = between.var / cohen.f ^ 2 n = 500 sim.means = rnorm(n = groups, mean = 0, sd = sqrt(between.var)) sim.data = lapply(sim.means, function(mean) rnorm(n = n, mean = mean, sd sqrt(within.var))) sim.anova = ? I'm pretty sure I've got data with the between group and within group variances that I want. I don't really know how to run an ANOVA on it though. All the examples I've been able to find (with aov and anova) require an explicit model. The ANOVA just tests the equivalence of means for a set of groups, right? Can I not just tell it to give me the likelihood the means are equal for all the columns without writing an explicit model. Any help would be appreciated, Will [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.