/* Program to accompany the article "Nonparametric regression for binary response data in SAS" published 23Mar2016, The DO Loop, http://blogs.sas.com/content/iml/2016/03/23/nonparametric-regression-binary-response-sas.html The data are described and obtained from Robert Allison's article "How to graph NBA data with SAS" published 14MAR2016, SAS Learning Post, http://blogs.sas.com/content/sastraining/2016/03/14/how-to-graph-nba-data-with-sas/ */ libname nba "C:\Users\frwick\Documents\My SAS Files\Blog"; proc format; value ShotFmt 1='Made' 0='Missed'; run; data Curry; set nba.Nba_Stephen_Curry(rename=(Shot_Made_Flag = Shot_Made)); keep Shot_Made X Y Shot_Distance Angle Loc_X Loc_Y Seconds_Remaining; X = Loc_x / 10; Y = Loc_Y / 10; /* (LOC_X, LOC_Y) in 1/10 feet */ Angle = atan2(Y, X) * 180 / constant("pi"); if y<0 && x<0 then Angle=Angle+360; label Shot_Made = "Shot Made" Angle = "Angle (degrees)" Shot_Distance = "Distance (feet)"; format Shot_Made ShotFmt.; run; /*****************************/ /* first nonparametric model */ *ods select SmoothingEstimates; proc gampl data=Curry; where Shot_Distance <= 30; model Shot_Made(event='Made') = Spline(X Y / maxdf=40) / dist=binary; id X Y Shot_Made; output out=GamPLOut; run; %let off0 = offsetmin=0 offsetmax=0 linearopts=(thresholdmin=0 thresholdmax=0); proc template; define statgraph ContourScatterPlot; dynamic _X _Y _Z _TITLE _group; begingraph / subpixel=on; entrytitle _TITLE; layout overlay / xaxisopts=(&off0) yaxisopts=(&off0); contourplotparm x=_X y=_Y z=_Z / gridded=false nhint=12 name="Contour"; continuouslegend "Contour" / title=_Z; endlayout; endgraph; end; run; ods graphics / width=500px height=400px; proc sgrender data=GamPLOut template=ContourScatterPlot; dynamic _TITLE="GAM Fit of Logistic Regression Model" _X="X" _Y="Y" _Z="Pred"; run; /* second nonparametric model */ proc adaptivereg data=Curry plots; where Shot_Distance <= 30; model Shot_Made(event='Made') = X Y / dist=binary; output out=AdaptiveOut p(ilink); run; proc sgrender data=AdaptiveOut template=ContourScatterPlot; dynamic _TITLE="AdaptiveReg Fit of Logistic Regression Model" _X="X" _Y="Y" _Z="Pred"; run;