BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mmazariegos
Fluorite | Level 6

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;

 Presentación1.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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."

View solution in original post

4 REPLIES 4
WarrenKuhfeld
Rhodochrosite | Level 12

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.

Rick_SAS
SAS Super FREQ

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."

mmazariegos
Fluorite | Level 6

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;

 

Rick_SAS
SAS Super FREQ

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 ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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