********************
* heifers.sas ******
********************;
* Note that the data are slightly different than in the original version of this
example.;
options nodate pageno=1 ;
ods graphics off;
ods listing gpath="c:\temp";
ods pdf file="U:\Documents\courses\sta820\Fall13\heifers.pdf";
data heifers;
input farm week heifer feed $ consumpt;
cards;
1 1 1 a 2.7
1 1 2 c 2.6
2 1 3 b 1.9
1 2 1 c 2.1
1 2 2 b 0.2
2 2 3 a 2.3
1 3 1 b 1.9
1 3 2 a 2.1
2 3 3 c 2.4
2 1 1 a 3.3
2 1 2 c 2.3
1 1 3 b 0.1
2 2 1 b 1.7
2 2 2 a 2.8
1 2 3 c 1.8
2 3 1 c 2.1
2 3 2 b 1.7
1 3 3 a 2.7
;
run;
title 'Model 1: feed, week, heifer(farm) and farm effects';
proc mixed data=heifers method=type3 ;
class farm week heifer feed;
model consumpt=feed;
random week heifer(farm) farm;
lsmeans feed/cl;
run;
/*
Tests on the treatment factor (main effect test, tests of contrasts) are
the same if we collapse the columns (heifers) and squares (farms) rows of the anova table into a single
source of variability due to heifer to heifer differences across the
6 distinct heifers in the experiment.
This collapsing would be appropriate if there isn't any identifiable distinction
from square to square; that is, if the 6 heifers in this experiment were essentially homogeneous
rather than being from two different farms, or being different breeds, etc.
Whether the heifers variability is decomposed into farm and heifers(farm) variability does
not affect the basic analysis (tests of main effects and contrasts),
but it can affect the computation of standard errors and confidence
intervals for treatment means in the mixed effect model, so whether this decomposition is
done should be based on the design. If the squares really do correspond to different levels of an
identified nuisance variable that was blocked (by square) in the design, then the decomposition
(as in the previous call to PROC MIXED) should be used; if not, then the following analysis is more appropriate.
*/
* renumber the heifers from 1 to 6 rather than 1 to 3 in each square: ;
data heif2;
set heifers;
if farm=2 then heifer=heifer+3;
run;
title 'Model 2: feed, week, and heifer effects';
title2 'Notice this model is equivalent to model 1 except that';
title3 "it doesn't decompose heifer and farm effects separately";
proc mixed data=heif2 method=type3;
class week heifer feed;
model consumpt=feed;
random week heifer;
lsmeans feed/cl; * Note the SEs and confidence intervals are slightly different than in the previous model;
run;
* Note that in this program we treated the efects of all blocking factors as random.
I think that is the appropriate assumption here. The analysis is unchanged
except for SEs and confidence intervals on treatment means and other
non-contrast linear combinations of the treatment means if we treat the
block effects as fixed and fit the model in PROC GLM;
ods pdf close;