/* SAS example for Weighted Least Squares */ /* We use the blood pressure data in Table 11.1 of the book */ data bloodp; input age dbp; cards; 27 73 21 66 22 63 24 75 25 71 23 70 20 65 20 70 29 79 24 72 25 68 28 67 26 79 38 91 32 76 33 69 31 66 34 73 37 78 38 87 33 76 35 79 30 73 31 80 37 68 39 75 46 89 49 101 40 70 42 72 43 80 46 83 43 75 44 71 46 80 47 96 45 92 49 80 48 70 40 90 42 85 55 76 54 71 57 99 52 86 53 79 56 92 52 85 50 71 59 90 50 91 52 100 58 80 57 109 ; run; /* Regressing the response, dbp, against the predictor, age */ /* The plots show some definite nonconstant error variance */ PROC REG data=bloodp; MODEL dbp = age; OUTPUT out=temp r=residual; PLOT dbp*age r.*age; run; /* Plot of absolute residuals against age shows that */ /* absolute residuals may increase linearly with age. */ data temp; set temp; absr = abs(residual); run; symbol1 v=star h=.8; axis1 order=(0 to 20 by 5); PROC GPLOT data = temp; PLOT absr*age/ vaxis = axis1; run; /* Regressing the absolute residuals against the predictor, age */ /* This second regression is done on the data set temp */ PROC REG data = temp; MODEL absr = age; OUTPUT out = temp1 p = s_hat ; run; /* Defining the weights using the fitted values from this second regression: */ data temp1; set temp1; w = 1/(s_hat**2); run; /* Using the WEIGHT option in PROC REG to get the WLS estimates: */ /* This last regression is done on the data set temp1 */ PROC REG data = temp1; WEIGHT w; MODEL dbp = age / clb; OUTPUT out=temp2 r=residual; PLOT dbp*age r.*age; run;