BookmarkSubscribeRSS Feed
darb
Calcite | Level 5

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
Rick_SAS
SAS Super FREQ

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 566 views
  • 0 likes
  • 2 in conversation