/* In this data set (taken from Spurrier */ /* (1993, Technometrics)), the response */ /* is the diameter of a cornmeal product */ /* and the predictor is the percent of */ /* sucrose in the product. */ DATA corn; INPUT sucrpct diameter; cards; 0 79 2 65 4 64 6 70 8 78 ; run; /* Checking the shape of the regression relationship */ symbol1 v=circle l=32 c = black; PROC GPLOT DATA=corn; PLOT diameter*sucrpct; RUN; /* A polynomial regression should be used here. */ /* Specifically, we will use a quadratic regression model. */ /* We will center the X variable: */ /* We also create a "quadratic-term" variable" */ PROC MEANS DATA = corn; VAR sucrpct; OUTPUT OUT = sucrstats MEAN(sucrpct) = meansucrpct; run; DATA corn2; IF _N_=1 THEN SET sucrstats; SET corn; csucrpct = sucrpct - meansucrpct; csucrpctsq = csucrpct**2; run; /* Looking at the new data set "corn2" */ PROC PRINT DATA = corn2; run; /* Now we perform the quadratic regression: */ PROC REG DATA = corn2; MODEL diameter = csucrpct csucrpctsq; OUTPUT OUT=NEW P=PRED; RUN; /* PROC GPLOT gives a naive plot of the points with the */ /* connected estimated regression curve overlain on it. */ /* See the R example for a nicer plot. */ /* A nicer plot can be done in SAS, see below for details. */ symbol1 v=circle l=32 c = black; symbol2 i = join v=star l=32 c = black; PROC GPLOT DATA=NEW; PLOT diameter*sucrpct PRED*sucrpct/ OVERLAY; RUN; * Plotting the fitted curve (this plotting approach only works with linear, quadratic, or cubic); title 'Quadratic Regression Plot'; proc sgplot data=corn2; reg y=diameter x=csucrpct / degree=2; run; title;