[R] how can i do anova
Joshua Wiley
jwiley.psych at gmail.com
Mon Oct 11 18:10:10 CEST 2010
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:
> Hi,
>
> I've a table like the following. I want to do ANOVA. Could you please tell
> me how can i do it.
> I want to show whether the elements (3 for each column) of a column are
> significantly different or not.
> Just to inform you that i'm a new user of "R"
>
>
> 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
>
>
> Thank you.
>
> Moon
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list