X Tutup
Skip to content

docstrings of cross-correlation functions (acorr and xcorr) need clarification #1835

@pierre-haessig

Description

@pierre-haessig

1) lags interpretation

Coming from a discussion on numpy mailing-list [1] I noticed an ambiguity in the interpretation of the sign of the lags in plt.xcorr cross-correlation function. In R's acf/ccf documentation [2] there is the following notice :

The lag k value returned by ccf(x, y) estimates the correlation between x[t+k] and y[t].

I think that xcorr uses the same convention (like Matlab [3]) so we should put some similar notice. (note that this does not seem to be a universal definition. On Wikipedia cross-correlation page, the definition mentions x[t] * y[t+k] instead)

2) normed argument

In addition, the definition of the normed argument seems weird:

If normed = True, normalize the data by the cross correlation at 0-th lag

I think this is not what is computed [4]:

if normed:
    c /= np.sqrt(np.dot(x, x) * np.dot(y, y))

Maybe the acorr definition of normalization also needs so fine tuning because it's somehow recursive.

[1] http://mail.scipy.org/pipermail/numpy-discussion/2013-March/065839.html
[2] http://stat.ethz.ch/R-manual/R-patched/library/stats/html/acf.html
[3] http://www.mathworks.fr/fr/help/signal/ref/xcorr.html
[4] https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes.py#L4508

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesDocumentation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup