R/mdmb_weighted_var.R

Defines functions mdmb_weighted_var

## File Name: mdmb_weighted_var.R
## File Version: 0.07

mdmb_weighted_var <- function(x, w=rep(1,length(x)), unbiased=TRUE, na.rm=TRUE)
{
    m <- stats::weighted.mean(x=x, w=w, na.rm=na.rm)
    e <- x - m
    v1 <- sum(w*e^2, na.rm=na.rm)
    v2 <- sum(w, na.rm=na.rm)
    if (unbiased){
        N <- sum( ! is.na(e) )
        v2 <- (N-1)/N*v2
    }
    v1 <- v1 / v2
    return(v1)
}
alexanderrobitzsch/mdmb documentation built on July 18, 2024, 11:14 p.m.