View source: R/weighted_stats.R
weighted_moments | R Documentation |
Compute weighted moments
weighted_moments(x, w, n = 2L, center = TRUE)
x |
Observations |
w |
Case weights (optional) |
n |
Number of moments to calculate |
center |
Calculate centralized moments (default) or noncentralized moments, i.e. E((X - E(X))^k) or E(X^k). |
A vector of length n
where the k
th entry is the k
th weighted
moment of x
with weights w
. If center
is TRUE
the moments are
centralized, i.e. E((X - E(X))^k). The first moment is never centralized.
The moments are scaled with 1 / sum(w), so they are not de-biased.
e.g. the second central weighted moment
weighted_moment(x, w)[2L]
is equal to
var(rep(x, w)) * (sum(w) - 1) / sum(w)
for integer w
Other weighted statistics:
weighted_quantile()
,
weighted_tabulate()
weighted_moments(rexp(100))
weighted_moments(c(1, 2, 3), c(1, 2, 3))
c(mean(rep(1:3, 1:3)), var(rep(1:3, 1:3)) * 5 / 6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.