Description Usage Arguments Details Value Author(s) Examples
Compute the weighted mean and variance of a vector of numeric values. If no weights are supplied, defaults to computing the unweighted mean and the unweighted maximum-likelihood variance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
x |
Vector of values to be analyzed. |
wt |
Weights associated with the values in x. |
unbiased |
Logical scalar determining whether variance should be unbiased (TRUE) or maximum-likelihood (FALSE). |
df_type |
Character scalar determining whether the degrees of freedom for unbiased estimates should be based on numbers of cases ("count"; default) or sums of weights ("sum_wts"). |
The weighted mean is computed as
sum(x * wt) / sum(wt)
where x is a numeric vector and w is a vector of weights.
The weighted variance is computed as
var(x) = sum((x - sum(x * wt) / sum(wt))^2 * wt) / sum(wt)
and the unbiased weighted variance is estimated by multiplying var(x) by k/(k-1).
A weighted mean and variance if weights are supplied or an unweighted mean and variance if weights are not supplied.
Jeffrey A. Dahlke
1 2 3 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.