Package {sgmean}


Type: Package
Title: Proportional Trimmed Mean
Version: 0.1.1
Date: 2026-07-27
Description: 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. See Gaviria Chaverra (2026) <doi:10.32614/CRAN.package.sgmean>.
License: MIT + file LICENSE
Encoding: UTF-8
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
URL: https://github.com/jcarlosgaviria/sgmean
BugReports: https://github.com/jcarlosgaviria/sgmean/issues
Config/roxygen2/version: 8.0.0
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2026-07-29 17:23:13 UTC; Personal
Author: Juan C. Gaviria-Chaverra ORCID iD [aut, cre]
Maintainer: Juan C. Gaviria-Chaverra <jcarlos.gaviria@udea.edu.co>
Repository: CRAN
Date/Publication: 2026-07-29 22:20:09 UTC

Proportional Trimmed Mean

Description

Computes a proportional trimmed mean that resolves the integer truncation problem of base R's mean(..., trim). When k = \text{trim} \times n is non-integer, a fractional discount (1 - \delta) is applied to boundary observations, where \delta = k - \lfloor k \rfloor.

Usage

sgmean(x, trim = 0.05, na.rm = FALSE)

Arguments

x

A numeric vector.

trim

Fraction of observations to trim symmetrically from each end of the sorted data. Must be in [0, 0.5).

na.rm

Logical. Should missing values be removed before computation? Default is FALSE.

Details

The proportional trimmed mean generalizes mean(..., trim) by treating k = \text{trim} \times n as a continuous parameter. Three cases are handled:

k = 0

Returns the arithmetic mean.

0 < k < 1 (Type A)

Applies a discount (1-k) to X_{(1)} and X_{(n)}.

k exact integer

Reduces to mean(..., trim), producing identical results to R base.

k > 1, non-integer (Type B)

Eliminates \lfloor k \rfloor observations from each tail and applies a fractional discount (1-\delta) to the new boundary observations, where \delta = k - \lfloor k \rfloor.

Value

A single numeric scalar.

References

Gaviria Chaverra, J. C. (2026). sgmean: A Proportional Trimmed Mean for R Compatible with Statgraphics. The R Journal.

Examples

# Type A distortion: k = 0.05 * 15 = 0.75
x <- c(850, 920, 980, 1050, 1120, 1180, 1250,
       1320, 1400, 1480, 1550, 1700, 1850, 2100, 8500)
mean(x, trim = 0.05)    # 1816.667 — no trimming applied (k* = 0)
sgmean(x, trim = 0.05)  # 1499.074 — proportional discount applied

# Type B distortion: k = 0.10 * 15 = 1.50
mean(x, trim = 0.10)    # 1376.923 — effective trim 6.7%
sgmean(x, trim = 0.10)  # 1365.833 — effective trim 10% (Statgraphics)

# Control: k = 1/15 * 15 = 1 (exact integer)
mean(x, trim = 1/15)    # identical to sgmean
sgmean(x, trim = 1/15)  # identical to mean(..., trim)