# can a vector of strictly positive values have a negative autocorrelation at any lag?

matlab is giving some weird results.

I have a vector of nonnegative numbers which is the duration between subsequent events. I calculate the autocorrelation of this and plot it, and after about lag 100 it turns negative...

the source data is here

and the autocorrelation is here

• Can the correlation between two non-negative random variables be negative? Nov 10, 2018 at 1:40
• @MossMurderer I don't think so but if I knew that I wouldn't be asking
– crow
Nov 10, 2018 at 2:06
• As one increases, the other decreases. Why would that be restricted to variables that can have negative values? Nov 10, 2018 at 2:39
• The correlation formula is $r = \frac{\sum{(x-m_x)(y-m_y)}}{\sqrt{\sum{(x-mx)^2}\sum{(y-my)^2}}}$ how can it be negative if no element of the input vectors x and y are negative? actually I see how it could be.. I've just never encountered a process with these characteristics... Interesting
– crow
Nov 10, 2018 at 3:04
• If x tends to be above/below $m_x$ when y is below/above $m_y$, then the numerator is a sum over mostly negative values. Nov 10, 2018 at 3:42

can a vector of strictly positive values have a negative autocorrelation at any lag?

[NB As whuber notes, the question is ambiguous. I read it as "With positive time series, can there be a lag at which there's a negative correlation?".]

Consider the sequence $$Y_t =12/Y_{t-1}$$ with $$Y_0=4$$.

Alternatively, consider $$Y_t=10-Y_{t-1}$$ with $$Y_0=4$$.

As a more prosaic but realistic example, take some stationary series that has a negative correlation at some lag and shift it up by some large value $$L$$ (some value easily large enough to make the whole series positive). The autocorrelations are unchanged.

Or take a series with a strong negative correlation and little noise that's close to zero (but can be both positive and negative) and exponentiate it. For example:

 x <- arima.sim(n=1000,list(ar=-.9),sd=.01)
y <- exp(x)
acf(y)


Any of these should suffice to demonstrate that negative autocorrelations are easily attained with positive variates.

• It's unclear which question you are answering, Glen: the answer to the question in the title, which can be understood as "can a vector of positive values have negative autocorrelation coefficients at all nonzero lags," would be a little different.
– whuber
Nov 10, 2018 at 13:56
• @whuber I'm answering "With positive time series, can there be a lag at which there's a negative autocorrelation?" which is how I read the title, though I agree it's ambiguous. I'll put a clarification in my answer. Nov 10, 2018 at 22:59