Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
R in Action, Second Edition.pdf
Скачиваний:
540
Добавлен:
26.03.2016
Размер:
20.33 Mб
Скачать

dose

0.5

1

2

response.var

supp

OJ

VC

 

 

 

 

 

 

 

 

Repeated measures ANOVA

 

 

 

 

 

 

 

229

 

 

 

len: main effects and 2−way interactions

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

len ~ supp | dose

 

 

 

 

len ~ dose | dose

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

30

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

25

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

20

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

len

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

15

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

10

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

len ~ supp | supp

 

 

 

 

len ~ dose | supp

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

30

Figure 9.8 Main effects

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

25

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

20

and two-way interaction

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

for the ToothGrowth

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

len

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

15

dataset. This plot was

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

10

created by the

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5

interaction2way()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

function.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

OJ

 

VC

0.5

1

 

 

2

 

 

 

 

 

 

 

 

 

 

supp

 

 

 

 

 

dose

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

x.values

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finally, you can use the interaction2wt() function in the HH package to produce a plot of both main effects and two-way interactions for any factorial design of any order (figure 9.8):

library(HH)

interaction2wt(len~supp*dose)

Again, this figure has been modified to display more clearly in black and white and will look slightly different when you run the code yourself.

All three graphs indicate that tooth growth increases with the dose of ascorbic acid for both orange juice and Vitamin C. For the 0.5 and 1 mg doses, orange juice produced more tooth growth than Vitamin C. For 2 mg of ascorbic acid, both delivery methods produced identical growth.

Of the three plotting methods provided, I prefer the interaction2wt() function in the HH package. It displays both the main effects (the box plots) and the two-way interactions for designs of any complexity (two-way ANOVA, three-way ANOVA, and so on).

Although I don’t cover the tests of model assumptions and mean comparison procedures, they’re a natural extension of the methods you’ve seen so far. Additionally, the design is balanced, so you don’t have to worry about the order of effects.

9.6Repeated measures ANOVA

In repeated measures ANOVA, subjects are measured more than once. This section focuses on a repeated measures ANOVA with one within-groups and one

230

CHAPTER 9 Analysis of variance

between-groups factor (a common design). We’ll take our example from the field of physiological ecology. Physiological ecologists study how the physiological and biochemical processes of living systems respond to variations in environmental factors (a crucial area of study given the realities of global warming). The CO2 dataset included in the base installation contains the results of a study of cold tolerance in Northern and Southern plants of the grass species Echinochloa crus-galli (Potvin, Lechowicz, & Tardif, 1990). The photosynthetic rates of chilled plants were compared with the photosynthetic rates of nonchilled plants at several ambient CO2 concentrations. Half the plants were from Quebec, and half were from Mississippi.

In this example, we’ll focus on chilled plants. The dependent variable is carbon dioxide uptake (uptake) in ml/L, and the independent variables are Type (Quebec versus Mississippi) and ambient CO2 concentration (conc) with seven levels (ranging from 95 to 1000 umol/m^2 sec). Type is a between-groups factor, and conc is a withingroups factor. Type is already stored as a factor, but you’ll need to convert conc to a factor before continuing. The analysis is presented in the next listing.

Listing 9.7 Repeated measures ANOVA with one betweenand within-groups factor

>CO2$conc <- factor(CO2$conc)

>w1b1 <- subset(CO2, Treatment=='chilled')

>fit <- aov(uptake ~ conc*Type + Error(Plant/(conc)), w1b1)

>summary(fit)

Error: Plant

 

 

 

 

 

 

 

Df Sum Sq Mean Sq F value

Pr(>F)

 

Type

1

2667

 

2667

60.4

0.0015

**

Residuals

4

177

 

44

 

 

 

---

 

 

 

 

 

 

 

Signif. codes:

0 '***'

0.001 '**' 0.01 '*'

0.05 '.' 0.1 ' ' 1

Error: Plant:conc

 

 

 

 

 

 

Df Sum Sq Mean Sq F value

Pr(>F)

 

conc

6

1472

245.4

52.5

1.3e-12

***

conc:Type

6

429

 

71.5

15.3

3.7e-07

***

Residuals 24

112

 

4.7

 

 

 

---

 

 

 

 

 

 

 

Signif. codes:

0 '***'

0.001 '**' 0.01 '*'

0.05 '.' 0.1 ' ' 1

>par(las=2)

>par(mar=c(10,4,4,2))

>with(w1b1, interaction.plot(conc,Type,uptake, type="b", col=c("red","blue"), pch=c(16,18),

main="Interaction Plot for Plant Type and Concentration"))

>boxplot(uptake ~ Type*conc, data=w1b1, col=(c("gold", "green")), main="Chilled Quebec and Mississippi Plants",

ylab="Carbon dioxide uptake rate (umol/m^2 sec)")

The ANOVA table indicates that the Type and concentration main effects and the Type × concentration interaction are all significant at the 0.01 level. The interaction is plotted via the interaction.plot() function in figure 9.9.

Repeated measures ANOVA

231

mean of uptake

Interaction Plot for Plant Type and Concentration

40

 

 

 

 

 

 

 

 

Type

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

35

 

 

 

 

 

 

 

 

 

Quebec

 

 

 

 

 

 

 

 

 

 

Mississippi

 

 

 

 

 

 

 

 

 

 

 

30

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

25

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

20

 

 

 

 

 

 

 

 

 

 

Figure 9.9 Interaction of

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ambient CO2 concentration

15

 

 

 

 

 

 

 

 

 

 

and plant type on CO2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

uptake. Graph produced by

10

 

 

 

 

 

 

 

 

 

 

the interaction.plot()

 

 

 

 

 

 

 

 

 

 

function.

 

 

 

 

 

 

 

 

 

 

 

95

175

250

350

500

675

1000

 

 

 

 

 

 

 

 

 

 

 

conc

 

 

 

 

 

In order to demonstrate a different presentation of the interaction, the boxplot() function is used to plot the same data. The results are provided in figure 9.10.

Chilled Quebec and Mississippi Plants

Carbon dioxide uptake rate (umol/m^2 sec)

40

35

30

25

20

15

10

Quebec.95

Mississippi.95

Quebec.175

Mississippi.175

Quebec.250

Mississippi.250

Quebec.350

Mississippi.350

Quebec.500

Mississippi.500

Quebec.675

Mississippi.675

Quebec.1000

Mississippi.1000

Figure 9.10 Interaction of ambient CO2 concentration and plant type on CO2 uptake. Graph produced by the boxplot() function.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]