options ls=80 ps=59 nodate;

data
oxygen;
input temp rate;
cards;
-18 5.2
-15 4.7
-10 4.5
-5 3.6
0 3.4
5 3.1
10 2.7
19 1.8
;

proc print;
title 'oxygen consumption data';
run;
proc gplot;
plot rate*temp;
run;

/* Examples 4.2, 4.3, and 4.6. Finding least squares estimates and the ANOVA;
"clb" = Confidence intervals for the parameter estimates */

proc reg;
model rate = temp / clb;
run;

/* Examples 4.4 and 4.5.
Obtaining CI's and PI's for a fixed x_0
"cli" = Prediction intervals for a new observation at each observed X
"clm" = Confidence intervals for the mean at each observed X
'.' means missing value; create this line for the x_0 of interest;
Note: SAS can not give confidence/prediction bands (as far as I can tell)
*/

data proposed;
input temp rate;
lines;
2.5 .
;
run;
data both; set oxygen proposed; /* merging two datasets */
run;
proc reg data=both;
model rate = temp/clm cli;
run;

/* Basic residual plots and analysis
"p" = predicted values for each observation (y-hat)
"r" = Residuals for each observation (also gives the internally
studentised residuals, the r_i's)
*/

proc reg;
model rate = temp/p r;
id temp;
plot r.*p.;
plot rate*temp='X' p.*temp='P' / overlay;
run;

/* 'student=student_residual' gives the internally studentised residuals (i.e., the r_i's)
'rstudent=student_deleted_residual' gives the externally studentised residuals (i.e., the t_i's)
Note: I'll create a new data set, diag, and then print the new data set. */

proc reg;
model rate = temp;
output out=diag p=yhat r=resid student=student_residual rstudent=student_deleted_residual;
run;
proc print data=diag;
title 'fitted values, residuals, and studentised residuals';
run;