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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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