DATA Step, Macro, Functions and more

Time Series data advice

Reply
Contributor
Posts: 50

Time Series data advice

Hi everyone, I need some guidance as to how I should approach this data.I have count  data that is collected over time in 3 month intervals. Everyone has a baseline session, but the final session varies. Some may have more follow up than others. I would like to show a decrease over time. Any feedback would be greatly apprecaited. Thanks!

 

 

The data is structed like this:

 

IDEventcountSessionDate
161/1/2015
141/31/2015
133/2/2015
124/1/2015
105/1/2015
232/1/2015
213/8/2015
204/12/2015
215/17/2015
206/21/2015
207/26/2015
3123/3/2015
3104/2/2015
395/2/2015
3106/1/2015
3117/1/2015
347/31/2015
328/30/2015
Super User
Posts: 10,460

Re: Time Series data advice

A very simplistic model could be:

proc reg data=have;
   by id;
   model eventcount= sessiondate;
run;
quit;

The parameter estimate for Sessiondate would be the average change per day over the period. The t value and Pr>|t| would indicate whether the change is significant. Though the number of records is kind of small.

 

Contributor
Posts: 50

Re: Time Series data advice

Thanks Ballard, This was very helpful. Here is my output. Can you tell me why it says ChildID=2297? Right under the title? Also, can you confirm that I'm interperting this correctly - The change over time was 4.9 but it was not statistically significiant.

 

 

Capture.PNG

 

SAS Super FREQ
Posts: 8,739

Re: Time Series data advice

If your code had BY CHILDID, then the line you are asking about comes from the BY group processing.
cynthia
Contributor
Posts: 50

Re: Time Series data advice

I understand that but why one specific case?


proc reg data=SymptomDemo2016_2;
by childid;
model PreAdmHisDaytActionID= Session;
run;
quit;
SAS Super FREQ
Posts: 8,739

Re: Time Series data advice

Don't know. I don't know your data. Was the data sorted by CHILDID? Were there error messages in the log? Are you looking at the bottom of the report, in other words, is childid=2297 the last BY group in your data?

cynthia
Contributor
Posts: 50

Re: Time Series data advice

Very strange. it's not the last case in the list. I did get some errors in the log it was:

354 proc reg data=SymptomDemo2016_2;
355 by childid;
356 model PreAdmHisDayActionID= Session;
357 run;

WARNING: There is insufficient variation in the data to create a density plot.
NOTE: The above message was for the following BY group:
ChildID=2022
WARNING: There is insufficient variation in the data to create a density plot.
NOTE: The above message was for the following BY group:
ChildID=2035
WARNING: There is insufficient variation in the data to create a density plot.
NOTE: The above message was for the following BY group:
ChildID=2077
WARNING: There is insufficient variation in the data to create a density plot.
NOTE: The above message was for the following BY group:
ChildID=2181
WARNING: There is insufficient variation in the data to create a density plot.
NOTE: The above message was for the following BY group:
ChildID=2258
NOTE: Interactivity disabled with BY processing.
NOTE: PROCEDURE REG used (Total process time):
real time 9:10.63
cpu time 1:01.58


358 quit;
Super User
Posts: 10,460

Re: Time Series data advice

The example I provided assumed you wanted a report per ID as that seemed to make sense from the data. Your messages about insufficient variation indicates that some of your child id values have very little data. Also, dates as absolute values can sometimes lead to odd things in regression such as the intercept values. SOMETIMES instead of the date you might want to provide a "days since first measurement" to use.

 

If you want to have an overall behavior, ignoring the specific children then the days interval would be a better way to go.

data start;
 informat ID Eventcount best4. sessiondate mmddyy10.;
 input ID Eventcount SessionDate ;
datalines;
1 6 1/1/2015 
1 4 1/31/2015 
1 3 3/2/2015 
1 2 4/1/2015 
1 0 5/1/2015 
2 3 2/1/2015 
2 1 3/8/2015 
2 0 4/12/2015 
2 1 5/17/2015 
2 0 6/21/2015 
2 0 7/26/2015 
3 12 3/3/2015 
3 10 4/2/2015 
3 9 5/2/2015 
3 10 6/1/2015 
3 11 7/1/2015 
3 4 7/31/2015 
3 2 8/30/2015 
;
run;

proc sort data= start;
   by id Sessiondate;
run;

data want;
   set start;
   by id;
   retain FirstDate;
   if first.id then FirstDate=SessionDate;
   DaysInStudy = SessionDate-Firstdate;
   drop firstdate;
run;


proc reg data=want;
   model eventcount= DaysInStudy;
run;
quit;

The parameter estimate for DaysInStudy still refers to average change per day but now is scaled so that each person starts at day 0.

 

Contributor
Posts: 50

Re: Time Series data advice

Hi Ballard,

 

Thanks for the explination. I took a slightly different approach. The program I am evaluating should have a baseline session then subsequent follow ups that occur in 3 month intervals. The majority of cases are resolved in a year. Some however span a longer time (2 years). What i'd like to see is if change occurs from the baseline session to the final session (completion of the program) and each session inbetween. 

 

Here is what I did, I turned each date into the session variable: 

proc sort data = start; by  ID Date; run; 

data start2;
set start;
by ID Date;
retain Session;
if first.ID then Session=1;
else if first.Date then Session+1;
run;

I then modeled the event count by the session:

 

proc reg data=Start2;
   model EventCount = Session;
run;
quit;

Here are my results:

 

Capture.PNG

So are we saying from Baseline to the last session we found a 3.59 decrease that is statistically significant? 

 

Thanks!

 

 

 

Respected Advisor
Posts: 4,640

Re: Time Series data advice

[ Edited ]

I would start with this:

 

data test;
input ID	Eventcount	SessionDate :mmddyy10.;
datalines;
1	6	1/1/2015
1	4	1/31/2015
1	3	3/2/2015
1	2	4/1/2015
1	0	5/1/2015
2	3	2/1/2015
2	1	3/8/2015
2	0	4/12/2015
2	1	5/17/2015
2	0	6/21/2015
2	0	7/26/2015
3	12	3/3/2015
3	10	4/2/2015
3	9	5/2/2015
3	10	6/1/2015
3	11	7/1/2015
3	4	7/31/2015
3	2	8/30/2015
;

proc sql;
create table test0 as
select 
    *, 
    intck("DAY", min(SessionDate), SessionDate) as SessionTime
from test
group by id;
quit;

proc glimmix data=test0;
class id;
model EventCount = SessionTime / dist=Poisson solution;
random intercept / subject=id;
estimate 'decrease' SessionTime 1 / lower ilink;
run;
PG
Ask a Question
Discussion stats
  • 9 replies
  • 276 views
  • 0 likes
  • 4 in conversation