weighted.meanvar: Function to compute the weighted mean and weighted variance...

View source: R/weighted.meanvar.R

weighted.meanvarR Documentation

Function to compute the weighted mean and weighted variance of 'x'

Description

This function allows for computing the weighted mean and weighted variance of a vector of continuous values.

Usage

weighted.meanvar(x, w, na.rm = FALSE)

Arguments

x

an object containing the values whose weighted mean is to be computed.

w

a numerical vector of weights of the same length as x giving the weights to use for elements of x.

na.rm

TRUE if missing values should be removed, FALSE otherwise.

Details

If w is missing then all elements of x are given the same weight, otherwise the weights coerced to numeric by as.numeric. On the contrary of weighted.mean the weights are NOT normalized to sum to one. If the sum of the weights is zero or infinite, NAs will be returned.

Value

A numeric vector of two values that are the weighted mean and weighted variance respectively.

References

http://en.wikipedia.org/wiki/Weighted_variance#Weighted_sample_variance

See Also

stats::weighted.mean

Examples

set.seed(54321)
weighted.meanvar(x=rnorm(100) + 10, w=runif(100))


bhklab/genefu documentation built on Nov. 30, 2024, 9:03 p.m.