# Using mixed models to treat time series data in R

I have a 4 year long daily time series for the gross margin (GROSS_MARGIN) of six different production plants (PLANTS, factor). For one of these plants, a treatment was applied at some point in time (so it has a before/after set of observations, TREATMENT). This plant was marked as case, the others as control (factor, CASE_CONTROL). The dates were decomposed in fiscal years (FY, factor) and months (MONTH, factor)

So, I came up with a model like this (I´m using R/lme4):

GROSS_MARGIN ~ TREATMENT + (CASE_CONTROL|FY) + (CASE_CONTROL|MONTH)


The idea is to generate a hierarchy of models able to isolate the effects of changes associated to fiscal year (e. g. long term market effects) and seasonality (monthly basis), which are uncontrollable from the effects of the treatment.

Here´s a data sample:

PLANT   GROSS_MARGIN    FY  DATE    MONTH   CASE_CONTROL    TREATMENT
B   191.5964372 1516    2016-04-19  Apr 0   0
U   216.8121963 1617    2017-04-03  Apr 1   0
U   166.4315772 1617    2016-07-21  Jul 1   0
U   135.5415243 1415    2015-02-24  Feb 1   0
U   58.11040508 1718    2017-08-28  Aug 1   1
U   101.5804414 1516    2015-08-18  Aug 1   0
P   177.0904659 1415    2014-11-21  Nov 0   0
U   75.4058245  1415    2015-05-28  May 1   0
P   100.4976949 1718    2017-07-19  Jul 0   0
U   201.7031536 1415    2014-10-08  Oct 1   0
P   286.5572358 1415    2015-04-06  Apr 0   0
B   300.6485076 1415    2014-08-18  Aug 0   0
P   167.4768055 1617    2016-11-29  Nov 0   0
R   91.08332248 1516    2015-09-15  Sep 0   0
U   372.4720477 1617    2017-02-21  Feb 1   0
P   166.4502071 1516    2016-02-12  Feb 0   0
R   233.8138379 1415    2015-04-24  Apr 0   0
U   53.47271932 1617    2017-05-08  May 1   0
P   144.6495899 1415    2015-03-03  Mar 0   0


Is this the adequate approach to this kind of data?

• This is probably not an adequate representation of the structure of the information in the data. For instance, having separate main effects for FY, month and day of the week would be more useful than testing for any interactions with case_control. Next, are there mean differences in gross margin between plants? If so, then a natural log transformation would help create a more level playing field. There's no shortage of literature out there about building HLMs. Singer's paper Using SAS PROC MIXED to Fit Multilevel Models, Hierarchical Models, and Individual Growth Models is one of the best. – DJohnson Nov 21 '17 at 19:45
• ctd. Forget the SAS part, it's just a great overview. Lee Cooper's book Market Share Analysis is another great intro to pooled time series/panel data models. Again, forget the market share part, it's just an excellent intro (here ... anderson.ucla.edu/faculty/lee.cooper/MCI_Book/BOOKI2010.pdf) Gelman and Hill's book is another useful resource Data Analysis Using Multilevel/Hierarchical Models. – DJohnson Nov 21 '17 at 19:48
• There are mean differences using centered data, but they're small. The series is definitively seasonal, so autocorrelation is my problem. Not sure how to use lme4 in this case and don't want to use nlme. Case control indeed don't mean a thing, but it was a requirement. This is a R/lme4 question, by the way. I should have stressed that. I'll check the books. – Jarretinha Nov 21 '17 at 21:15
• The panel data modeling literature wrt classic univariate time series issues such as autocorrelation, cointegration, stationarity, etc., is surprisingly thin, e.g., a multivariate, pooled data extension of the Dickey-Fuller test for unit roots doesn't exist, to the best of my knowledge. Papers by M. Hashan Pesaran, e.g., Testing Weak Cross-Sectional Dependence in Large Panels and Unit roots and cointegration in panels are the best references and leads. – DJohnson Nov 21 '17 at 22:25
• I think such refinement would be an overkill. My idea is to use time as a random effect and hope this will be enough to account for (auto) correlation effects, as some sort of repeated measures design. Am I pushing too hard the design? – Jarretinha Nov 21 '17 at 23:02