[R] anova

Bill.Venables@CMIS.CSIRO.AU Bill.Venables at CMIS.CSIRO.AU
Thu Dec 28 08:26:54 CET 2000



> -----Original Message-----
> From: Cobalt [mailto:grosso at mail.ru]
> Sent: Friday, 29 December 2000 7:23
> To: r-help at r-project.org
> Subject: [R] anova
> 
> 
> 
> ..Hello,

Well Hello, whoever you are.  (In this list anonymous messages are
considered rather impolite.  Next time please submit your message under your
real name as a gesture of good faith.  For this purpose an informative
signature file is useful.)


> 
> ..I'm learning R and Business Statistics at the same time.
> ..I'm pretty new to R. 
> ..I'm trying to perform ANOVA.
> 
> ..I have 3 samples from 3 populations for anova.
> ..So, I decided to perform anova by doing the following:
> 
> 	a <- (85,75,82,76,71,85)
> 	b <- (71,75,73,74,69,82) 
> 	c <- (59,64,62,69,75,67)

No, no, no.  That's just three syntax errors.  You must at least have had a
"c" before the opening parentheses.

> 
> ..Then,
> 
> 	print.anova(a,b,c)
> 
> ..I got:
> 
> "Error in print.anova(a, b, c) : anova object must have colnames(.)!"
> 
> 
> ..Then,
> 	I tried to create colnames, but probably I didn't 
> understand how to do it properly...And I guess my 'approach' 
> to performing ANOVA in R was definitely wrong too.....

Rather than just go by your feelings, analogies with other packages and
blind hunches it is a good idea to study the system first, or at least read
the manual while you are trying things out.

Here is one way of doing what you probably wanted to do in 3 easy steps:

1. Put your data (response and factor giving the sample to which each
belongs) together in a data frame first:

> 	a <- c(85,75,82,76,71,85)
> 	b <- c(71,75,73,74,69,82) 
> 	c <- c(59,64,62,69,75,67)  # "c" is not the best name to use.
> y <- c(a,b,c)
> f <- factor(rep(c("a","b","c"), rep(6,3)))
> dat <- data.frame(y, f)
> dat
    y f
1  85 a
2  75 a
3  82 a
4  76 a
5  71 a
6  85 a
7  71 b
8  75 b
9  73 b
10 74 b
11 69 b
12 82 b
13 59 c
14 64 c
15 62 c
16 69 c
17 75 c
18 67 c

2. Fit the single classification linear model using the aov fitting
function.


> fm <- aov(y ~ f, dat)


3. The object fm has the information in it needed for many things, including
the generation of an analysis of variance table.

         
> summary(fm)
            Df Sum Sq Mean Sq F value   Pr(>F)
f            2 516.00  258.00       9 0.002703
Residuals   15 430.00   28.67                 
 
> 
> ..Please, help me with ANOVA. I suspect, it's not that 
> difficult...but still can't figure out how to do it.
> ..Thanks in advance.

No, it is not that difficult at all, but unless you are prepared to look at
the documentation and spend a little time studying the examples you are
going to find it very tough going.

Bill Venables.

--
Bill Venables, CSIRO/CMIS Environmetrics Project
Email: Bill.Venables at cmis.csiro.au
Phone: +61 7 3826 7251
Fax:   +61 7 3826 7304
Postal: PO Box 120, Cleveland, Qld 4163, AUSTRALIA
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list