Skip to content

Two-factor ANOVA Help

3 messages · Jim Brindle, Gabor Grothendieck

#
On 10/8/05, Jim Brindle <j_brindle at hotmail.com> wrote:
Note that values, as returned from read.table, is already a data frame
and Rater is already a factor so you only need to convert Pipe to a
factor:

values <- read.table("filename.dat", header = TRUE)

# shows classes of columns among other things
# note that Rater is already a factor and values is already a data frame
str(g)

# convert Pipe to a factor
values$Pipe <- factor(values$Pipe)
g <- lm(Volume ~., values)
g
By default R uses treatment contrasts and uses the first level as the baseline.
You can change this using contrasts and contr.treatment.

 e.g. To use treatment effects on Pipe with level 2 as the baseline:

contrasts(values$Pipe) <- contr.treatment(3, base = 2)
g2 <- lm(Volume ~., values)
g2
See ?read.table, ?contrasts, ?contr.treatment
#
On 10/8/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
One more point.  In your #2 the second argument to lm is specified
as values so that's where lm will look for the variables.  The Rater
and Pipe defined immediately above that line will never be found since
those variables will already have been found in the values data frame.