Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Cubic Spline

Options

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-27-2018 01:23 PM
(480 views)

Hi All,

So I have data as follows:

Time = X

Result = Y

Time (Months) Result

0 7.17

3 5.98

6 7.31

12 73.87

18 80.92

30 39.11

36 37.93

42 33.3

48 35.2

78 33.26

I need to fit a cubic spline to the data, and then find Y-values for 8 equal time points between 19.2 and 44.4 months. And then do a regression on those 8 data points to find a slope.

I have been playing around with proc glmselect, and I get 5 knots and their parameters...but I can't seem to apply the equation correctly after the first knot, I am not sure how to get SAS to show me the other parts of the predictive equation (i.e. the second intercept)

This is how far I got:

ods select ANOVA ParameterEstimates SplineKnots TPFSplineDeatils;

ods output ParameterEstimates=param SplineKnots=spline ;

proc glmselect data=patient1;

effect spl = spline( time/ details naturalcubic basis=tpf(noint)

knotmethod=percentiles(5) );

model result = spl / selection=none ; /* fit model by using spline effects */

output out=SplineOut predicted=fit ; /* output predicted values for graphing */

quit;

1 REPLY 1

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I am confused by several things you said, but it sounds like you want to score the fitted model at 8 evenly-spaced points between 19.2 and 44.4. You can use the SCORE statement or use the STORE statement and PROC PLM, as follows:

```
data Patient1;
input Time Result;
datalines;
0 7.17
3 5.98
6 7.31
12 73.87
18 80.92
30 39.11
36 37.93
42 33.3
48 35.2
78 33.26
;
ods select ANOVA ParameterEstimates SplineKnots TPFSplineDetails;
ods output ParameterEstimates=param SplineKnots=spline ;
proc glmselect data=patient1;
effect spl = spline( time/ details naturalcubic basis=tpf(noint)
knotmethod=percentiles(5) );
model result = spl / selection=none ; /* fit model by using spline effects */
output out=SplineOut predicted=fit ; /* output predicted values for graphing */
store out=MyModel;
quit;
data ScoreData;
startT = 19.2;
endT = 44.4;
N = 8;
dt = (endT - startT) / (N-1);
do Time = startT to endT by dt;
output;
end;
keep Time;
run;
proc plm restore=MyModel;
score data=ScoreData out=ScoreResults;
run;
proc sgplot data=ScoreResults;
series x=Time y=Predicted; /* do you want the fitted curve? */
run;
proc sgplot data=ScoreResults;
reg x=Time y=Predicted; /* you said something about a slope? */
run;
```

What is unclear is the sentence " do a regression on those 8 data points to find a slope." Perhaps the hint above will provide the points that you need for the regression? You can use PROC REG to get the regression estimates, including the slope. If that's not what you want, then please explain further.

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.