Data visualization with SAS programming

a plot for intervention analysis interrupted time series proc autoreg

Reply
Contributor
Posts: 20

a plot for intervention analysis interrupted time series proc autoreg

Hi,

 

I'm using proc autoreg to find the effect of 3 interventions. I don't know how to produce the data with the estimated change pints (estimated time point at which the intervention began to affect the outcome). 

I'm using the following code:

proc sgplot data=a noautolegend;

series x=x y=y /markers;

reg x=x y=y/lineaattrs=(color=black);

xaxis grid values=('1jan1998'd to'1FEB2016'd )

refline 'date'd/transparency=0.5

refline 'date'd/transparency=0.5

refline 'date'd/transparency=0.5;

run;

 

so how can I show the estimated change point?? following each intervention I tried to put group after reg but it didn't work?

 

Thank you so much, 

 

SAS Super FREQ
Posts: 925

Re: a plot for intervention analysis interrupted time series proc autoreg

Assuming the REFLINEs show the change points, and the data for those points is in the DATE variable, you can do this:

 

proc sgplot data=a noautolegend;

series x=x y=y /markers;

reg x=x y=y/lineaattrs=(color=black);

xaxis grid values=('1jan1998'd to'1FEB2016'd );

refline date / transparency=0.5;

run;

Contributor
Posts: 20

Re: a plot for intervention analysis interrupted time series proc autoreg

Hello ,

 

thank you then the code will be enough, What if I want to show the trend change after each intervention point. I know I should do reg but didn't know how to do for each intervention differently !!

 

Thank you

Highlighted
SAS Super FREQ
Posts: 3,618

Re: a plot for intervention analysis interrupted time series proc autoreg

I don't fully understand your question, but if you want separate regression for three disjoint intervals, just add a GROUP variable to the data that identifies the observations that lie within each of the three regions.  Then you can use

REG x=x y=y / group=GROUP;

 

You can also use knots and spline effects to model change points. You put the knot location at the change point, as shown in the article "Nonsmooth models and spline effects."

Contributor
Posts: 20

Re: a plot for intervention analysis interrupted time series proc autoreg

Thank you for your reply and my apology for my late reply. Yes, I want to show the observed and predicted line after each intervention or change in time point. 

I will try the group, however, I have more than one group, I have 3 interventions, so I need the observed and predicted after each refline to be shown, so not sure how to make that ! 

 

Thank you, 

Lamia

Contributor
Posts: 20

Re: a plot for intervention analysis interrupted time series proc autoreg

[ Edited ]

I've attached a similar plot so you can understand what I mean.

 

Thanks

SAS Super FREQ
Posts: 3,618

Re: a plot for intervention analysis interrupted time series proc autoreg

The plot did not show up. Please try again to attach it. Sample data would also be useful.

 

If you are interested in change-point detection in time series, I can recommend a 2017 paper by Daymond Ling that discusses these issues.

Contributor
Posts: 20

Re: a plot for intervention analysis interrupted time series proc autoreg

Hello, 

I've attached a word document, I hope this time it will show, if not will do it again from home, maybe the computer server is private and don't allow sharing. 

My data looks as the following

                                                                                                                                                                                                       outcome

date (month-year)/   time  / intervention 1( coded as 0 and 1)/ intervention 2(coded the same)/ intervention 3 (coded the same/  rate 

                                                                                                     at different time point                but at different time point)           5.6

jan1998                  1            0                                                           0                                                                                                4.3

.                               .            0                                                           0                                                                                                    .

                                .            1                                                           0                                                                                                  .

.                                            1                                                           0                                                                                                   .

Jan2016                  214                                                                    1

                                                                                                          1

 

I hope this clear if not will attach a document of how the data looks like. I can't upload the original data because of privacy.

SAS Super FREQ
Posts: 3,618

Re: a plot for intervention analysis interrupted time series proc autoreg

It is not clear what problem you are having. Is it that you don't know how to use a regression procedure to come up with the predicted values? Is it the reference lines? Is it overlaying the observations and the predicted values?

 

Here are two approaches. The first uses only the REG statement in PROC SGPLOT. This performs OLS regression. The second uses PROC GLM to output predicted values for each group. The predicted values are then overlaid on the data. You can substitute another regression procedure for GLM.

 

data a;
call streaminit(1);
group = 1;
do t = 0 to 52;
   y = 90 + 5/52*t + rand("normal");
   output;
end;
group = 2;
do t = 53 to 156;
   y = 90 - 5/52*(t-53) + rand("normal");
   output;
end;
group = 3;
do t = 157 to 190;
   y = 20 + 25/52*(t-157) + rand("normal");
   output;
end;
run;

proc sgplot data=A;
reg x=t y=y / group=group;
refline 52 156 / axis=x;
run;


proc glm data=A plots=none;
by group;
model y = t;
output out=modelOut predicted=pred;
quit;

proc sgplot data=modelOut;
scatter x=t y=y / group=group;
series x=t y=pred / group=group break lineattrs=(thickness=2);
refline 52 156 / axis=x;
run;

If this does not answer your question, please provide the SAS code that you are using and describe how you want to modify the output.

Ask a Question
Discussion stats
  • 8 replies
  • 169 views
  • 0 likes
  • 3 in conversation