* Orange Example -- source code file orange.txt; options linesize=70 nodate; * Create original orange dataset; data orange; infile 'c:/datasets/orange.txt' firstobs=4; input variety pesticide yield; * Print orange dataset; proc print data=orange; * Obtain means of each of the 12 cells; proc means data=orange noprint mean; var yield; by variety pesticide; output out=out mean=yield std=std; * Print means in out dataset; proc print data=out; * Set plotting symbols and colors for gplot; goptions reset=all; symbol1 v=dot c=blue i=join; symbol2 v=star c=red i=join; symbol3 v=square c=green i=join; symbol4 v=plus c=black i=join; * Create interaction plots; proc gplot data=out; plot yield * pesticide = variety; title 'Plot A: Interaction Plot'; proc gplot data=out; plot yield * variety = pesticide; title 'Plot B: Interaction Plot'; * Additive ANOVA model; proc anova data=orange; class pesticide variety; model yield = pesticide variety; * ANOVA model with interaction term; proc anova data=orange; class pesticide variety; model yield = pesticide variety pesticide*variety; * Additive ANOVA model. proc glm can compute * residuals and predicted values; proc glm data=orange; class pesticide variety; model yield = pesticide variety; output out=additive p=pred r=resid; * ANOVA model with interaction term, using proc glm; proc glm data=orange; class pesticide variety; model yield = pesticide variety pesticide*variety; output out=interact p=pred r=resid; * Don't connect points for residual plots; goptions reset=all; symbol1 v=dot c=blue; symbol2 v=star c=red; symbol3 v=square c=green; symbol4 v=plus c=black; proc gplot data=additive; plot resid*pred / vref=0; title 'Plot C: Residual Plot for Additive Model'; proc gplot data=additive; plot resid*pesticide / vref=0; by variety; title 'Plot D: Residual Plots by Variety for Additive Model'; proc gplot data=interact; plot resid*pred / vref=0; title 'Plot E: Residual Plot for Model with Interaction'; proc gplot data=additive; plot resid*pesticide / vref=0; by variety; title 'Plot F: Residual Plots by Variety for Model with Interaction'; data regress; set orange; dummy_vari_1 = (variety = 1); dummy_vari_2 = (variety = 2); dummy_pest_1 = (pesticide = 1); dummy_pest_2 = (pesticide = 2); dummy_pest_3 = (pesticide = 3); interact_11 = dummy_vari_1 * dummy_pest_1; interact_12 = dummy_vari_1 * dummy_pest_2; interact_13 = dummy_vari_1 * dummy_pest_3; interact_21 = dummy_vari_2 * dummy_pest_1; interact_22 = dummy_vari_2 * dummy_pest_2; interact_23 = dummy_vari_2 * dummy_pest_3; drop variety pesticide; proc print data=regress; * Additive model; proc reg data=regress; model yield = dummy_vari_1 dummy_vari_2 dummy_pest_1 dummy_pest_2 dummy_pest_3 / p r; * Model with interaction; proc reg data=regress; model yield = dummy_vari_1 dummy_vari_2 dummy_pest_1 dummy_pest_2 dummy_pest_3 interact_11 interact_12 interact_13 interact_21 interact_22 interact_23 / p r; run; quit;