Skip to main content

Fast Grubbs' test implementation with C++ bindings.

Project description

Stat Grubb

High speed Grubbs Test used to calculate the the z-score data points in a data set. I created this to learn about c++ and python integration and to have an fast alternate to the major python libaries. You can view the package on pypi here.

How the Algorithm Works

run_Grubbs — Grubbs Test with Outlier Removal

This is an iterative algorithm that progressively removes outliers from the dataset before computing z-scores.

run_NoOutlier — Standard Z-Score (No Outlier Removal)

A single-pass calculation with no iterative removal:

  1. Compute mean and standard deviation across the entire dataset.
  2. Compute z = (x − mean) / sd for every data point.

Because no points are removed, outliers pull the mean and standard deviation toward themselves, which compresses z-scores across the rest of the dataset.


Implementation Specifics

  • The dataset is assumed to follow a normal distribution.
  • The Grubbs test is designed for detecting one outlier per iteration; the loop repeats to handle multiple outliers.
  • Mean and standard deviation are computed with Welford's algorithm to avoid floating-point cancellation errors.

Performance

Benchmarked against an equivalent pure-Python/NumPy/SciPy implementation:

Dataset run_Grubbs speedup run_NoOutlier speedup
1k 43× 1.3×
10k 1.2×
100k 2.5× 1.3×

The large gains in run_Grubbs come from O(1) outlier removal (swap-to-end) and incremental mean/variance updates (reverse Welford), avoiding repeated full-array passes.

Installing GrubbsTest

macOS only (Apple Silicon)

pip install grubbstest

Usage

import fastgrubbstest as g

Functions

  • run_Grubbs(data, alpha=0.05)
    • Calculates z-scores with iterative outlier removal from mean and standard deviation calculation
    • Outliers still receive a z-score, computed relative to the cleaned distribution
  • run_NoOutlier(data)
    • Calculates z-scores without removing outliers from mean and standard deviation

Inputs

  • run_Grubbs

    • data: data in dict format
    • alpha: significance level for Student's t-distribution (default 0.05)
  • run_NoOutlier

    • data: data in dict format

Input Format

  • A dictionary where each key is the ID and the value is the number
    {"ab": 85, "cd": 4, ...}
    

Output Format

  • A dictionary where each key is the ID and the value is a list of [original_value, z_score]
    {"ab": [85, 1.23], "cd": [4, -0.56], ...}
    

License

This project is licensed under the MIT License

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

grubbstest-2.0.0-cp313-cp313-macosx_11_0_arm64.whl (81.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

grubbstest-2.0.0-cp312-cp312-macosx_11_0_arm64.whl (81.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

grubbstest-2.0.0-cp311-cp311-macosx_11_0_arm64.whl (82.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

grubbstest-2.0.0-cp310-cp310-macosx_11_0_arm64.whl (82.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

grubbstest-2.0.0-cp39-cp39-macosx_11_0_arm64.whl (82.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file grubbstest-2.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grubbstest-2.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 278514736c429fe3b7b72e69a54e00a962962e3dec9d382ca28819425282aebe
MD5 cefdcdb54ae5d7ee410e5dc0e0de01c2
BLAKE2b-256 df07e76f0659774159efa1643fc30e707b979f5fdbdd698c2c4c276e3879ffd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for grubbstest-2.0.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on davidolejniczak/FastGrubbsTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grubbstest-2.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grubbstest-2.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42acd3c6d8ee9deb5cb947214811aa3ae3373c5979c131e4582f97cb8609e939
MD5 a6e16424c1945c05f6d2f458be479168
BLAKE2b-256 97e731416c01d4cebd3100fa89e4de6e0c1bbdee02b48a694d9b582aa823c40c

See more details on using hashes here.

Provenance

The following attestation bundles were made for grubbstest-2.0.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on davidolejniczak/FastGrubbsTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grubbstest-2.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grubbstest-2.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 533fc99d1acbc9cfa575d18f553be876e44041fe1ffde8578712eeec0b44b84d
MD5 c3173115863d6815900fb2e7ee395f35
BLAKE2b-256 6a1633f1373638488d6785f913fcacb11b5e298e58b86f56469b9f3ef5d1ef04

See more details on using hashes here.

Provenance

The following attestation bundles were made for grubbstest-2.0.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on davidolejniczak/FastGrubbsTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grubbstest-2.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grubbstest-2.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32d622e2e1ed4f2f1eacd5d1c19f8a2bee10882893e59c3bb0f00e3fad4b826f
MD5 020862e216802e5f66fef6ec8e775104
BLAKE2b-256 e0d3a099ed1579525cf801dfa7ffdd89caf3c40e610fb3f1ebfd05dce2ec694a

See more details on using hashes here.

Provenance

The following attestation bundles were made for grubbstest-2.0.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish.yml on davidolejniczak/FastGrubbsTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grubbstest-2.0.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grubbstest-2.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55f135b9f8575a3e9129d8f51c3fa6e704fa8071875cf38beb8152871af6db3c
MD5 6745efad46903b62891ac5127050b4a3
BLAKE2b-256 a9df9bb513425d55b7990abb5f9ca8ea6aaa2ede9479714e79cbea18f7b41335

See more details on using hashes here.

Provenance

The following attestation bundles were made for grubbstest-2.0.0-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: publish.yml on davidolejniczak/FastGrubbsTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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