/* Example using body fat data from Chapter 7 */ data body; input triceps thigh midarm bodyfat; y=bodyfat; x1=triceps; x2=thigh; x3=midarm; cards; 19.5 43.1 29.1 11.9 24.7 49.8 28.2 22.8 30.7 51.9 37.0 18.7 29.8 54.3 31.1 20.1 19.1 42.2 30.9 12.9 25.6 53.9 23.7 21.7 31.4 58.5 27.6 27.1 27.9 52.1 30.6 25.4 22.1 49.9 23.2 21.3 25.5 53.5 24.8 19.3 31.1 56.6 30.0 25.4 30.4 56.7 28.3 27.2 18.7 46.5 23.0 11.7 19.7 44.2 28.6 17.8 14.6 42.7 21.3 12.8 29.5 54.4 30.1 23.9 27.7 55.3 25.7 22.6 30.2 58.6 24.6 25.4 22.7 48.2 27.1 14.8 25.2 51.0 27.5 21.1 ; run; /* Ridge regression */ /* Creating Figure 11.3 on page 435 */ proc sql; create table ch7tab1a as select *, ( y - mean(y) )/( std(y)*( sqrt( count(y)-1 ) ) ) as ty, ( x1 - mean(x1) )/( std(x1)*( sqrt( count(x1)-1 ) ) ) as tx1, ( x2 - mean(x2) )/( std(x2)*( sqrt( count(x2)-1 ) ) ) as tx2, ( x3 - mean(x3) )/( std(x3)*( sqrt( count(x3)-1 ) ) ) as tx3 from body; quit; symbol1 v=dot h=.8; proc reg data = ch7tab1a outest = temp outstb noprint; model y = x1-x3/ ridge = (0.001 to 0.1 by .001) outvif ; plot / ridgeplot vref=0; run; quit; proc reg data = ch7tab1a outest = temp outstb noprint; model y = x1-x3 / ridge = 0.02; run; quit; proc print data = temp; where _ridge_ = 0.02 and y = -1; var y intercept x1 x2 x3; run; proc reg data = ch7tab1a outest = temp outstb outvif; model y = x1-x3/ridge = (0.0 to 0.01 by 0.002 0.02 to 0.05 by 0.01 0.5 1.0); run;quit; proc print data = temp; where _type_ = 'RIDGESTB'; var _ridge_ x1 x2 x3; run; proc print data = temp; where _type_ = 'RIDGEVIF'; var _ridge_ x1 x2 x3; run; proc print data = temp; where _type_ = 'RIDGEVIF'; var _ridge_ x1 x2 x3; run; /* LASSO regression: */ PROC GLMSELECT DATA=body plot=coefficients; MODEL bodyfat = triceps thigh midarm / SELECTION = lasso; run;