What if we fit a Poisson model with fractional polynomial or spline to generate the smooth function from predicted values? There is an implementation is Stata https://minerva-access.unimelb.edu.au/items/862e275d-600b-529e-a7e8-4cf7239c1740
Again, you could do that. It is just a different kind of smoother. But I don't think any model will enable you get CIs for the turning points.
I think you might want to discuss the problem with your colleagues or a local statistician. If this is something that you will want to publish or that has clinical implications, you would be wise to think carefully about the scientific validity of the statistical method.
If you decide on a method and program it in SAS, we can help if you run into coding difficulties.
Good luck.
You could use A Time Series Decomposition to get TREND component and using Rick blog's DIFF skill to get those special kinks .
data have;
input y @@;
x+1;
cards;
5447 5412 5215 4697 4344 5426
5173 4857 4658 4470 4268 4116
4675 4845 4512 4174 3799 4847
4550 4208 4165 3763 4056 4058
5008 5140 4755 4301 4144 5380
5260 4885 5202 5044 5685 6106
8180 8309 8359 7820 7623 8569
8209 7696 7522 7244 7231 7195
8174 8033 7525 6890 6304 7655
7577 7322 7026 6833 7095 7022
7848 8109 7556 6568 6151 7453
6941 6757 6437 6221 6346 5880
;
proc iml;
use have;
read all var {y};
close ;
mdel = 0; trade = 0; year = 0;
period= 0; log = 0; maxit = 100;
update = .; /* use default update method */
line = .; /* use default line search method */
sigmax = 0; /* no upper bound for variances */
back = 100;
opt = mdel || trade || year || period || log || maxit ||
update || line || sigmax || back;
call tsdecomp(cmp,coef,aic) data=y order=2 sorder=0 nar=2
npred=5 opt=opt icmp={1 3} print=1;
trend=cmp[,1];
slope = dif(trend);
sgn = sign(slope);
difSgn = dif(sgn);
create trend var{trend difSgn};
append;
close;
quit;
data want;
merge have trend;
if difSgn in (-2 2) then kink=trend;
run;
proc sgplot data=want;
series x=x y=y/lineattrs=(color=blue);
series x=x y=trend/lineattrs=(color=red);
scatter x=x y=kink/markerattrs=(color=green size=20 symbol=starfilled);
run;
Here is another function to get TREND component of time series decomposition.
Try both to see which one is better to fit your data.
data have;
set sashelp.stocks(keep=stock date close rename=(close=y));
if stock='IBM';
run;
proc iml;
use have;
read all var {y};
close ;
call tsbaysea(trend,season,series,adj,abic)
data=y order=2 sorder=1 npred=12 print=2;
slope = dif(trend);
sgn = sign(slope);
difSgn = dif(sgn);
create trend var{trend difSgn};
append;
close;
quit;
data want;
merge have trend;
if difSgn in (-2 2) then kink=trend;
run;
proc sgplot data=want;
series x=date y=y/lineattrs=(color=blue);
series x=date y=trend/lineattrs=(color=red);
scatter x=date y=kink/markerattrs=(color=green size=14 symbol=starfilled);
run;
KSharp: Your two examples show the point I was trying to make: the problem is not well-defined if you define the turning points by using a smoother. As you showed, choosing different smoothers will usually result in a different number and location of the turning points.
Hi KSharp, Thanks for the code. How can i find out the numerical values of those points?
data want;
merge have trend;
if difSgn in (-2 2) then kink=y; /*<---change 'trend' into 'y'--*/
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.