weighted.var: Weighted univariate variance coping with missing values

Description Usage Arguments Details Value Author(s) See Also Examples

Description

This function is analogue to weighted.mean.

Usage

1
weighted.var(x, w, na.rm = FALSE)

Arguments

x

a vector with data

w

positive weights (may not have missings where x is observed)

na.rm

if TRUE remove missing values

Details

The weights w are standardised such that ∑_{observed} w_i equals the number of observed values in x. The function calculates

∑_{observed} w_i (x_i-weighted.mean(x,w,na.rm=T))^2/((∑_{observed} w_i)-1).

Value

The weighted variance of x with weights w (with missing values removed when na.rm=TRUE).

Author(s)

Beat Hulliger

See Also

See Also as weighted.mean

Examples

1
2
3
4
x<-rnorm(100)
x[sample(1:100,20)]<-NA
w<-rchisq(100,2)
weighted.var(x,w,na.rm=TRUE)


Search within the modi package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.