Solved
New Contributor
Posts: 4

Generalized least squares regression and fitted cubic splines

[ Edited ]

Hi all,

To assess the dose-response relation and evaluate the shape of the lactation per child and weight change relation I am using generalized least squares regression and fitted cubic splines with knots at the 5th, 35th, 50th, 65th, and 95th percentile of lactation per child distribution (corresponding to 2, 3, 5, 7, and 10 months). I am adjusting for age, weight at 18 years, educational level, socioeconomic status, age at menarche, age at first pregnancy, average gestational weight change, dietary pattern, physical activity and smoking status. Below the code that I am using, the issue is that I am supposed to get a graph like the one at the left side and I am getting the one that it is on your right side. Do you have any idea what it is happening?

Thank you in advance,

Monica

``````ods select ANOVA ParameterEstimates SplineKnots;
proc glmselect data=merged0811dersesdiet;
effect spl = spline(lactationbypar / details naturalcubic basis=tpf(noint)
knotmethod=percentiles(5) );
model weightchange2 = spl age ep28e1c1 ep12 ep14 educatlevelm_2 educatlevelm_3 educatlevelm_9 SESM_1 SESM_2 SESM_9 gwgaverage factor1 factor2 factor3 totmet08 smkm_2 smkm_3 smkm_9/ selection=none;         /* fit model by using spline effects */
output out=SplineOut predicted=Fit; /* output predicted values for graphing */
quit;

title "Restricted Cubic Spline Regression";
proc sgplot data=SplineOut noautolegend;
series x=lactationbypar y=Fit  / lineattrs=(thickness=3 color=red);
run;``````

Accepted Solutions
Solution
‎08-03-2017 08:49 PM
SAS Super FREQ
Posts: 3,752

Re: Generalized least squares regression and fitted cubic splines

[ Edited ]
Posted in reply to mmazariegos

First, you should always sort the data by the X variable before you create the SERIES plot.

``````proc sort data=SplineOut;
by lactationbypar;
run;

proc sgplot data=SplineOut noautolegend;
series x=lactationbypar y=Fit / lineattrs=(thickness=3 color=red);
run;``````

However, even that won't "fix" the problem because you have other covariates in the model.  What you want to do is use the EFFECTPLOT statement to create the graph. It enables you to see the fit at specified values of the other covariates. Examples and links to the documentation are available in the article "Use the EFFECTPLOT statement to visualize regression models in SAS."

For those readers who aren't sure what the OP is doing with the EFFECT statement and the cubic splines, see "Regression with restricted cubic splines in SAS."

All Replies
SAS Super FREQ
Posts: 291

Re: Generalized least squares regression and fitted cubic splines

Posted in reply to mmazariegos

Sort the data first by X.  Or I think there is some option on the series plot, a sort by or connect by or some such thing.

Solution
‎08-03-2017 08:49 PM
SAS Super FREQ
Posts: 3,752

Re: Generalized least squares regression and fitted cubic splines

[ Edited ]
Posted in reply to mmazariegos

First, you should always sort the data by the X variable before you create the SERIES plot.

``````proc sort data=SplineOut;
by lactationbypar;
run;

proc sgplot data=SplineOut noautolegend;
series x=lactationbypar y=Fit / lineattrs=(thickness=3 color=red);
run;``````

However, even that won't "fix" the problem because you have other covariates in the model.  What you want to do is use the EFFECTPLOT statement to create the graph. It enables you to see the fit at specified values of the other covariates. Examples and links to the documentation are available in the article "Use the EFFECTPLOT statement to visualize regression models in SAS."

For those readers who aren't sure what the OP is doing with the EFFECT statement and the cubic splines, see "Regression with restricted cubic splines in SAS."

New Contributor
Posts: 4

Re: Generalized least squares regression and fitted cubic splines

Thank you! The last question, using this code can I add confidence intervals?

``````proc sort data=SplineOut;
by lactationbypar;
run;

proc sgplot data=SplineOut noautolegend;
series x=lactationbypar y=Fit / lineattrs=(thickness=3 color=red);
run;``````

SAS Super FREQ
Posts: 3,752

Re: Generalized least squares regression and fitted cubic splines

Posted in reply to mmazariegos

The OUTPUT statement in regression procedures usually supports a way to output the lower- and upper-limits for predicted means (and sometimes for individual predictions). Let's say you write the lower and upper values to the variables LCL and UCL. Then you can use the BAND statement in PROC SGPLOT like this:

band x=lactationbypar lower=LCL upper=UCL ;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 4 replies
• 251 views
• 3 likes
• 3 in conversation