weighted_moment: Weighted statistic

View source: R/utilities.R

weighted_momentR Documentation

Weighted statistic

Description

The weighted_moment is a wrapper around R's weighted_mean which raises the variable x to the power a before taking the weighted mean. weighted_var and weighted_std are based on weighted_moment.

Usage

weighted_moment(x, w, a = 1, ranked = x, na.rm = FALSE)

Arguments

x

the variable whose moment is to be estimated

w

the weights

a

the degree of the moment

na.rm

a logical indicating whether NA's should removed

probs

the probabilities of the quantiles

names

no idea what this does

Details

The weighted_quantile function yields a version of quantiles which does not quite reach the sophistication of that built into R. In particular, for a probability p this function yields the highest x for which cumsum(w)/sum(w) < p, rather than some interpolated value. weighted_median is weighted_quantile(x,w, p = .5)

Value

The desired statistic. Weighted quantile produces a vector with length(probs).

Author(s)

Markus Jantti markus.jantti@iki.fi

See Also

weighted_mean, cov.wt

Examples


x <- rexp(100)
w <- rpois(100,5)
weighted_median(x, w)
weighted_moment(x,w, 1)
weighted_mean(x,w, 1)
weighted_var(x,w)


mjantti/incdist documentation built on Aug. 23, 2023, 5:33 p.m.