turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Generalized least squares regression and fitted cu...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago - last edited 2 weeks ago

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

2 weeks ago

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago - last edited 2 weeks ago

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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

2 weeks ago

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago - last edited 2 weeks ago

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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 ;