| Title: | Weighted Descriptive Statistics |
|---|---|
| Description: | Weighted versions of common descriptive statistics (variance, standard deviation, covariance, correlation, quantiles). |
| Authors: | Johann D. Gaebler [aut, cre] |
| Maintainer: | Johann D. Gaebler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-11 09:19:48 UTC |
| Source: | https://github.com/cran/wstats |
Weighted correlation coefficient, computed as
weighted_cov(x, y, w) / (weighted_sd(x, w) * weighted_sd(y, w)).
weighted_cor(x, y, w, na.rm = FALSE)weighted_cor(x, y, w, na.rm = FALSE)
x |
A numeric vector of observations. |
y |
A numeric vector of observations (same length as |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
A single numeric value in [-1, 1].
Computes the population (importance-weight) weighted covariance
sum(w_hat * (x - mu_x) * (y - mu_y)).
weighted_cov(x, y, w, na.rm = FALSE)weighted_cov(x, y, w, na.rm = FALSE)
x |
A numeric vector of observations. |
y |
A numeric vector of observations (same length as |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
A single numeric value.
Computes the population weighted excess kurtosis:
sum(w_hat * ((x - mu) / sigma)^4) - 3.
weighted_kurtosis(x, w, na.rm = FALSE)weighted_kurtosis(x, w, na.rm = FALSE)
x |
A numeric vector of observations. |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
A single numeric value.
Computes the weighted MAD as the weighted median of |x - median(x, w)|,
scaled by constant (default 1.4826 for consistency with stats::mad()
under normality).
weighted_mad(x, w, na.rm = FALSE, constant = 1.4826)weighted_mad(x, w, na.rm = FALSE, constant = 1.4826)
x |
A numeric vector of observations. |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
constant |
Scale factor (default |
A single numeric value.
Convenience wrapper: weighted_quantile(x, w, 0.5, na.rm).
weighted_median(x, w, na.rm = FALSE)weighted_median(x, w, na.rm = FALSE)
x |
A numeric vector of observations. |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
A single numeric value.
Computes weighted quantiles using a type-7 analog: observations are placed
at the midpoints of their weight intervals in the cumulative weight
distribution, rescaled to [0, 1], and quantiles are obtained by linear
interpolation. For equal weights this matches quantile(x, type = 7).
weighted_quantile(x, w, probs = seq(0, 1, 0.25), na.rm = FALSE)weighted_quantile(x, w, probs = seq(0, 1, 0.25), na.rm = FALSE)
x |
A numeric vector of observations. |
w |
A numeric vector of non-negative weights (need not sum to 1). |
probs |
A numeric vector of probabilities in [0, 1]. |
na.rm |
Logical. If |
A numeric vector of the same length as probs.
Square root of weighted_var().
weighted_sd(x, w, na.rm = FALSE)weighted_sd(x, w, na.rm = FALSE)
x |
A numeric vector of observations. |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
A single numeric value.
Computes the population weighted skewness (Fisher's g1):
sum(w_hat * ((x - mu) / sigma)^3).
weighted_skewness(x, w, na.rm = FALSE)weighted_skewness(x, w, na.rm = FALSE)
x |
A numeric vector of observations. |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
A single numeric value.
Computes the population (importance-weight) weighted variance
sum(w_hat * (x - mu)^2) where w_hat = w / sum(w) and
mu = weighted.mean(x, w).
weighted_var(x, w, na.rm = FALSE)weighted_var(x, w, na.rm = FALSE)
x |
A numeric vector of observations. |
w |
A numeric vector of non-negative weights (need not sum to 1). |
na.rm |
Logical. If |
A single numeric value.