I’d like to test whether my time series of consecutive payments is independent or not and thought that since this is a pretty common condition in statistics it should be easy. Well, turns out is isn’t – at least for me.

Now I found these earlier posts which have driven me into the Ljung-Box or Box-Pierce direction:

Testing normality and independence of time series residuals

What is a reasonable independence test for a time series?

I'm working with R and at first I wanted to check the test and if I correctly understand its p-value. So I thought of the following vector and expected a quite low p-value but now I’m surprised about the high number (0.5391) and its implication on not to reject the hypothesis of “independently distributed”.

Box.test(test,lag=1,type = "Ljung-Box")

So what am I getting wrong or is there a different/better way to test the independence of my time series where I don't know its distribution?

  • $\begingroup$ What kind of data are you working with? Is it continuos data? $\endgroup$
    – fsociety
    Commented May 9, 2016 at 9:23
  • $\begingroup$ Yes, it's continous. (I only have 15 observations of a yearly payment.) $\endgroup$
    – Zap
    Commented May 9, 2016 at 9:33
  • $\begingroup$ Not sure if that is what you want to achieve, but you could compare a simple regression model with a AR(1) regression by model comparison (e.g., using BIC). $\endgroup$
    – fsociety
    Commented May 9, 2016 at 9:54
  • $\begingroup$ So let's say test is my time series. Then I should compare the AIC (since BIC is not an output of ar) of ar(test, FALSE, 1) with the AIC of what simple regression? $\endgroup$
    – Zap
    Commented May 9, 2016 at 12:24

1 Answer 1


If you want to conduct a hypothesis test to evaluate whether a time series has an autocorrelation that differs from 0 then the Ljung-Box test is a perfectly reasonable approach.

However, I'm not sure why you would expect your vector to display a strongly autocorrelated signal, as there's basically no variation in it all.

Try the test again with one of R's built in datasets that show a clear autocorrelation signal, such as in my example below using monthly temperature data over many years.

Box.test(nottem, lag = 1, type = "Ljung-Box")

Note that at this and other lags you'll find a very small p-value, which (as you seem to have been expecting) indicates that if you assume the null hypothesis to be true (i.e. the autocorrelation to be 0), then the probability of observing this data or more extreme data (i.e. more autocorrelated data) is very small, and therefore it's reasonable to conclude the data are highly likely to be autocorrelated.

To understand the autocorrelation pattern further I would also strongly suggest initially looking at the autocorrelation and partial autocorrelation function (see https://en.wikipedia.org/wiki/Partial_autocorrelation_function for a good explanation), which can be done easily in R with the acf and pacf function as shown below for the same data. These will help you understand the extent of the lags in your data.

  • $\begingroup$ Well I expected a low p-value because all observation are nearly the same, so a high correlation. After wiki I still have troubles in understanding those plots. For example acf has six breaks on the x-axis between 0 and 0.5 but delivers only five values in the plot.For pacf it's six breaks, six values. And what sense does a lag of for example 0.3 in your data even make? R can not even perform that since it expects integers. lag(nottem,k=0.3) $\endgroup$
    – Zap
    Commented May 9, 2016 at 11:58
  • $\begingroup$ And furthermore I fail to reproduce the acf-values from your data. Here is my code for lag 1: n1<-nottem[1:(length(nottem)-1)] n2<-nottem[2:(length(nottem))] m1<-mean(n1) m2<-mean(n2) acf_lag1<-sum((n1-m1)*(n2-m2))/(sqrt(sum((n1-m1)^2))*sqrt(sum((n2-m2)^2))) acf(nottem)$acf[2] $\endgroup$
    – Zap
    Commented May 9, 2016 at 13:56

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.