Skip to main content

L-Moments for robust statistics.

Project description

jorenham/lmo

Lmo - Trimmed L-moments and L-comoments

license PyPI PyPI - Downloads versions GitHub Workflow Status (with branch) GitHub commit activity (branch)


Is your tail too heavy?
Can't find a moment?
Are the swans black?
The distribution pathological?

... then look no further: Lmo's got you covered!

Uniform or multi-dimensional, Lmo can summarize it all with one quick glance!

Unlike the legacy moments, L-moments uniquely describe a probability distribution, and are more robust and efficient. The "L" stands for Linear; it is a linear combination of order statistics. So Lmo is as fast as sorting your samples (in terms of time-complexity).

Key Features

  • Calculates trimmed L-moments and L-comoments, from samples or any scipy.stats distribution.
  • Full support for trimmed L-moment (TL-moments), e.g. lmo.l_moment(..., trim=(1/137, 3.1416)).
  • Generalized Method of L-moments: robust distribution fitting that beats MLE.
  • Fast estimation of L-comoment matrices from your multidimensional data or multivariate distribution.
  • Goodness-of-fit test, using L-moment or L-moment ratio's.
  • Exact (co)variance structure of the sample- and population L-moments.
  • Theoretical & empirical influence functions of L-moments & L-ratio's.
  • Complete docs, including detailed API reference with usage examples and with mathematical $\TeX$ definitions.
  • Clean Pythonic syntax for ease of use.
  • Vectorized functions for very fast fitting.
  • Fully typed, tested, and tickled.
  • Optional Pandas integration.

Quick example

Even if your data is pathological like Cauchy, and the L-moments are not defined, the trimmed L-moments (TL-moments) can be used instead. Let's calculate the TL-location and TL-scale of a small amount of samples:

>>> import numpy as np
>>> import lmo
>>> rng = np.random.default_rng(1980)
>>> x = rng.standard_cauchy(96)  # pickle me, Lmo
>>> lmo.l_moment(x, [1, 2], trim=(1, 1)).
array([-0.17937038,  0.68287665])

Now compare with the theoretical standard Cauchy TL-moments:

>>> from scipy.stats import cauchy
>>> cauchy.l_moment([1, 2], trim=(1, 1))
array([0.        , 0.69782723])

See the documentation for more examples and the API reference.

Roadmap

  • Automatic trim-length selection.
  • Plotting utilities (deps optional), e.g. for L-moment ratio diagrams.

Installation

Lmo is on PyPI, so you can do something like:

pip install lmo

Required dependencies

These are automatically installed by your package manager, alongside lmo.

Package Minimum version
Python 3.10
NumPy 1.22
SciPy 1.9

Optional dependencies

Package Minimum version Notes
Pandas 1.4 Lmo extends pd.Series and pd.DataFrame with convenient methods, e.g. df.l_scale(trim=1). Install as pip install lmo[pandas] to ensure compatibility.

Foundational Literature

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lmo-0.12.0.tar.gz (91.0 kB view details)

Uploaded Source

Built Distribution

lmo-0.12.0-py3-none-any.whl (97.3 kB view details)

Uploaded Python 3

File details

Details for the file lmo-0.12.0.tar.gz.

File metadata

  • Download URL: lmo-0.12.0.tar.gz
  • Upload date:
  • Size: 91.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/6.6.6-76060606-generic

File hashes

Hashes for lmo-0.12.0.tar.gz
Algorithm Hash digest
SHA256 56c72a8ff9f4caccc715301e90f329d01ea76065fbe1210ad4ade299125d5d33
MD5 3531ea05a6d82e79937c54608554b2d1
BLAKE2b-256 ebf2484d05b38c2e40fcb880b5ac57ceaf8b59e98cac6fce9a8a78755924747d

See more details on using hashes here.

File details

Details for the file lmo-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: lmo-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 97.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/6.6.6-76060606-generic

File hashes

Hashes for lmo-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f87234fb70d58c47875064d6f3f2c90b7584ae560c94c4ac79ec23f213d21d80
MD5 8bf5c8b22ea232c6b06fd97406d49572
BLAKE2b-256 38c5db2a8e665f88696178fe13899272062af85961c9089cd3063d3160add249

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page