Box-Ljung test on white noise series I generate this data in R: 
set.seed(111)
ds=rnorm(1000)

When I perform Box-Ljung test to test the independency:
Box.test(ds,type='Ljung',lag=log(length(ds)))

it gave me p-value=0.5957, which is reasonable. However, when I perform this:
Box.test(ds[180:299],type='Ljung',lag=log(length(ds[180:299])))

it gave me p-value=0.00162045, which means the autocorrelation of this sub-sequence is significantly different from zero. This also happens for some other subsequences. However, I generated the time series using $rnorm$ function in R with 1000 data points. Could anybody please explain this? Thanks very much in advance.
For the convenience of you readers who are not using R, the sub-sequence ds[180:299] can be obtained here: http://ykang.hostoi.com/ds120.pdf 
 A: Let us do a simulation where we apply the test 1000 times for time series of length 120.
> fun <- function(n) {Box.test(rnorm(n),type="Ljung-Box",lag=log(n))$p.value}
> set.seed(111)
> mc <- sapply(rep(120,1000),fun)
> sum(mc<0.05)/length(mc)
[1] 0.039

So you get 39 cases out of 1000 for which the null is rejected if we assume threshold 0.05. This is perfectly normal. 
The test statistic is a random variable which has a distribution. This means that it can get values which are unlikely, or likely with small probability. We reject the null hypothesis when the value is unlikely, yet by doing this we commit Type I error. 
A: This subsequence testing is actually related to the locally stationary extension of the Box test to detect time-varying dependencies (paper).
Under the null hypothesis of independent white noise you can compute the Box test on $N$ non-overlapping subwindows over your time series, add them all together, and then test the sum of these test statistics for significance.  This works out since asymptotically the test statistic of window $i$ has a $\chi^2$ distribution with $k_i$ degrees of freedom, where $k_i$ is the lags tested in subwindow $i$, $i = 1, \ldots, N$.  Under the null they are independent, and the sum of independent $\chi^2$ random variables has again a $\chi^2$ distribution with $K = \sum_{i=1}^{N} k_i$ degrees of freedom.
This should answer why one subwindow of your time series may have a low p-value; but when you add all sub-window test statistic, this one large test statistic in your particular window will be balanced with some extremely low test statistics in other subwindows.  Overall, you will get again the right test coverage.
See the paper above for technical details. For R code and a data application see this blog post or the other stackoverflow post: ``Nice example where a series without a unit root is non stationary?''
