Skip to content

how can i do anova

6 messages · Andrew Miles, Joshua Wiley, Liviu Andronic +1 more

#
Type ?anova on your R command line for the basic function, and links  
to related functions.

Also, try a google search of something like "doing anova in R" and you  
should find multiple tutorials or examples.

Andrew Miles
On Oct 11, 2010, at 11:33 AM, Mauluda Akhtar wrote:

            
#
Hi Moon,

Here is something to get you started.

# Read Data into R
dat <- read.table(textConnection("
 bp_30048741 bp_30049913 bp_30049953 bp_30049969 bp_30049971 bp_30050044
[1,]          69          46          43          54          54          41
[2,]          68          22          39          31          31          22
[3,]          91          54          57          63          63          50"),
header = TRUE)
closeAllConnections()

# Load the reshape package
library(reshape)

# Generally it is easier to use data in 'long' format
# that is one column with values, another indicate what those are
dat.long <- melt(dat)

# Look at the data
dat.long
# Another useful function that shows the structure of an object
# You should see that 'variable' is a factor with six levels (one for
each column)
# and value is integer class, this is good
str(dat.long)

# Now to fit your model, we can use the aov() function
# The formula specifies the DV on the left and the IVs on the right
# or the outcome and predictors if you think of it that way
# the data = argument tells aov() where to find the data
# in this case in the dat.long variable
model.aov <- aov(value ~ variable, data = dat.long)

# Now you can just print it as is
model.aov
# But you may also like the results of, summary()
summary(model.aov)

# If you're thinking about this from a regression point of view
# Fit linear regression model (must like aov())
model.lm <- lm(value ~ variable, data = dat.long)

# Look at your model
model.lm
summary(model.lm)

# It may seem very different at first, but now if you use the anova()
# (Mind that it is a slightly different function than aov() )
# You can get the ANOVA source table from the regression model
anova(model.lm)

Hope that helps,

Josh
On Mon, Oct 11, 2010 at 8:33 AM, Mauluda Akhtar <mauluda82 at gmail.com> wrote:

  
    
#
Hello
On Mon, Oct 11, 2010 at 5:33 PM, Mauluda Akhtar <mauluda82 at gmail.com> wrote:
Try to do this with either Rcmdr or Deducer, both GUIs to R. Regards
Liviu