[R] Learning to do randomized block design analysis

Bert Gunter gunter.berton at gene.com
Wed Dec 5 00:06:18 CET 2007


Let's be careful here. aov() treats block as a **random** error component of
variance.  lm() treats block as a **fixed effect**. That's a different
kettle of fish. Perhaps both Kevin and the authors of his textbook need to
read up on fixed versus random effects and what they mean -- and what sorts
of tests make sense for each.


Bert Gunter
Genentech Nonclinical Statistics


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of T.K.
Sent: Tuesday, December 04, 2007 2:46 PM
To: Zembower, Kevin
Cc: r-help at r-project.org
Subject: Re: [R] Learning to do randomized block design analysis

This seems to work.
The trick is to use 'lm' instead of 'aov'.

> model.aov <- lm(Score.changes ~ factor(Therapy) + factor(Block),
data=table)
> anova(model.aov)
Analysis of Variance Table

Response: Score.changes
                Df Sum Sq Mean Sq F value   Pr(>F)
factor(Therapy)  2 260.93  130.47  15.259 0.001861 **
factor(Block)    4 438.00  109.50  12.807 0.001484 **
Residuals        8  68.40    8.55
---
Signif. codes:  0 ?**?0.001 ?*?0.01 ??0.05 ??0.1 ??1



On Dec 4, 2007 12:15 PM, Zembower, Kevin <kzembowe at jhuccp.org> wrote:

> We just studied randomized block design analysis in my statistics class,
> and I'm trying to learn how to do them in R. I'm trying to duplicate a
> case study example from my textbook [1]:
>
> > # Case Study 13.2.1, page 778
> > cd <- c(8, 11, 9, 16, 24)
> > dp <- c(2, 1, 12, 11, 19)
> > lm <- c(-2, 0, 6, 2, 11)
> >  table <- data.frame(Block=LETTERS[1:5], "Score changes"=c(cd, dp,
> lm), Therapy=rep(c("Contact Desensitisztion", "Demonstration
> Participation", "Live Modeling"), each=5))
> > table
>   Block Score.changes                     Therapy
> 1      A             8     Contact Desensitisztion
> 2      B            11     Contact Desensitisztion
> 3      C             9     Contact Desensitisztion
> 4      D            16     Contact Desensitisztion
> 5      E            24     Contact Desensitisztion
> 6      A             2 Demonstration Participation
> 7      B             1 Demonstration Participation
> 8      C            12 Demonstration Participation
> 9      D            11 Demonstration Participation
> 10     E            19 Demonstration Participation
> 11     A            -2               Live Modeling
> 12     B             0               Live Modeling
> 13     C             6               Live Modeling
> 14     D             2               Live Modeling
> 15     E            11               Live Modeling
> > model.aov <- aov(Score.changes ~ Therapy + Error(Block), data=table)
> > summary(model.aov)
>
> Error: Block
>          Df Sum Sq Mean Sq F value Pr(>F)
> Residuals  4  438.0   109.5
>
> Error: Within
>          Df Sum Sq Mean Sq F value   Pr(>F)
> Therapy    2 260.93  130.47  15.259 0.001861 **
> Residuals  8  68.40    8.55
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> >
>
> I don't understand why R doesn't output a value for F and Pr for the
> Error (Block) dimension, as my textbook shows 12.807 and 0.0015
> respectively. All the other numbers match. Can these two values be
> recovered? Also, my text shows a total line which R omits. Is this
> because it's not particularly useful?
>
> Thanks for your suggestions and advice. Also, if I'm executing this type
> of problem in R inefficiently, I'd appreciate suggestions.
>
> -Kevin
>
> [1] An Introduction to Mathematical Statistics and Its Applications,
> Larsen and Marx, fourth edition.
>
> Kevin Zembower
> Internet Services Group manager
> Center for Communication Programs
> Bloomberg School of Public Health
> Johns Hopkins University
> 111 Market Place, Suite 310
> Baltimore, Maryland  21202
> 410-659-6139
>
> ______________________________________________
> 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.
>



-- 
======================================
T.K. (Tae-kyun) Kim
Ph.D. student
Department of Marketing
Marshall School of Business
University of Southern California
======================================

	[[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.



More information about the R-help mailing list