# How to do time-series analysis for 2x2x2 factorial design?

I have a dataset with the following variables for the treatment (nutrition, fertilizer), that records algal growth in water across time (t0, t1...t10). In series with fertilizer marked as "nitrogen" , nitrogen was added after day t5. In series marked as "none", no nitrogen was added.

nutrition fertilizer t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
good      none       6  7  5   4  4  3  4  5  4  3  2
good      nitrogen   4  5  6   7  8  33 44 55 66 77 88
bad       none       6  7  5   5  0  3  4  5  2  3  2
bad       nitrogen   4  5  6   7  8  3  3  0  6  7  8


I wish to do an analysis that compares algal growth before and after fertilizer treatment for the good and bad food type using (good, none) or (bad, none) as controls.

I was recommended to do some type of time-series analysis for this data. However, there is so much out there that I don't know which, or what type would be most appropriate. My software of preference is R. Any suggestions?

• Do you have any replicates, or is what you posted the full dataset? – eric_kernfeld Dec 6 '17 at 14:01
• Yes, each treatment above has 6 replicates each – PythonDabble Dec 6 '17 at 14:02
• You say before and after fertilizer treatment. So is row 1 the same unit of treatment as row 2? Same pond before and after fertilizer is added? Or is the fertilizer added between t4 and t5, when the big spike is observed? – eric_kernfeld Dec 6 '17 at 14:43
• Yes, all rows have the same unit of treatment. All rows are separate ponds. In Row 1 and Row 3, no fertlizers were ever added. In row 2 and Row 4 fertilizer was added between day t4 and t5 – PythonDabble Dec 6 '17 at 15:24
• Are the time points evenly spaced? – eric_kernfeld Dec 6 '17 at 16:45

My go-to strategy for this type of data is a regression framework. For example, you could use the model $y_{it} = \beta_{0k} x_{itk} + \beta_{1k} d(t) + \beta_{2k} d(t)x_{itk} + \epsilon_{it}$, where:

• $y_{it}$ is the outcome for pond $i$, time $t$,
• $x_{itk}$ is 1 if good nutrition, 0 if bad
• $d(t)$ is the number of days since adding fertilizer (0 if no fertilizer added).
• $\epsilon_{it}$ is an i.i.d. error term.

You could account for within-pond correlations by adding random effects to each of the beta's. This is an alternative to e.g. autoregressive models, which introduce correlations in $\epsilon_i$ within each pond from one time point to the next.

The resulting covariance structure depends on what random effect or error model you choose. For example, including a random intercept produces a compound symmetric covariance structure, where the diagonal is constant at one value and the off-diagonal constant at another value. Correlation is constant within ponds for any two time points. The autoregressive error model would have rapidly decreasing covariances as observations move farther apart, but still constant variance. Random slopes would produce variances that increase over time, so that in the disgusting old fertilized algae-infested ponds, the amount of algae is expected to increase in variability as well as in quantity. It would also increase covariances between observations at high values of $d(t)$, since the best-fit line "wags" back and forth sweeping them out in parallel. You could select a model based on what type of covariance you expect.

• Why are you using d = 0 for all of the days with no fertilizer added case? Otherwise, how is it possible to compare trajectories after t5 from control and treatment? – PythonDabble Dec 8 '17 at 20:05
• Also, why aren't you accounting for time and infection status separately? For example, if were to do something like a longitudinal analysis, I would have a model like lmer(algal growth ~ food + fertilizer + days + prepostfertlizer + (1|pond) where prepostfertilizer is coded as 0 for values before t5, and 1 for values after t5. – PythonDabble Dec 8 '17 at 20:10
• What is infection status? Is that some other response variable that you did not include in the original question? – eric_kernfeld Dec 10 '17 at 18:03
• I would expect the fertilizer to have an effect only after it is added, so I think you want I(prepostfertlizer*fertilizer) in place of each one separately. Or, if you put zeroes in prepostfertlizer for the non-fertilized ponds, you could just keep the prepostfertlizer term and omit the fertilizer term. I meant $d$ to have the same role as I(prepostfertlizer*fertilizer) in your model, except I put my model in terms of the absolute amount of algae rather than algal growth. – eric_kernfeld Dec 10 '17 at 18:10