繁体   English   中英

偏自相关函数的 P 值

[英]P-value of partial autocorrelation function

目标:计算 2 到 40 阶的偏自相关的 p 值。相关也是如此

目前:我正在使用“statsmodel”的模块acfpacf来计算自相关和偏自相关。

from statsmodels.graphics.tsaplots import acf, pacf
[accf, qstat, pvalue] = acf(rtrn, unbiased=False, nlags=40, qstat=True, fft=False, alpha=None, missing='none')
paccf = pacf(rtrn, nlags=40, method='ywunbiased', alpha=None) 

# let's say rtrn is known
# rtrn = np.arange(80)
# accf = array([ 1.,  0.9625,  0.92502344, ..., -0.25011721])
# paccf = array([ 1., 0.97468354, -0.02532447, ..., -0.12554433])
# !!! I would like also the p-values of these correllations

有人可以告诉我要使用的公式或模块吗?

在此先感谢您的帮助。

您可以使用statsmodel 的“Ljung-Box 测试”

from statsmodels import stats

lbvalues, pvalues = stats.diagnostic.acorr_ljungbox(rtnr) #I guess rtnr is your data to test for 

p 值与置信区间有关,因为如果您的 p 值恰好为 0.05,那么您在 0.05 处的置信区间将上升但不会超过 0。

考虑到这一点,我们可以反转置信区间计算,这样我们就可以将 alpha 设为未知变量,并使用自相关值作为输入,而不是将 alpha 固定为 0.05。

如果您查看 stattools,这就是它们计算置信区间的方式:

from statsmodels.tsa import stattools
ret = stattools.pacf_ols(x, nlags=40)
varacf = 1. / len(x)  # for all lags >=1
interval = stattools.stats.norm.ppf(1. - alpha / 2.) * np.sqrt(varacf)
confint = np.array(lzip(ret - interval, ret + interval))

要反转这个方程来求解 p 值,您将间隔设置为等于 pacf 值,然后求解 alpha。

pvalues = stats.norm.sf(abs(ret) / np.sqrt(1. / len(x)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM