# About the stationarity of a sine wave

I generated two sine wave time series and want to check the stationarity of them.

(1) The first time series is short. kpss.test() thinks it is stationary. PP.test() doesn't reject the null of unit root.

n=120
t=1:n
x=sin(t/(n-1)*6*pi)+rnorm(n)*0.2
par(mfrow=c(2,1))
plot(x,ty='l',xlab='',ylab='x',main='Sine')

# stationary test (H0:stationary)
kpss.test(x)$p.value #[1] 0.1 # unit root test (H0: unit root) PP.test(x)$p.value
#[1] 0.4937582


(2) The second one is much longer. kpss.test() says it is non-stationary while PP.test() tells it is stationary.

n=1000
t=1:n
x=sin(t/(n-1)*6*pi)+rnorm(n)*0.2
plot(x,ty='l',xlab='',ylab='x',main='Sine')

# stationary test (H0:stationary)
kpss.test(x)$p.value #[1] 0.01 # unit root test (H0: unit root) PP.test(x)$p.value
#[1] 0.01


While kpss.test() is more powerful for small samples (please see this Q&A), the first instance is understandable. However, I am really confused why kpss.test() fails for the second larger-sample time series. Anyone have any comments or answers please?

• a sine wave is not stationary but unless I missed something, I don't think it has a unit root (which is a particular kind of nonstationarity). But in any case, failure to find a unit root doesn't imply stationarity. – Glen_b Dec 2 '13 at 1:43

## 2 Answers

We can classify trend part of time series in two parts: 1) Deterministic; 2) Stochastic. Most of the tests around stationarity is to test the unit root (deterministic trend).

In your case it is clearly deterministic trend. The trend part one can write as a function of time. Regarding the kpss test, null hypothesis of kpss test is the series is level or trend stationary. Kpss test accept H0 in your case. (In your second case, if you increase your frequency the test may fail to rejct the H0, x=sin(t/(n-1)*60*pi)+rnorm(n)*0.2).

Usually in time series modelling first step is to eliminate (remove or by adding deterministic part) deterministic part in the time series. So practically this cases will not arise.

• Surely you meant that the tests for stationarity test for stochastic trend? – mpiktas Dec 2 '13 at 5:07
• @mpiktas, let me know if I am missing something. – vinux Dec 2 '13 at 5:23
• Well the tests for stationarity usually test or test against unit root, hence stochastic trend, not deterministic. – mpiktas Dec 2 '13 at 7:53
• Agreed. I will add this and avoid the confusion. – vinux Dec 2 '13 at 8:49
• I agree with @mpiktas that unit root test is for stochastic trend. But the null hypothesis of kpss test if level or trend stationary. The 'Trend' here means linear trend instead of any deterministic trend. – yanfei kang Dec 2 '13 at 10:42

The Kwiatkowski–Phillips–Schmidt–Shin 1992 paper proved an influential contribution to time-series analysis, because it was the first well-recognized test that tested for non-stationarity by taking as null-hypothesis that the series is (linear determinisitic) trend-stationary -contrary to the Dickey-Fuller (or Phillips-Peron) family of tests that have as null that a unit root exists (i.e. that the series contains a stochastic trend).

The reasoning behind the KPSS test is that unit-root tests of the DF/PP variety have low power especially when the root may be close to but below unity. Most researchers advise that one should run both kinds of tests, and if they give conflicting results as regards the kind of trend detected, one should conclude that the data are not informative enough to provide an answer.

In the original KPSS test, a time series is modeled as being comprised of a linear deterministic trend, a random walk (the stochastic trend), and a white noise:

$$y_t = at+r_t+u_t, \qquad r_t=r_{t-1}+\varepsilon_t,\; \\u_t, \varepsilon_t\sim\operatorname{white noise and independent}$$

The null hypothesis is that $$\operatorname{Var}(\varepsilon_t)=0$$ which effectively eliminates the existence of the random walk (since it turns it into a constant, supplying the series with a drift). Under this null, the time-series is trend-stationary (i.e. it is stationary around a linear deterministic trend).
The test can also be used to test level-stationarity by not including the deterministic-trend part in the specification.
Under the additional assumption of normally distributed $\varepsilon_t$, the test statistic is a one-sided Lagrange Multiplier one. If the normality assumption is dropped, and if we further weaken the white-noise assumption and assume that $\{\varepsilon_t\}$ forms a mixing process, then the test-statistic has a non-standard distribution, which has special critical values.

As for a sine wave, does it look like it may contain a linear deterministic trend? Seasonality is what happens here. One of the original authors of the KPSS test (Peter C.B. Phillips) shows in this paper that the KPSS test statistic has the same limiting distribution when the data exhibit seasonality.

But here comes the critical point: the KPSS statistic is based on the residuals of least-squares regression of the dependent variable on a constant and a linear time-trend, when there is no seasonality. When there is seasonality, then the test statistic is based on a least-squares regression on a constant and seasonal dummies (or other more complicated ways to model seasonality). Does your software know what kind of regression to estimate in order to calculate the KPSS statistic?