Skip to main content

dieboldmariano

This package provides a simple, pure-Python implementation of the Diebold-Mariano statistical test. It has no dependencies outside the Python standard library.

What is the Diebold-Mariano test?

Assume we have a real-valued timeseries $T_{n \ge 0}$, and two forecasters $F$, $G$ who each produce predictions $F_{n \ge 0}$, $G_{n \ge 0}$. Which one is better? Is the difference statistically significant?

The cost function for errors can be specified arbitrarily and does not need to be symmetric (for example, one might want to penalize errors in one direction more).

An usual choice (the default in this implementation if no cost function is passed explicitly) is the square error.

The test produces the DM statistic and the corresponding p-value.

A more detailed and very accessible description is available at the link [3] in the references section.

Code example

from dieboldmariano import dm_test
T = [10, 20, 30, 40, 50]
F = [11, 21, 29, 42, 53]
G = [13, 26, 24, 40, 59]

dm_test(T, F, G, one_sided=True)
# (-2.2229922805746782, 0.04515565862099125)

Usage

The public interface of the package is the dm_test function.

It outputs a tuple of two values, the DM statistic and the p-value, in that order.

It takes the following parameters:

V (ordinal): Sequence[float]
The actual timeseries.

P1 (ordinal): Sequence[float]
First prediction series.

P2 (ordinal): Sequence[float]
Second prediction series.

loss (keyword): Callable[[float, float], float]
Loss function used to charge each prediction at each timestep. Takes actual and predicted values as arguments in that order. Default: squared error lambda u, v: (u - v) ** 2

h (keyword): int
Forecast horizon. Default: 1

one_sided (keyword): bool
If true, tests if P2 has at least as much predictive accuracy as P1. If false, tests if accuracies are equal. Default: false

harvey_correction (keyword): bool
If true, uses modified test statistics per [1]. Default: true

variance_estimator (keyword): Literal["acf", "bartlett"]
Long-run variance estimator type:

  • "acf": autocorrelation method
  • "bartlett": Bartlett weights method

Both methods are discussed in [2].

References

[1] Diebold, F.X. and Mariano, R.S. (1995) Comparing predictive accuracy. Journal of Business and Economic Statistics, 13, 253-263.

[2] Harvey, D., Leybourne, S., & Newbold, P. (1997). Testing the equality of prediction mean squared errors. International Journal of forecasting, 13(2), 281-291.

[3] https://www.real-statistics.com/time-series-analysis/forecasting-accuracy/diebold-mariano-test/

Metadata

Release files for dieboldmariano 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dieboldmariano 1.1.0
File Size Uploaded Provenance
dieboldmariano-1.1.0.tar.gz 5.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dieboldmariano 1.1.0
File Interpreter ABI Platform
dieboldmariano-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / dieboldmariano-1.1.0.tar.gz

Download URL dieboldmariano-1.1.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7afe22da3440dbaa3d6d8f5d0785ad92ccd256d87aba2b214485c0fb8856da22
BLAKE2b-256 checksum
How to use checksums
25eb5f2a15a611d59ea72023a0ad1788f842177125235c2932cbb44636f74ac6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Release files / dieboldmariano-1.1.0-py3-none-any.whl

Download URL dieboldmariano-1.1.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5000b8bfabfcb3ca9aebdfd74b6c9814ce5e00650356323b0939cdf6f7cd4d7e
BLAKE2b-256 checksum
How to use checksums
9fe985a1d3d95ac9124ab3fc15763031a2f9079affe6483896270988d87fc1a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Security for dieboldmariano 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page