Proportional Trimmed Mean

Computes a proportional trimmed mean that resolves the integer truncation problem of base R's mean(..., trim). When k = trim * n is non-integer, a fractional discount (1 - delta) is applied to boundary observations, where delta = k - floor(k). The resulting estimator is continuous in alpha for any fixed n, syntactically identical to mean(..., trim), and compatible with the 'Statgraphics' implementation. The package also provides standard errors, confidence intervals and Yuen-type one-sample, paired and two-sample t tests for trimmed means (following Yuen (1974) ), a robust effect size, a truncation diagnostic, and descriptive statistics (winsorized mean and sigma, quantiles following Hyndman and Fan (1996) , biweight scale, skewness, kurtosis). See Gaviria Chaverra (2026) .


sgmean

sgmean computes the trimmed mean using a proportional discount method on the extremes, replicating the behavior of Statgraphics software.

Unlike R’s built-in mean(..., trim), which removes boundary values entirely, sgmean applies a weighted reduction — producing results consistent with Statgraphics.

sgmean is an independent project and is not affiliated with or endorsed by Statgraphics.

Installation

The version on CRAN is 0.1.2 (the function sgmean() only). The development version on GitHub is 0.2.0 and adds inference, diagnostics and descriptive statistics (see below); it will reach CRAN later.

# CRAN version (0.1.2)
install.packages("sgmean")

# Development version (0.2.0)
# install.packages("remotes")
remotes::install_github("jcarlosgaviria/sgmean")

Usage

library(sgmean)

x <- c(2, 4, 6, 8, 100)

# sgmean method (Statgraphics compatible)
sgmean(x, trim = 0.05)

# Base R method (different result)
mean(x, trim = 0.05)

New in 0.2.0 (GitHub version)

x <- c(850, 920, 980, 1050, 1120, 1180, 1250, 1320, 1400, 1480, 1550,
       1700, 1850, 2100, 8500)

# Proportional trimmed mean vs. base R
sgmean(x, trim = 0.10)          # 1365.833
mean(x, trim = 0.10)            # 1376.923 (R truncates k = 1.5 to 1)
diagnose_truncation(x, trim = 0.10)
plot_trim_profile(x)

# Inference for the trimmed mean (Yuen-type tests return 'htest' objects)
y <- c(900, 1010, 1100, 1190, 1250, 1330, 1420, 1500, 1610, 1720, 1830,
       1950, 2100, 2300, 2600)   # a second sample
ttest_trimmed(x, mu0 = 1300, trim = 0.10)
ci_trimmed(x, trim = 0.10)
se_trimmed(x, trim = 0.10)
ttest_rel_trimmed(x, y, trim = 0.10)     # paired samples
ttest_ind_trimmed(x, y, trim = 0.10)     # two samples; also gives effect_size
effect_size_trimmed(x, y, trim = 0.10)   # robust standardized difference

# Statgraphics-style descriptive statistics (29 results; English or Spanish labels)
sg_summary(x, trim = 0.10)
print(sg_summary(x, trim = 0.10), lang = "es")
set_language("es")

Also available: winsorized_mean(), winsorized_sigma(), sg_quantile() (Hyndman-Fan types 1-9, default type 2), quartiles(), iqr(), geometric_mean(), dam(), sbi(), skewness(), kurtosis(), cv(), std_error() and sg_mode(). Three functions carry the prefix sg_ (sg_quantile, sg_mode, sg_summary) so that they do not mask stats::quantile, base::mode and summary.

The standard error and the test for fractional k = trim * n interpolate between the classical estimators for floor(k) and floor(k) + 1 values per tail. They coincide with the classical Tukey-McLaughlin / Yuen results when k is an integer; for fractional k they are a heuristic supported by simulation, not a proven result. See NEWS.md for details.

Python

The same methods are available in Python: sgmean on PyPI and sgmean-python on GitHub. The two packages share reference values in their test suites.

Author

Juan Carlos Gaviria Chaverra

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("sgmean")

0.2.0 by Juan C. Gaviria-Chaverra, 4 days ago


https://github.com/jcarlosgaviria/sgmean


Report a bug at https://github.com/jcarlosgaviria/sgmean/issues


Browse source code at https://github.com/cran/sgmean


Authors: Juan C. Gaviria-Chaverra [aut, cre] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports graphics, stats

Suggests knitr, rmarkdown, testthat


See at CRAN