Lab 9_nested_splitplot_R.doc

advertisement
Lab 9: Nested and Split Plot, Split Block, Strip Plot
Example 1:
Researchers conducted an experiment to determine the content of a cardio-vascular drug. They
obtained a random sample of three batches and from each of two blending sites, and from each batch
they selected 5 tablets each.
Data:
Site
Batch
Tablet
1
2
3
4
5
1
1
5.03
2
4.64
5.10
5.25
4.98
5.05
4.73
4.95
4.82
5.06
SAS program:
title1 "Nested analysis";
data tablet;
input y
site1 batch;
cards;
5.03 1
1
5.10 1
1
5.25 1
1
4.98 1
1
5.05 1
1
4.64 1
2
4.73 1
2
4.95 1
2
4.82 1
2
5.06 1
2
5.10 1
3
5.15 1
3
5.20 1
3
5.08 1
3
5.14 1
3
5.05 2
1
4.96 2
1
5.12 2
1
5.12 2
1
5.05 2
1
5.46 2
2
5.15 2
2
5.18 2
2
5.18 2
2
5.11 2
2
4.90 2
3
4.95 2
3
3
5.10
2
1
5.05
2
5.46
3
4.90
5.15
5.20
5.08
5.14
4.96
5.12
5.12
5.05
5.15
5.18
5.18
5.11
4.95
4.86
4.86
5.07
4.86 2
3
4.86 2
3
5.07 2
3
;
proc glm data=tablet;
class site1 batch;
model y=site1 batch(site1);
random batch(site1)/test;
run;
proc mixed data=tablet;
class site1 batch;
model y=site1;
random batch(site1);
run;
Example 2:
In an experiment on the preparation of chocolate cakes, conducted at Iowa State College, 3 Recipes for
o
preparing the batter were compared. Recipes I and II differed in that the chocolate was added at 40 C
o
and 60 C , respectively, while recipe III contained extra sugar. In addition, 6 different baking
o
o
o
Temperatures were tested: these ranged in 10 C steps from 175 to 225 . Each time that a mix was
made by a recipe, enough batter was prepared for 6 cakes, each of which was baked at a different
temperature. In this way, 5 replicates of each recipe were constructed.
The data from this experiment are shown in the following table:
Breaking Angle for Cakes (Degrees, Cochran and Cox, 1957).
Temperature
Recipe
Rep
175
185
195
205
215
1
42
46
47
39
53
2
47
29
35
47
57
1
3
32
32
37
43
45
4
26
32
37
43
39
5
28
30
31
37
41
1
39
46
51
49
55
2
35
46
47
39
52
2
3
34
30
42
35
42
4
25
26
28
46
37
5
31
30
29
35
40
1
46
44
45
46
48
2
43
43
43
46
47
3
3
33
24
40
37
41
4
38
41
38
30
36
5
21
25
31
35
33
________________________________________________________
Breaking Angle for Cakes (Cochran and Cox, 1957).
225
42
45
45
26
47
42
61
35
37
36
63
58
38
35
23
SAS code:
title 'Breaking Angle for Cakes - A Split-Plot Design';
title2 'Whole Plot - CRD with a Oneway Treatment Structure (Recipe)';
title3 'Sub Plot - RCBD with a Oneway Treatment Structure (Temperature)';
data a;
input Recipe Batch Temperature Angle @@;
cards;
1 1 175 42 1 1 185 46 1 1 195 47 1 1 205 39 1 1 215 53 1 1 225 42
1 2 175 47 1 2 185 29 1 2 195 35 1 2 205 47 1 2 215 57 1 2 225 45
1 3 175 32 1 3 185 32 1 3 195 37 1 3 205 43 1 3 215 45 1 3 225 45
1 4 175 26 1 4 185 32 1 4 195 37 1 4 205 43 1 4 215 39 1 4 225 26
1 5 175 28 1 5 185 30 1 5 195 31 1 5 205 37 1 5 215 41 1 5 225 47
2
2
2
2
2
1
2
3
4
5
175
175
175
175
175
39
35
34
25
31
2
2
2
2
2
1
2
3
4
5
185
185
185
185
185
46
46
30
26
30
2
2
2
2
2
1
2
3
4
5
195
195
195
195
195
51
47
42
28
29
2
2
2
2
2
1
2
3
4
5
205
205
205
205
205
49
39
35
46
35
2
2
2
2
2
1
2
3
4
5
215
215
215
215
215
55
52
42
37
40
2
2
2
2
2
1
2
3
4
5
225
225
225
225
225
42
61
35
37
36
3 1 175 46 3 1 185 44 3 1 195 45 3 1 205 46 3 1 215 48 3 1 225 63
3 2 175 43 3 2 185 43 3 2 195 43 3 2 205 46 3 2 215 47 3 2 225 58
3 3 175 33 3 3 185 24 3 3 195 40 3 3 205 37 3 3 215 41 3 3 225 38
3 4 175 38 3 4 185 41 3 4 195 38 3 4 205 30 3 4 215 36 3 4 225 35
3 5 175 21 3 5 185 25 3 5 195 31 3 5 205 35 3 5 215 33 3 5 225 23
;
title4 'Analysis of Cake Data Using Proc GLM with random';
proc glm data = a;
class Recipe Batch Temperature;
model Angle = Recipe Batch(Recipe) Temperature Temperature*Recipe;
random Batch(Recipe)/test;
lsmeans Temperature / pdiff stderr;
run;
title4 'Analysis of Cake Data Using Proc Mixed';
proc mixed data = a;
class Recipe Batch Temperature;
model Angle = Recipe Temperature Temperature*Recipe / ddfm = satterth;
random
Batch(Recipe);
lsmeans Temperature / pdiff;
title4 'Marginal Plot for Mean Angle of Breakage and Temperature';
proc sort data = a; by Temperature;
proc means data = a noprint; by Temperature;
var Angle;
output out = b mean = Meanangl;
run;
proc gplot data = b;
plot Meanangl*Temperature;
run;
R CODE:
mysp=read.csv("spltplt.csv",header=TRUE)
head(mysp)
y=mysp$resp
A=as.factor(mysp$recipe)
sub=as.factor(mysp$batch)
B=as.factor(mysp$temp)
mysp=data.frame(y,A,B,sub)
library(lattice) # Can only list one package at a time
library(car)
library(agricolae)
with(mysp, xyplot(y ~ A | B))
#code for split plot
res.1 <- aov(y ~ A*B + Error(sub/A), data = mysp)
summary(res.1)
#for residual analysis we need to run the model without random effects:
res.2 <- aov(y ~ A*B + sub/A, data = mysp)
plot(res.2)
Example 2: A researcher is interested in comparing the yield among four (4) varieties of Oats which are
planted in combination with four (4) seed treatments. The design chosen consists of four (4) field strips,
each of which is divided into four (4) equal sized units. The four oat varieties are randomly assigned to
the four plots within each field strip. Following the assignment of each variety of oats, each
experimental unit containing a variety of oat, was subdivided into four sub-units. The four seed
treatments were randomly assigned to the four sub-units. This structure can be visualized in the
following field strip:
Seed
Block Treatment
1
1
2
Oat 1
42.9
53.8
Variety
Oat 2 Oat 3
53.3
62.3
57.6
63.4
Oat 4
75.4
70.3
2
3
3
4
49.5
44.4
59.8
64.1
64.5
63.6
68.8
71.6
1
2
3
4
41.6
58.5
53.8
41.8
69.6
69.6
65.8
57.4
58.5
50.4
46.1
56.1
65.6
67.3
65.3
69.4
1
2
3
4
28.9
43.9
40.7
28.3
45.4
42.4
41.4
44.1
44.6
45.0
62.6
52.7
54.0
57.6
45.6
56.6
1
35.1
35.1
50.3
52.7
2
51.9
51.9
46.7
58.5
3
45.4
45.4
50.3
51.0
4
51.6
51.6
51.8
47.4
________________________________________________
4
SAS Code:
options pageno=1;
title 'Analysis of a Split-Block Design';
title2 'Consisting of 4 Blocks, 4 Levels of Oats (Whole Plot Factor)';
title3 'and 4 Levels of Seed Treatment (Sub-Plot Factor)';
data a;
input block oat seed yield @@;
cards;
1 1 1 42.9 1 1 2 53.8 1 1 3 49.5 1 1 4 44.4
2 1 1 41.6 2 1 2 58.5 2 1 3 53.8 2 1 4 41.8
3 1 1 28.9 3 1 2 43.9 3 1 3 40.7 3 1 4 28.3
4 1 1 30.8 4 1 2 46.3 4 1 3 39.4 4 1 4 34.7
1
2
3
4
2
2
2
2
1
1
1
1
53.3
69.6
45.4
35.1
1
2
3
4
2
2
2
2
2
2
2
2
57.6
69.6
42.4
51.9
1
2
3
4
2
2
2
2
3
3
3
3
59.8
65.8
41.4
45.4
1
2
3
4
2
2
2
2
4
4
4
4
64.1
57.4
44.1
51.6
1
2
3
4
3
3
3
3
1
1
1
1
62.3
58.5
44.6
50.3
1
2
3
4
3
3
3
3
2
2
2
2
63.4
50.4
45.0
46.7
1
2
3
4
3
3
3
3
3
3
3
3
64.5
46.1
62.6
50.3
1
2
3
4
3
3
3
3
4
4
4
4
63.6
56.1
52.7
51.8
1 4 1 75.4 1 4 2 70.3 1 4 3 68.8 1 4 4
2 4 1 65.6 2 4 2 67.3 2 4 3 65.3 2 4 4
3 4 1 54.0 3 4 2 57.6 3 4 3 45.6 3 4 4
4 4 1 52.7 4 4 2 58.5 4 4 3 51.0 4 4 4
;
proc print data = a;
title4 'Analysis using Proc GLM';
proc glm data = a;
class block oat seed;
model yield = block oat block*oat seed
71.6
69.4
56.6
47.4
oat*seed;
random block block*oat/test;
lsmeans oat*seed / pdiff adjust=tukey;
run;
title4 'Analysis using Proc Mixed';
proc mixed data = a;
class block oat seed;
model yield = oat seed oat*seed / ddfm = satterth;
random block block*oat;
lsmeans oat seed oat*seed / pdiff;
run;
Consider an agricultural field trial involving "t" varieties of wheat (Factor A) and "s" types of fertilizers
(Factor B). Both seeding and fertilizing are most easily performed in strips. By placing the wheat varieties
in rows and the fertilizers in columns a "strip plot" experimental design is produced. Before inferences
can be made for either of the factors, the design must be replicated (Rep), say n  2 times.
options pagno = 1 linesize = 120;
title "Analysis of a Strip-Plot Experimental Design";
title2 "Four Replicate Plots Consisting of Two Irrigation Levels";
title3 "and Three Nitrogen Levels. The Response is Yield of Wheat";
data wheat;
input Replicate Nitrogen Irrigation Yield @@;
cards;
1 1 1 55
1 1 2 71
2 2 1 70
2 2 2 78
1 3 1 69
1 3 2 78
2 3 1 79
2 3 2 80
1 2 1 62
1 2 2 77
2 1 1 63
2 1 2 77
3 3 2 81
3 3 1 77
4 3 1 76
4 3 2 79
3 1 2 77
3 1 1 63
4 2 1 66
4 2 2 76
3 2 2 79
3 2 1 66
4 1 1 65
4 1 2 75
;
proc sort data = wheat; by replicate nitrogen irrigation;
proc print data = wheat;
run;
title4 "Proc GLM Analysis";
proc glm data = wheat;
class Replicate Nitrogen Irrigation;
model Yield = Replicate Nitrogen Replicate*Nitrogen Irrigation
Replicate*Irrigation Nitrogen*Irrigation;
random Replicate Replicate*Nitrogen Replicate*Irrigation/test;
lsmeans Nitrogen*Irrigation / pdiff;
run;
title4 "Proc Mixed Analysis";
proc mixed data = wheat;
class Replicate Nitrogen Irrigation;
model Yield = Nitrogen Irrigation Nitrogen*Irrigation / ddfm = satterth;
random Replicate Replicate*Nitrogen Replicate*Irrigation;
lsmeans Nitrogen*Irrigation / pdiff;
run;
Download