[R] One way ANOVA with NO model

2006-03-10 Thread Jason Horn
I'd like to do a simple one-way ANOVA comparing the means of 6  
groups.  But it seems like the only way to do an ANOVA in R is to  
specify some sort of model, where there is an outcome or dependent  
variable that is a function of independent variables (linear model).   
But I don't have a linear model, I just want to do a simple ANOVA  
(and f-test) to compare the means.  How do I do this?  My stats  
skills are basic, so please bear with me.

Thanks for any ideas...

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] One way ANOVA with NO model

2006-03-10 Thread Adaikalavan Ramasamy
Suppose you have 6 groups (A, B, C, D, E, F) and you measured the weight
of 5 individuals from each group. Therefore you have 30 weight
observations in total.

You wish to test if the mean of the response variable is different for
each of the groups. 
[ i.e. the null hypothesis is that all 6 groups means are the same. ]


Lets simulate some data first:

 grp - gl(6, k=5, labels=LETTERS[1:6])
 grp
  [1] A A A A A B B B B B C C C C C D D D D D E E E E E F F F F F
 Levels: A B C D E F

 set.seed(1)# for reproducibility only
 w - runif(30, min=40, max=75) # weights 
 w - round(w, digits=1)


Let us first calculate the group means:

   tapply(w, grp, mean)
   A B C D E F
   56.24 62.36 55.54 63.54 55.34 53.94

The group means are close, except for possibly group B and D.


You can do a formal testing by regressing the response (weight) to its
predictors (group). You will need to use the lm() function in R.

   fit - lm( w ~ grp )

 
You can get a summary of the fit by 

   summary(fit)
   ...
   Coefficients:
   Estimate Std. Error t value Pr(|t|)
   (Intercept)   56.240  4.725  11.903 1.48e-11 ***
   grpB   6.120  6.682   0.9160.369
   grpC  -0.700  6.682  -0.1050.917
   grpD   7.300  6.682   1.0930.285
   grpE  -0.900  6.682  -0.1350.894
   grpF  -2.300  6.682  -0.3440.734
   ...

This simply says that the intercept is strongly NOT zero. Based on the
p-values, one can roughly summarise that none of the groups appear to be
different.


Another useful tool is the ANOVA test which tests if the between group
variations are larger than average within group variation.

   anova(fit)
   Analysis of Variance Table

   Response: w
 Df  Sum Sq Mean Sq F value Pr(F)
   grp5  411.15   82.23  0.7367 0.6033
   Residuals 24 2678.79  111.62

This says that there is no significant variation between the groups.

Hope this helps.

Regards, Adai



On Fri, 2006-03-10 at 11:24 -0500, Jason Horn wrote:
 I'd like to do a simple one-way ANOVA comparing the means of 6  
 groups.  But it seems like the only way to do an ANOVA in R is to  
 specify some sort of model, where there is an outcome or dependent  
 variable that is a function of independent variables (linear model).   
 But I don't have a linear model, I just want to do a simple ANOVA  
 (and f-test) to compare the means.  How do I do this?  My stats  
 skills are basic, so please bear with me.
 
 Thanks for any ideas...
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] One way ANOVA with NO model

2006-03-10 Thread Jason Horn
Thanks to all for your help, especially to Adaikalavan for his  
excellent and concise response.  The key (for me) was realizing that  
the one variable that I am measuring is the dependent variable, and  
the groups are the independent variable.  The model can then be  
easily represented in R with fit - lm( variable ~ grp ).

Thanks again!

- Jason


On Mar 10, 2006, at 11:57 AM, Adaikalavan Ramasamy wrote:

 Suppose you have 6 groups (A, B, C, D, E, F) and you measured the  
 weight
 of 5 individuals from each group. Therefore you have 30 weight
 observations in total.

 You wish to test if the mean of the response variable is different for
 each of the groups.
 [ i.e. the null hypothesis is that all 6 groups means are the same. ]


 Lets simulate some data first:

  grp - gl(6, k=5, labels=LETTERS[1:6])
  grp
   [1] A A A A A B B B B B C C C C C D D D D D E E E E E F F F F F
  Levels: A B C D E F

  set.seed(1)# for reproducibility only
  w - runif(30, min=40, max=75) # weights
  w - round(w, digits=1)


 Let us first calculate the group means:

tapply(w, grp, mean)
A B C D E F
56.24 62.36 55.54 63.54 55.34 53.94

 The group means are close, except for possibly group B and D.


 You can do a formal testing by regressing the response (weight) to its
 predictors (group). You will need to use the lm() function in R.

fit - lm( w ~ grp )


 You can get a summary of the fit by

summary(fit)
...
Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)   56.240  4.725  11.903 1.48e-11 ***
grpB   6.120  6.682   0.9160.369
grpC  -0.700  6.682  -0.1050.917
grpD   7.300  6.682   1.0930.285
grpE  -0.900  6.682  -0.1350.894
grpF  -2.300  6.682  -0.3440.734
...

 This simply says that the intercept is strongly NOT zero. Based on the
 p-values, one can roughly summarise that none of the groups appear  
 to be
 different.


 Another useful tool is the ANOVA test which tests if the between group
 variations are larger than average within group variation.

anova(fit)
Analysis of Variance Table

Response: w
  Df  Sum Sq Mean Sq F value Pr(F)
grp5  411.15   82.23  0.7367 0.6033
Residuals 24 2678.79  111.62

 This says that there is no significant variation between the groups.

 Hope this helps.

 Regards, Adai



 On Fri, 2006-03-10 at 11:24 -0500, Jason Horn wrote:
 I'd like to do a simple one-way ANOVA comparing the means of 6
 groups.  But it seems like the only way to do an ANOVA in R is to
 specify some sort of model, where there is an outcome or dependent
 variable that is a function of independent variables (linear model).
 But I don't have a linear model, I just want to do a simple ANOVA
 (and f-test) to compare the means.  How do I do this?  My stats
 skills are basic, so please bear with me.

 Thanks for any ideas...

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting- 
 guide.html




__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html