wtd_sd: Calculate weighted standard deviation

wtd_sdR Documentation

Calculate weighted standard deviation

Description

Calculated the weighted standard deviation using a vector of values and a vector of weights.

Usage

wtd_sd(x, w = NULL, sample = T, error = F)

Arguments

x

(num vector) A vector of values.

w

(num vector) A vector of weights.

sample

(log scalar) Whether this is a sample as opposed to a population (default true).

error

(lgl scalr) Whether to throw an error if there is no data at all or no pairwise complete cases. Default yes.

Examples

set.seed(1)
X = rnorm(100)
set.seed(1)
W = runif(100)
sd(X) #0.898
wtd_sd(X, W) #0.894, slightly different
wtd_sd(X) #0.898, not using weights

Deleetdk/kirkegaard documentation built on June 7, 2024, 7:49 a.m.