2016-10-07 33 views
0

因此,我想對resudual做一個box-ljung測試,但我得到一個奇怪的錯誤,我無法弄清楚爲什麼。從statsmodel acorr_ljungbox錯誤

x = diag.acorr_ljungbox(np.random.random(20)) 

我試圖做同樣的用隨機陣列還,仍然是相同的錯誤:

ValueError: operands could not be broadcast together with shapes (19,) (40,) 
+0

你可以發佈周邊代碼 –

+0

問題是因爲該函數默認使用lag = 40,並且數組比這更短。如果您明確設定延遲,則會解決該問題。請參閱下面的回答 –

回答

0

這看起來像在默認滯後設定一個錯誤,這被設置爲40個獨立的長度的的數據。

作爲一種解決方法並獲得適當的統計信息,lags需要受到限制,例如,使用下面5個滯後。

>>> from statsmodels.stats import diagnostic as diag 

>>> diag.acorr_ljungbox(np.random.random(50))[0].shape 
(40,) 

>>> 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])) 
+0

這裏現在報告https://github.com/statsmodels/statsmodels/issues/3229 – user333700