Error in acorr_ljungbox from statsmodel
<p>So I am trying to do a box-ljung test on a resudual, but I am getting a strange error and am not able to figure out why.</p>

<pre><code>x = diag.acorr_ljungbox(np.random.random(20))
</code></pre>

<p>I tried doing the same with a random array also, still the same error:</p>

<pre class="lang-none prettyprint-override"><code>ValueError: operands could not be broadcast together with shapes (19,) (40,)
</code></pre>

<p>This looks like a bug in the default lag setting, which is set to 40 independent of the length of the data.</p>

<p>As a workaround and to get a proper statistic, the <code>lags</code> needs to be restricted, e.g. using 5 lags below.</p>

<pre><code>&gt;&gt;&gt; from statsmodels.stats import diagnostic as diag

&gt;&gt;&gt; diag.acorr_ljungbox(np.random.random(50))[0].shape
(40,)

&gt;&gt;&gt; diag.acorr_ljungbox(np.random.random(20), lags=5)
(array([ 0.36718151,  1.02009595,  1.23734092,  3.75338034,  4.35387236]),
array([ 0.54454461,  0.60046677,  0.74406305,  0.44040973,  0.49966951]))
</code></pre>

python statsmodels