[R] how can i do anova
jwiley.psych at gmail.com
Mon Oct 11 18:10:10 CEST 2010
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)
# Load the reshape package
# 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
# Another useful function that shows the structure of an object
# You should see that 'variable' is a factor with six levels (one for
# and value is integer class, this is good
# 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
# But you may also like the results of, summary()
# 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
# 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
Hope that helps,
On Mon, Oct 11, 2010 at 8:33 AM, Mauluda Akhtar <mauluda82 at gmail.com> wrote:
> 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.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Ph.D. Student, Health Psychology
University of California, Los Angeles
More information about the R-help