Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Clarify output size in statsmodels.tsa.stattools.acf #7818

Closed
enricovara opened this issue Oct 24, 2021 · 5 comments · Fixed by #7927
Closed

DOC: Clarify output size in statsmodels.tsa.stattools.acf #7818

enricovara opened this issue Oct 24, 2021 · 5 comments · Fixed by #7927

Comments

@enricovara
Copy link
Contributor

Autocorrelation output size is inconsistent using statsmodels.tsa.stattools.acf

The statsmodels.tsa.stattools.acf function returns nlags+1 values for the acf and confint return variables (because it includes the output at lag 0 (ie., acf=1)) but nlags values for the qstat and values return variables. I see this as needlessly confusing and easily fixed by making all outputs of size nlags or all of size nlags+1. If otherwise there is a reason for this, I'd love to be educated!

Code Sample, a copy-pastable example if possible

import statsmodels.tsa.stattools as smtsa
import numpy as np
x = np.random.randint(0,10,size=20)
acf, confint, qstat, pvalues = smtsa.acf(x, nlags=7, qstat=True, alpha=0.05)

print('len(acf)', len(acf))
print('len(confint)', len(confint))
print('len(qstat)', len(qstat))
print('len(pvalues)', len(pvalues))
Output

len(acf) 8
len(confint) 8
len(qstat) 7
len(pvalues) 7

Expected Output

len(acf) 7
len(confint) 7
len(qstat) 7
len(pvalues) 7

or

len(acf) 8
len(confint) 8
len(qstat) 8
len(pvalues) 8

Output of import statsmodels.api as sm; sm.show_versions()

[paste the output of import statsmodels.api as sm; sm.show_versions() here below this line]
INSTALLED VERSIONS

Python: 3.7.12.final.0
OS: Linux 5.4.104+ #1 SMP Sat Jun 5 09:50:34 PDT 2021 x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

Statsmodels

Installed: 0.10.2 (/usr/local/lib/python3.7/dist-packages/statsmodels)

Required Dependencies

cython: 0.29.24 (/usr/local/lib/python3.7/dist-packages/Cython)
numpy: 1.19.5 (/usr/local/lib/python3.7/dist-packages/numpy)
scipy: 1.4.1 (/usr/local/lib/python3.7/dist-packages/scipy)
pandas: 1.1.5 (/usr/local/lib/python3.7/dist-packages/pandas)
dateutil: 2.8.2 (/usr/local/lib/python3.7/dist-packages/dateutil)
patsy: 0.5.2 (/usr/local/lib/python3.7/dist-packages/patsy)

Optional Dependencies

matplotlib: 3.2.2 (/usr/local/lib/python3.7/dist-packages/matplotlib)
backend: module://ipykernel.pylab.backend_inline
cvxopt: 1.2.7 (/usr/local/lib/python3.7/dist-packages/cvxopt)
joblib: 1.0.1 (/usr/local/lib/python3.7/dist-packages/joblib)

Developer Tools

IPython: 5.5.0 (/usr/local/lib/python3.7/dist-packages/IPython)
jinja2: 2.11.3 (/usr/local/lib/python3.7/dist-packages/jinja2)
sphinx: 1.8.5 (/usr/local/lib/python3.7/dist-packages/sphinx)
pygments: 2.6.1 (/usr/local/lib/python3.7/dist-packages/pygments)
pytest: 3.6.4 (/usr/local/lib/python3.7/dist-packages)
virtualenv: Not installed

@bashtage
Copy link
Member

I think it is because the ACF is well defined for lag 0 (it is the variance) while the q-stat and its p-value are not defined for 0 lags. Docs could be improved.

@bashtage bashtage changed the title Output size is inconsistent using statsmodels.tsa.stattools.acf DOC: Clarify output size in statsmodels.tsa.stattools.acf Oct 25, 2021
@enricovara
Copy link
Contributor Author

The ACF for lag 0 is 1 if I'm not mistaken, and is therefore trivial?

@bashtage
Copy link
Member

Yes, sorry. Was thinking of autocov rather than autocorr. But still well defined. Of course, has no estimation error too. Probably not worth the pain to change these to match.

@enricovara
Copy link
Contributor Author

I understand, thanks!

bashtage added a commit to bashtage/statsmodels that referenced this issue Dec 6, 2021
@bashtage
Copy link
Member

bashtage commented Dec 6, 2021

I made a few smal changes in 7927, that build on your commits. Thanks for this.

@bashtage bashtage added this to the 0.13.2 milestone Feb 8, 2022
@bashtage bashtage modified the milestones: 0.13.2, 0.14 Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants