sgmean for Python
Proportional trimmed mean compatible with Statgraphics.
Resolves the integer truncation problem of scipy.stats.trim_mean.
Installation
pip install sgmean
The problem
scipy.stats.trim_mean computes the trimmed mean via integer
truncation: it calculates k = proportiontocut * n and silently
reduces it to the nearest integer below. This generates two types
of silent distortion:
- Type A (k < 1): returns the arithmetic mean without any trimming
- Type B (k > 1, non-integer): trims fewer observations than requested
The solution
sgmean applies a fractional discount (1 - delta) to boundary
observations, where delta = k - floor(k):
from sgmean import sgmean
import numpy as np
x = np.array([850, 920, 980, 1050, 1120, 1180, 1250,
1320, 1400, 1480, 1550, 1700, 1850, 2100, 8500])
# Type A distortion (k = 0.05 * 15 = 0.75)
from scipy import stats
stats.trim_mean(x, 0.05) # 1816.667 — no trimming applied
sgmean(x, trim=0.05) # 1499.074 — correct proportional discount
# Type B distortion (k = 0.10 * 15 = 1.50)
stats.trim_mean(x, 0.10) # 1376.923 — 33% trimming loss
sgmean(x, trim=0.10) # 1365.833 — matches Statgraphics exactly
Reference
Gaviria-Chaverra, J.C. (2026). sgmean: A Proportional Trimmed Mean for R Compatible with Statgraphics. The R Journal. DOI: 10.32614/CRAN.package.sgmean
License
MIT
Metadata
Release files for sgmean 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sgmean-0.1.0.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sgmean-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / sgmean-0.1.0.tar.gz
| Download URL | sgmean-0.1.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec56ea950d4194574221b881aa59e02b5e84057f68ff13f18c89a66ef3705e88
|
|
BLAKE2b-256 checksum How to use checksums |
261db2ef6b64f78d982d614406b5d8747eb1df5a1f82c2c8835840b67e30bf9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / sgmean-0.1.0-py3-none-any.whl
| Download URL | sgmean-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ba3cc8f0614f555f3abc9df887a865c87b910ef7845d2666c8dc7a98eeaa3da
|
|
BLAKE2b-256 checksum How to use checksums |
29ea6bf0f3c8d538488af03beb9d1835f559a9c2f1cd453411b1a624da5b6e86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for sgmean 0.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.