Help with ANOVA in R

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with ANOVA in R

Amit Patel-7
Hi

I am attempting Anova analysis to compare results from four groups
(Samp1-4) which are lists of intensities from the experiment. I am
doing this by first creating a structured list of the data and then
conducting the ANOVA (Script provided below). Im an R beginner so am
not sure if I am using this correctly. Two major questions I have are:

1)
Is using the code (zzz.aov <- aov(Intensity ~ Group + Error(Sample),
data = zzzanova)) the correct method to calculate the variances between
the four groups (samp 1-4). I am unsure of the inclusion of the error
portion.

2) I beleive this method (aov) assumes equal variances. How can I adjust this to do an ANOVA with unequal variances




#####SCRIPT STARTS
#Creates a structured list suitable for ANOVA analysis
# Intensity     Group (1,2,3,4)     Sample(1:62)
"zzzanova" <-
structure(list(Intensity = c(t(Samp1), t(Samp2), t(Samp3), t(Samp4)),
Group = structure(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
         2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
         3,3,3,3,3,3,3,3,3,3,3,3,3,3,
         4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4), .Label = c("Group1", "Group2", "Group3", "Group4"), class = "factor"),
    Sample = structure(c( 1, 2, 3, 4, 5, 6, 7, 8, 9,
    10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
    20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62)
))
, .Names = c("Intensity",
"Group", "Sample"), row.names =
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
"31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
"51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
"61","62"),class = "data.frame")

#Conducts the ANOVA for that PCI
zzz.aov <- aov(Intensity ~ Group + Error(Sample), data = zzzanova)

#####SCRIPT ENDS


THANKS IN ADVANCE




______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with ANOVA in R

Ravi Kulkarni

Your line of code:

  zzz.aov <- aov(Intensity ~ Group + Error(Sample), data = zzzanova)

indicates that you are trying to do a repeated measures ANOVA, not just an ANOVA. The Error(Sample) term in your expression indicates that Sample is a within subjects factor, which I presume is not the case.
The way I understood your data, the Sample column is just an id number for the subjects - is that right?

If you just want to compare the means of Intensity for the the four Groups, then just do:

  zzz.aov <- aov(Intensity ~ Group, data = zzzanova)

You may want to consult this resource for explicit examples of ANOVA in R:

  http://www.personality-project.org/R/r.anova.html

Ravi Kulkarni
Reply | Threaded
Open this post in threaded view
|

Re: Help with ANOVA in R

Vokey, John
In reply to this post by Amit Patel-7
>
> Your line of code:
>
>  zzz.aov <- aov(Intensity ~ Group + Error(Sample), data = zzzanova)
>
> indicates that you are trying to do a repeated measures ANOVA, not just an
> ANOVA. The Error(Sample) term in your expression indicates that Sample is a
> within subjects factor, which I presume is not the case.
> The way I understood your data, the Sample column is just an id number for
> the subjects - is that right?
>
> If you just want to compare the means of Intensity for the the four Groups,
> then just do:
>
>  zzz.aov <- aov(Intensity ~ Group, data = zzzanova)
>
> You may want to consult this resource for explicit examples of ANOVA in R:
>
>  http://www.personality-project.org/R/r.anova.html
>
> Ravi Kulkarni

No, Error(Sample) does NOT indicate a repeated-measures ANOVA.  This use of Error() is, in fact, correct for this between design, and labels the error partition, although not doing so will still return the same result with a generic name for the error partition.  However, slightly more complicated designs (say, one between and one within factor) will *require* the Sample ID vector (as factor) to assign the partitions. [i.e., with s as the factor of IDs, and P as the repeated measure factor, and A as the between factor, then aov(dv~A*P+Error(s/P)) is the correct specification, although I prefer, and instruct my students, to expand explicitly in the aov call, what the call itself expands to: aov(dv~A+P+A:P+Error(s+s:P)), making it clear that there will be two partitions: s and s:P---s being used to test A, and s:P being used to test P and A:P].
--
Please avoid sending me Word or PowerPoint attachments.
See <http://www.gnu.org/philosophy/no-word-attachments.html>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Help with ANOVA in R

lulumecindy
In reply to this post by Amit Patel-7
Hello everyone:
                            I'm a new member of this group.
                            Following the question(2) of Amit Patel-7,
                            I know "oneway.test" has the option of "var.equal=F".
                            Maybe it's can be the answer of this question!
                            But, I have a question about "oneway.test",
                            How can I get "SS", and "MS" information from "oneway.test"?
                            R code and the results are as follows.
                            Thank you very much.  :)

> anova(lm(BackCalac~factor(Assay),data=Control))
Analysis of Variance Table

Response: BackCalac
                      Df  Sum Sq Mean Sq F value    Pr(>F)    
factor(Assay)  4 270.846  67.711  56.219 1.345e-10 ***
Residuals     20  24.088   1.204                      

> oneway.test(BackCalac~factor(Assay), var.equal=T,data=Control)

        One-way analysis of means

data:  BackCalac and factor(Assay)
F = 56.2191, num df = 4, denom df = 20, p-value = 1.345e-10

> oneway.test(BackCalac~factor(Assay), var.equal=F,data=Control)

        One-way analysis of means (not assuming equal variances)

data:  BackCalac and factor(Assay)
F = 92.8834, num df = 4.000, denom df = 9.625, p-value = 1.165e-07