BookmarkSubscribeRSS Feed
lamiaH
Obsidian | Level 7

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, 

 

8 REPLIES 8
DanH_sas
SAS Super FREQ

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;

lamiaH
Obsidian | Level 7

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

Rick_SAS
SAS Super FREQ

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."

lamiaH
Obsidian | Level 7

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

lamiaH
Obsidian | Level 7

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

 

Thanks

Rick_SAS
SAS Super FREQ

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.

lamiaH
Obsidian | Level 7

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.

Rick_SAS
SAS Super FREQ

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 2074 views
  • 0 likes
  • 3 in conversation