options ls=65 ps=54;              /* linesize=65 characters pagesize=54 lines */
title 'Breaking Strength Data from Table 4-8 pg. 150';

* Read data into SAS from an external file;
filename raw '~/Montgomery/Data/tble4-8.dat';
data raw;
  infile raw;
  input strength diameter machine; 
run;

* Print the data;
proc print data=raw;         
run;

* Mplot (multiple plot) of the data;
proc plot data=raw;
  plot strength*diameter=machine;
run;

* Stage I and Stage II Analysis of Covariance;
proc glm data=raw;
  class machine;
  model strength = machine diameter / p;
  lsmeans machine / stderr tdiff pdiff;
  output out=temp p=fit r=resid student=stdresid;
run;

* Validation of Assumptions;

* Covariate free of TRMT?;     
proc glm data=raw;
  class machine;
  model diameter = machine;
run;

* Residual plots and Normal Probability plot;
proc rank data=temp out=checkass normal=vw;
  var resid;
  ranks expected;
run;

proc plot data=checkass vpct=50 hpct=50;
  plot stdresid*fit = '*' / vref=-2 2 vrefchar='-' box;
  plot stdresid*diameter = '*' / vref=-2 2 vrefchar='-' box;
  plot stdresid*machine = '*' / vref=-2 2 vrefchar='-' box;
  plot expected*resid = '*' / box;
run;

* 1-Way ANOVA with no covariate;
* Wrong Analysis;
proc glm data=raw;
  class machine;
  model strength = machine;
run;