0
$\begingroup$

I have two data sets of time series, estimated fish populations, one pre treatment (n=36) and one post treatment (n=11). The means of the two data sets are not significantly different owing, I think, to high variability in both. If you fit a line to each data set, the pretreatment data shows a positive line slope while the posttreatment line shows a negative line slope. How can you test the two line slopes to show a significant difference between the two?

$\endgroup$
2
  • $\begingroup$ Can you augment your post with a plot? $\endgroup$ Dec 12, 2022 at 18:07
  • 1
    $\begingroup$ "intervention detection in time series" can test not only the change a mean at one or more points in time but a change in trend at one or more points in time. I have written and commented about this a number of times. Pleasr search for my responses. Essentially after adjusting for arima effects and 1 time pukse anomalies, a search can be performed following Professor Lon Liu to detect when significant changes in mean/trend occurred. $\endgroup$
    – IrishStat
    Dec 12, 2022 at 18:45

1 Answer 1

1
$\begingroup$

As you evidently have a defined time at which the treatment began, this is a simpler problem than trying to find a change point in general. You model population as a function of time, but include an interaction between time and treatment. That allows for different slopes and intercepts, depending on treatment.

Here's a simple example in R. Have pop increase for the first 36 time points and decrease for the last 11, with random noise built in. The treatment trt starts at time=37.

set.seed(204)
popUp <- 25 + 0.4*(1:36) + rnorm(36)
popDown <- 39.4 - 0.8*(1:11) + rnorm(11)
fishDat <- data.frame(pop=c(popUp,popDown),time=1:47,trt=c(rep(FALSE,36),rep(TRUE,11)))

Then do a linear regression model including an interaction of time with treatment.

fishMod <- lm(pop~time*trt,data=fishDat)
summary(fishMod)

# Call:
# lm(formula = pop ~ time * trt, data = fishDat)
# 
# Residuals:
#      Min       1Q   Median       3Q      Max 
# -2.28058 -0.74752  0.00296  0.82027  2.65717 
# 
# Coefficients:
#              Estimate Std. Error t value Pr(>|t|)    
# (Intercept)  24.92105    0.41817  59.596  < 2e-16 
# time          0.40047    0.01971  20.319  < 2e-16 
# trtTRUE      43.90492    4.95099   8.868 2.90e-11 
# time:trtTRUE -1.20957    0.11877 -10.184 4.95e-13 
# ---
# 
# Residual standard error: 1.228 on 43 degrees of freedom
# Multiple R-squared:  0.9202,  Adjusted R-squared:  0.9146 
# F-statistic: 165.3 on 3 and 43 DF,  p-value: < 2.2e-16

The time:trtTRUE interaction coefficient indicates that the slope is different between the 2 treatment periods. It's the difference from the coefficient shown for time alone, which represents the slope while trt=FALSE.

You might use a Poisson generalized linear model if your values are counts. It's often better to model time flexibly, for example with a regression spline, but you might not have enough data with only 11 points during the treatment period.

A warning: if you decided to do this analysis of slope only after you saw the results, then the p-values shouldn't be relied upon. The model producing them assumes that you didn't use prior outcomes from the data to build the model. If you were already intending to look at different slopes over time depending on treatment, then you're OK.

Another warning: proper time-series analysis takes into account correlations along time among the observations. That's particularly important if you are trying to evaluate multiple observed predictor variables. I don't think you will have a problem justifying a simple evaluation of linear trends in this simple case with a defined time at which you introduced the treatment.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.