为什么在Python中statsmodels的相关性和自相关函数结果不同?

4 投票
1 回答
2770 浏览
提问于 2025-04-18 12:18

我需要找出两个不同的数据系列A和B之间的相关性,以及A和B各自的自相关性。使用statsmodels提供的相关性函数时,我得到了不同的结果。计算A的自相关性和计算A与A之间的相关性是不一样的,为什么结果会不同呢?

下面是我说的这种行为的一个例子:

import numpy as np
from matplotlib import pyplot as plt
from statsmodels.tsa.stattools import ccf
from statsmodels.tsa.stattools import acf

#this is the data series that I want to analyze
A = np.array([np.absolute(x) for x in np.arange(-1,1.1,0.1)])

#This is the autocorrelation using statsmodels's autocorrelation function
plt.plot(acf(A, fft=True))

enter image description here

#This the autocorrelation using statsmodels's correlation function
plt.plot(ccf(A, A))

enter image description here

1 个回答

4

这两个函数在布尔值参数 unbiased 的默认设置上是不同的。要想得到和 acf(A, fft=True) 一样的结果,可以使用 ccf(A, A, unbiased=False)

撰写回答