Tom's answer https://stats.stackexchange.com/a/7848/49691 to question How to make a time series stationary? highlights that:
"If a series exhibits level shifts (ie change in intercept) the appropriate remedy to make the series stationary is to "demean" the series".
So I figured out this scenario:
set.seed(1023)
library(urca)
ts1 <- rnorm(500,0,2)
ts2 <- rnorm(500,0,2) + 5
tst <- c(ts1, ts2)
par(mfrow=c(2,1))
plot(tst, type='l')
plot(tst-mean(tst), type ='l')
Now, if I run the adf.test on original time series tst, I obtain:
(urdftest_lag = floor(12* (length(tst)/100)^0.25))
[1] 21
summary(ur.df(tst , type = "none", lags = urdftest_lag, selectlags="BIC"))
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression none
Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
Residuals:
Min 1Q Median 3Q Max
-6.1189 -1.3516 0.0144 1.4353 9.9318
Coefficients:
Estimate Std. Error t value Pr(>|t|)
z.lag.1 -0.01769 0.01857 -0.952 0.34125
z.diff.lag1 -0.87169 0.03643 -23.928 < 2e-16 ***
z.diff.lag2 -0.77406 0.04553 -17.000 < 2e-16 ***
z.diff.lag3 -0.68475 0.05112 -13.395 < 2e-16 ***
z.diff.lag4 -0.59907 0.05483 -10.925 < 2e-16 ***
z.diff.lag5 -0.58710 0.05705 -10.291 < 2e-16 ***
z.diff.lag6 -0.55286 0.05822 -9.495 < 2e-16 ***
z.diff.lag7 -0.43192 0.05798 -7.450 2.07e-13 ***
z.diff.lag8 -0.32365 0.05625 -5.754 1.17e-08 ***
z.diff.lag9 -0.26836 0.05352 -5.014 6.34e-07 ***
z.diff.lag10 -0.25028 0.04900 -5.107 3.94e-07 ***
z.diff.lag11 -0.17598 0.04250 -4.141 3.77e-05 ***
z.diff.lag12 -0.09793 0.03205 -3.056 0.00231 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.131 on 965 degrees of freedom
Multiple R-squared: 0.4489, Adjusted R-squared: 0.4415
F-statistic: 60.46 on 13 and 965 DF, p-value: < 2.2e-16
Value of test-statistic is: -0.9522
Critical values for test statistics:
1pct 5pct 10pct
tau1 -2.58 -1.95 -1.62
Based on test statistics, I cannot reject the null hypothesis of unit root presence.
If I run the same test on the demean time series, I get:
summary(ur.df(tst - mean(tst) , type = "none", lags = urdftest_lag, selectlags="BIC"))
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression none
Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
Residuals:
Min 1Q Median 3Q Max
-5.8250 -1.3856 -0.0245 1.4120 9.0471
Coefficients:
Estimate Std. Error t value Pr(>|t|)
z.lag.1 -0.06758 0.02564 -2.635 0.00854 **
z.diff.lag1 -0.80020 0.03912 -20.456 < 2e-16 ***
z.diff.lag2 -0.68062 0.04594 -14.816 < 2e-16 ***
z.diff.lag3 -0.56764 0.04903 -11.578 < 2e-16 ***
z.diff.lag4 -0.45288 0.04995 -9.067 < 2e-16 ***
z.diff.lag5 -0.41513 0.04933 -8.416 < 2e-16 ***
z.diff.lag6 -0.35931 0.04685 -7.669 4.22e-14 ***
z.diff.lag7 -0.21806 0.04185 -5.211 2.29e-07 ***
z.diff.lag8 -0.08629 0.03205 -2.693 0.00721 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.153 on 969 degrees of freedom
Multiple R-squared: 0.435, Adjusted R-squared: 0.4298
F-statistic: 82.9 on 9 and 969 DF, p-value: < 2.2e-16
Value of test-statistic is: -2.6353
Critical values for test statistics:
1pct 5pct 10pct
tau1 -2.58 -1.95 -1.62
And in this case, I reject the null hypothesis of unit root presence
However I cannot understand how such demeaning works with respect the Augmented Dickey Fuller test. Are not we dealing with the "same" time series in both cases besides the mean level ?