/* analysis of genotype and fertilzation split plot study */
/* uses simulated data */
/* shows one way to simulate data in SAS */
/* creating data with same means as SplitPlot.r */
data split;
do block = 1 to 4;
b = 6*normal(0);
/* random effect for each block, shared by all obs in that block */
/* constant is seed for random number generator */
do genotype = 'A','B','C';
gb = 7*normal(0);
/* random effect for each main plot, shared by all obs in main plot */
g = 125 + 15*(genotype='B') - 10*(genotype='C');
/* genotype means are 125, 140, and 115 */
do fert = 0 to 150 by 50;
beta1 = 0.4 + 0.2*(gentype='C');
beta2 = -0.0015;
y = g + beta1*fert + beta2*fert**2 + b + gb + 6*normal(0);
output;
/* output writes an observation to the data set */
end;
end;
end;
proc mixed method=type3; /* for type 3 ANOVA, use =type1 for sequential ANOVA */
class block genotype fert;
model y = genotype fert genotype*fert / ddfm = satterth;
/* ddfm specifies how to compute denominator degrees of freedom */
/* only fixed effects go in the model statement */
random block block*genotype;
/* specifies random effects. */
/* DO NOT put the same term in both model and random stmt's. */
/* Doing so will cause all sorts of trouble, because you're specifying a
/* model that doesn't make sense. */
lsmeans genotype fert genotype*fert / diff;
/* /diff gives all pairwise differences and tests */
/* that's one way to get simple effects */
ods output diffs=meandiff;
/* save the table of lsmean differences in a new sas data set */
/* You'll see why in a little bit */
/* if you want the data set but suppress printing the table, add:
ods html exclude diffs; */
estimate 'Genotype A - B' genotype 1 -1 0;
/* main effect of A - B */
contrast 'Fertilization, linear polynomial' fert -3 -1 1 3;
estimate 'Genotype A-B when fert=0' genotype 1 -1 0 genotype*fert 1 0 0 0 -1 0 0 0 0 0 0 0 ;
/* simple effect includes coeff for genotype and their interaction */
/* order of genotype*fert groups depends on order of genotype and fert in the class stmt */
/* to check: look at the order in which lsmeans are printed */
/* if you get it wrong (e.g. 1 -1 0 0 ..), the contrast is non-estimable */
run;
proc print data=meandiff;
where (fert=0) and (_fert=0);
/* only print out differences when both levels of fertilizer are 0 */
run;