R/weighted_var.R

Defines functions weighted_var

Documented in weighted_var

## File Name: weighted_var.R
## File Version: 9.12


# weighted variance
# This function is a wrapper to cov.wt
weighted_var <- function( x, w=rep(1,length(x) ), method="unbiased",
    select=NULL )
{
    res <- tam_weighted_stats_select(x=x, w=w, select=select)
    x <- res$x
    w <- res$w
    dat <- data.frame("x"=x )
    res <- stats::cov.wt( x=dat, wt=w, cor=FALSE, center=TRUE, method=method )
    res <- res$cov[1,1]
    return(res)
}

Try the TAM package in your browser

Any scripts or data that you put into this service are public.

TAM documentation built on Aug. 29, 2022, 1:05 a.m.