Hi all,

What is the formula for the correction factor for a weighted variance?

Example:

```
using StatsBase
v = [1,2,3]
p = [.3,.5,.2]
std(v, ProbabilityWeights(p); corrected=true)
```

Thanks!

Hi all,

What is the formula for the correction factor for a weighted variance?

Example:

```
using StatsBase
v = [1,2,3]
p = [.3,.5,.2]
std(v, ProbabilityWeights(p); corrected=true)
```

Thanks!

It is still `n/(n-1)`

.

The reason for the correction is the constraint by the sample mean which ‘reduces’ a degree of freedom.

2 Likes

Thanks, and sorry for the noise. I must have made an error when initially checking to see if it was `n/(n-1)`

. When I looked into the issue more, it seemed like there was disagreement on how it should be calculated for unequal weights. The example below demonstrates the factor is `n/(n-1)`

.

Thanks again!

```
using StatsBase
n = 10
f = n /(n - 1)
v = rand(n)
p = v ./ sum(v)
varc = var(v, ProbabilityWeights(p); corrected=true)
varu = var(v, ProbabilityWeights(p); corrected=false)
varc / varu
```