Re: [R] [PS] Two Way ANOVA
Ben, I would like to test the sulfur on the clover field, nitrogen on the clover field and then test for the presence of interaction. Sorry about the last email, seems it really screwed itself over, here it is again, hopefully nicer: Nitrogen(0) Nitrogen(20) Sulfur(0) 4.54 5.73 Sulfur(3)4.647.05 Sulfur(6)5.275.81 Sulfur(9)5.816.30 Each of those is a cell mean of 3 values. Would I simply do as follows?: yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30) sulfur - c(1,2,3,4,1,2,3,4) nitro - c(1,1,1,1,2,2,2,2) summary(aov(yield~sulfur*nitro)) Thanks, DM - Original Message From: Ben Fairbank [EMAIL PROTECTED] To: David Mackovjak [EMAIL PROTECTED] Sent: Wednesday, March 19, 2008 3:14:36 PM Subject: RE: [PS] [R] Two Way ANOVA DM -- I think it would be helpful if you could also tell us what it is you are hoping to find out from the analysis. For example, a statement such as I am seeking to find if there are any effects of the concentration (or presence?) of nitrogen and/or sulfur on the (fill in your dependent variable, such as 'cell division times' or 'changes in unbuffered pH' or whatever it is). That will help readers to see what design you need. For example, do you want to look ONLY for an interaction, or do you want to test for main effects of N and S also? You might like to download Faraway's 2002 paper Practical Regression and Anova Using R as start; google should find it for you. Ben -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Mackovjak Sent: Wednesday, March 19, 2008 5:02 PM To: r-help@r-project.org Subject: [PS] [R] Two Way ANOVA First time using, the mailing list and I'm somewhat new to R, so excuse me if I do anything wrong. I was wondering how I would set up a two way ANOVA for the following data: Nitrogen (0) Nitrogen (20) (cell means) (cell means) [Sulfur means] Sulfur (0) 4.48 5.76 4.52 (4.54) 5.64 (5.73) [5.14] 4.63 5.78 Sulfur (3) 4.70 7.01 4.65 (4.64) 7.11 (7.05) [5.84] 4.57 7.02 Sulfur (6) 5.21 5.88 5.23 (5.27) 5.82 (5.81) [5.54] 5.38 5.73 Sulfur (9) 5.88 6.26 5.98 (5.81) 6.26 (6.30) [6.11] 5.91 6.37 [Nitrogen means] [5.10] [6.22] Source ofVariation SS Sulfur3.15 Nitrogen 7.59 Sulfur x Nitrogen 3.84 Error 0.08 Total14.66 From googling I know I want to get it to the form: fit - aov(y ~ A*B, data=mydataframe) But what would I set for A, B and y? Looking for last minute shopping deals? __ R-help@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. Be a better friend, newshound, and __ R-help@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.
Re: [R] [PS] Two Way ANOVA
I do have the values for each individual values for each cell. They are as follows: N(0)N(20) 4.48 5.76 4.52 5.64 4.635.78 4.70 7.01 4.65 7.11 4.57 7.02 5.21 5.88 5.23 5.82 5.38 5.73 5.88 6.26 5.98 6.26 5.91 6.37 So how would I go about this then? - Original Message From: Rolf Turner [EMAIL PROTECTED] To: David Mackovjak [EMAIL PROTECTED] Sent: Wednesday, March 19, 2008 4:36:47 PM Subject: Re: [R] [PS] Two Way ANOVA With the given structure of your data you CANNOT test for interaction in the general sense. There are no degrees of freedom left for error. If you have access to the (three) individual values in each cell, then you can test for interaction. If these individual values are lost to posterity [Expostulation: Why the expletive deleted do people ***do*** things like this? Use your expletive deleted data, not summary statistics!!!] then you can still test for a ***particular form*** of interaction using Tukey's ``1 degree of freedom for non- additivity' test. I don't know if it's implemented in R, but it wouldn't be hard to roll your own. See ``Analysis of Messy Data'' volume 2 by George A. Milliken and Dallas E. Johnson, van Nostrand Reinhold, 1989, page 7 ff. On 20/03/2008, at 12:03 PM, David Mackovjak wrote: Ben, I would like to test the sulfur on the clover field, nitrogen on the clover field and then test for the presence of interaction. Sorry about the last email, seems it really screwed itself over, here it is again, hopefully nicer: Nitrogen(0) Nitrogen(20) Sulfur(0) 4.54 5.73 Sulfur(3)4.647.05 Sulfur(6)5.275.81 Sulfur(9)5.816.30 Each of those is a cell mean of 3 values. Would I simply do as follows?: yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30) sulfur - c(1,2,3,4,1,2,3,4) nitro - c(1,1,1,1,2,2,2,2) Not quite; you need to make sulfur and nitro into ***factors***. summary(aov(yield~sulfur*nitro)) Better, I think, to use lm() directly rather than the aov() wrapper. fit - lm(yield ~ sulfur*nitro) anova(fit) You see that you get no F-tests. The model fits ``perfectly'' so there is no residual sum of squares (and no degrees of freedom for error). cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:17}} __ R-help@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.
Re: [R] [PS] Two Way ANOVA
You put all the responses into one vector and the appropriate independents Sulfur and nitrogen into the other. So your table would look like this (see below). You would test. summary(aov(Dependent~factor(Nitrogen)*factor(Sulfur))). And your output would look likt this (see further below) from which you can start in-depth analyses. Dependent NitrogenSulfur 4.481 1 4.521 1 4.631 1 4.7 1 2 4.651 2 4.571 2 5.211 3 5.231 3 5.381 3 5.881 4 5.981 4 5.911 4 5.762 1 5.642 1 5.782 1 7.012 2 7.112 2 7.022 2 5.882 3 5.822 3 5.732 3 6.262 4 6.262 4 6.372 4 Df Sum Sq Mean Sq F valuePr(F) factor(Nitrogen) 1 7.5937 7.5937 1514.96 2.2e-16 *** factor(Sulfur) 3 3.1543 1.0514 209.76 4.717e-13 *** factor(Nitrogen):factor(Sulfur) 3 3.8358 1.2786 255.08 1.024e-13 *** Residuals 16 0.0802 0.0050 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von David Mackovjak Gesendet: Wednesday, March 19, 2008 7:55 PM An: Rolf Turner; R-help@r-project.org Betreff: Re: [R] [PS] Two Way ANOVA I do have the values for each individual values for each cell. They are as follows: N(0)N(20) 4.48 5.76 4.52 5.64 4.635.78 4.70 7.01 4.65 7.11 4.57 7.02 5.21 5.88 5.23 5.82 5.38 5.73 5.88 6.26 5.98 6.26 5.91 6.37 So how would I go about this then? - Original Message From: Rolf Turner [EMAIL PROTECTED] To: David Mackovjak [EMAIL PROTECTED] Sent: Wednesday, March 19, 2008 4:36:47 PM Subject: Re: [R] [PS] Two Way ANOVA With the given structure of your data you CANNOT test for interaction in the general sense. There are no degrees of freedom left for error. If you have access to the (three) individual values in each cell, then you can test for interaction. If these individual values are lost to posterity [Expostulation: Why the expletive deleted do people ***do*** things like this? Use your expletive deleted data, not summary statistics!!!] then you can still test for a ***particular form*** of interaction using Tukey's ``1 degree of freedom for non- additivity' test. I don't know if it's implemented in R, but it wouldn't be hard to roll your own. See ``Analysis of Messy Data'' volume 2 by George A. Milliken and Dallas E. Johnson, van Nostrand Reinhold, 1989, page 7 ff. On 20/03/2008, at 12:03 PM, David Mackovjak wrote: Ben, I would like to test the sulfur on the clover field, nitrogen on the clover field and then test for the presence of interaction. Sorry about the last email, seems it really screwed itself over, here it is again, hopefully nicer: Nitrogen(0) Nitrogen(20) Sulfur(0) 4.54 5.73 Sulfur(3)4.647.05 Sulfur(6)5.275.81 Sulfur(9)5.816.30 Each of those is a cell mean of 3 values. Would I simply do as follows?: yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30) sulfur - c(1,2,3,4,1,2,3,4) nitro - c(1,1,1,1,2,2,2,2) Not quite; you need to make sulfur and nitro into ***factors***. summary(aov(yield~sulfur*nitro)) Better, I think, to use lm() directly rather than the aov() wrapper. fit - lm(yield ~ sulfur*nitro) anova(fit) You see that you get no F-tests. The model fits ``perfectly'' so there is no residual sum of squares (and no degrees of freedom for error). cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:17}} __ R-help@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. __ R-help@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.
Re: [R] [PS] Two Way ANOVA
Btw. you can plot the effect by looking at the following graph with using either Sulfur or Nitrogen as the trace or x-axis: interaction.plot(Sulfur,Nitrogen,Dependent) interaction.plot(Nitrogen,Sulfur,Dependent) Cheers, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von David Mackovjak Gesendet: Wednesday, March 19, 2008 7:55 PM An: Rolf Turner; R-help@r-project.org Betreff: Re: [R] [PS] Two Way ANOVA I do have the values for each individual values for each cell. They are as follows: N(0)N(20) 4.48 5.76 4.52 5.64 4.635.78 4.70 7.01 4.65 7.11 4.57 7.02 5.21 5.88 5.23 5.82 5.38 5.73 5.88 6.26 5.98 6.26 5.91 6.37 So how would I go about this then? - Original Message From: Rolf Turner [EMAIL PROTECTED] To: David Mackovjak [EMAIL PROTECTED] Sent: Wednesday, March 19, 2008 4:36:47 PM Subject: Re: [R] [PS] Two Way ANOVA With the given structure of your data you CANNOT test for interaction in the general sense. There are no degrees of freedom left for error. If you have access to the (three) individual values in each cell, then you can test for interaction. If these individual values are lost to posterity [Expostulation: Why the expletive deleted do people ***do*** things like this? Use your expletive deleted data, not summary statistics!!!] then you can still test for a ***particular form*** of interaction using Tukey's ``1 degree of freedom for non- additivity' test. I don't know if it's implemented in R, but it wouldn't be hard to roll your own. See ``Analysis of Messy Data'' volume 2 by George A. Milliken and Dallas E. Johnson, van Nostrand Reinhold, 1989, page 7 ff. On 20/03/2008, at 12:03 PM, David Mackovjak wrote: Ben, I would like to test the sulfur on the clover field, nitrogen on the clover field and then test for the presence of interaction. Sorry about the last email, seems it really screwed itself over, here it is again, hopefully nicer: Nitrogen(0) Nitrogen(20) Sulfur(0) 4.54 5.73 Sulfur(3)4.647.05 Sulfur(6)5.275.81 Sulfur(9)5.816.30 Each of those is a cell mean of 3 values. Would I simply do as follows?: yield- c(4.54,4.64,5.27,5.81,5.73,7.05,5.81,6.30) sulfur - c(1,2,3,4,1,2,3,4) nitro - c(1,1,1,1,2,2,2,2) Not quite; you need to make sulfur and nitro into ***factors***. summary(aov(yield~sulfur*nitro)) Better, I think, to use lm() directly rather than the aov() wrapper. fit - lm(yield ~ sulfur*nitro) anova(fit) You see that you get no F-tests. The model fits ``perfectly'' so there is no residual sum of squares (and no degrees of freedom for error). cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:17}} __ R-help@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. __ R-help@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.
Re: [R] [PS] Two Way ANOVA
On 20/03/2008, at 12:54 PM, David Mackovjak wrote: I do have the values for each individual values for each cell. They are as follows: N(0)N(20) 4.48 5.76 4.52 5.64 4.635.78 4.70 7.01 4.65 7.11 4.57 7.02 5.21 5.88 5.23 5.82 5.38 5.73 5.88 6.26 5.98 6.26 5.91 6.37 So how would I go about this then? (1) Assign to ``yield'' the foregoing 24 values. (2) Set up a factor ``nitro'' giving the corresponding levels of nitrogen (e.g. with labels ``n0'' and ``n20'' --- rather than ``1'' and ``2'' to be more evocative and to make it clear that the value of ``nitro'' are ***not*** numeric!). (3) Likewise set up a factor ``sulfur'' with labels, say ``s0'', ``s3'', ``s6'', ``s9''. Note that yield is a numeric vector of length 24, nitro and sulfur are factors (with 2 and 4 levels respectively) also (of course!) of length 24. (4) Fit your linear model: fit - lm(yield ~ nitro*sulfur) (5) Do your analysis of variance: anova(fit) (6) Check that the anova assumptions seem to be OK: plot(fitted(fit),resid(fit)) # Looks pretty good to me. (7) An interaction plot might be illuminating: interaction.plot(sulfur,nitro,yield) # The (n20,s3) cell sticks out like a sore toe. Since there *is* interaction you might want to treat the modelling exercise as a one-way anova on an 8-level factor (one level for each cell). You can create the appropriate factor using ``interaction()''. You could fit the one-way model (use aov() this time; TukeyHSD demands it!) and then do TukeyHSD() to the result to find out what really differs from what. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@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.