问题
I want to test whether a time series contains structural changes or not.
Using this simulated example creates a series with two breaks after 30 and 80 observations.
set.seed(42)
sim_data = data.frame(outcome = c(rnorm(30, 10, 1), rnorm(50, 20, 2), rnorm(20, 45, 1)))
sim_ts = ts(data = sim_data, start = c(2010, 1), frequency = 12)
plot(sim_ts)
I use the strucchange R package to determine the number (if any) of break points and model these:
library("strucchange")
break_points = breakpoints(sim_ts ~ 1) #2 breakpoints at 30 and 80
break_factor = breakfactor(break_points, breaks = 2)
break_model = lm(sim_ts ~ break_factor - 1)
... and put the fitted model with 2 structural change points on top of the raw time series:
lines(fitted(break_points, breaks = 2), col = 4)
What I'm interested in is: how can I test whether the model with structural changes fits better than a simple linear model?
simple_lm = lm(sim_ts ~ time(sim_ts))
abline(simple_lm, col='red') #to add the linear line to the plot
Is the model comparison just: anova(simple_lm, break_model)
?
And wouldn't I need an initial test for stationarity first? Or is this subsumed by the model comparison?
回答1:
The "normal" way in the forecasting literature to evaluate a good fit is the use of a loss function (MSE). Because you are not forecasting maybe the easiest way is to just compare R². (If all you care about is a good fit)
The Anova Method needs the asumption of independence of observervations, so I´m not sure if there is a possible pitfall. Even though it seems to work here.
来源:https://stackoverflow.com/questions/51483673/model-comparison-for-breakpoint-time-series-model-in-r-strucchange