sample variance
is defined similarly to the normal biased sample variance
:
where
, which is
for normalized weights. If the weights are frequency weights (and thus are random variables), it can be shown that
is the maximum likelihood estimator of
for iid Gaussian observations.
For small samples, it is customary to use an unbiased estimator for the population variance. In normal unweighted samples, the N in the denominator (corresponding to the sample size) is changed to N − 1 (see Bessel's correction). In the weighted setting, there are actually two different unbiased estimators, one for the case of frequency weights and another for the case of reliability weights.
Frequency weights
If the weights are frequency weights[definition needed], then the unbiased estimator is:

This effectively applies Bessel's correction for frequency weights.
For example, if values
are drawn from the same distribution, then we can treat this set as an unweighted sample, or we can treat it as the weighted sample
For example, if values
{
2
,
2
,
4
,
5
,
5
,
5
}
{\displaystyle \{2,2,4,5,5,5\}}
are drawn from the same distribution, then we can treat this set as an unweighted sample, or we can treat it as the weighted sample
{
2
,
4
,
5
}
{\displaystyle \{2,4,5\}}
with corresponding weights
{
2
,
1
,
3
}
{\displaystyle \{2,1,3\}}
, and we get the same result either way.
If the frequency weights
{
w
i
}
{\displaystyle \{w_{i}\}}
{
2
,
2
,
4
,
5
,
5
,
5
}
{\displaystyle \{2,2,4,5,5,5\}}
are drawn from the same distribution, then we can treat this set as an unweighted sample, or we can treat it as the weighted sample
{
2
,
4
,
5
}
{\displaystyle \{2,4,5\}}
with corresponding weights
{
2
,
1
,
3
}
{\displaystyle \{2,1,3\}}
, and we get the same result either way.
If the frequency weights
{
w
i
}
{\displaystyle \{w_{i}\}}
are normalized to 1, then the correct expression after Bessel's correction becomes
where the total number of samples is
V
1
{\displaystyle V_{1}}
(not
N
{\displaystyle N}
). In any case, the information on total number of samples is necessary in order to obtain an unbiased correction, even if
w
i
{\displaystyle w_{i}}
has a different meaning other than frequency weight.
Note that the estimator can be unbiased only if the weights are not standardized nor normalized, these processes changing the data's mean and variance and thus leading to a loss of the base rate (the population count, which is a requirement for Bessel's correction).
Reliability weights
If the weights are instead non-random (reliability weights[definition needed]), we can determine a correction factor to yield an unbiased estimator. Assuming each random variable is sampled from the same distribution with mean
μ
{\displaystyle \mu }
and actual variance
σ
actual
2
{\displaystyle \sigma _{\text{actual}}^{2}}
, taking expectations we have,
- standardized nor normalized, these processes changing the data's mean and variance and thus leading to a loss of the base rate (the population count, which is a requirement for Bessel's correction).
If the weights are instead non-random (reliability weights[definition needed]), we can determine a correction factor to yield an unbiased estimator. Assuming each random variable is sampled from the same distribution with mean
μ
{\displaystyle \mu }
and actual variance
σ
actual
2
{\displaystyle \sigma _{\text{actual}}^{2}}
, taking expectations we have,
-
V
2
=
∑
i
=
1
N
w
i
2
{\displaystyle V_{2}=\sum _{i=1}^{N}w_{i}^{2}}
. Therefore, the bias in our estimator is
(
1
−
V
2
V
1
2
)
{\displaystyle \left(1-{\frac {V_{2}}{V_{1}^{2}}}\right)}
, analogous to the
(
N
−
1
N
)
{\displaystyle \left({\frac {N-1}{N}}\right)}
bias in the unweighted estimator (also notice that
V
1
2
/
V
2
=
N
e
f
f
{\displaystyle \ V_{1}^{2}/V_{2}=N_{eff}}
is the effective sample size). This means that to unbias our estimator we need to pre-divide by
1
−
(
V
2
/
V
1
2
)
{\displaystyle 1-\left(V_{2}/V_{1}^{2}\right)}
, ensuring that the expected value of the estimated variance equals the actual variance of the sampling distribution.
The final unbiased estimate of sample variance is:
-
s
w
2
=
σ
^
w
2
1
−
(
V
2
/
V
1
2
)
=
∑
i
=
1
N
w
i
(
x
i
−
μ
∗
)
2
V
1
−
(
V
2
/
V
1
)
{\displaystyle {\begin{aligned}s_{\mathrm {w} }^{2}\ &={\frac {{\hat {\sigma }}_{\mathrm {w} }^{2}}{1-(V_{2}/V_{1}^{2})}}\\&={\frac {\sum \limits _{i=1}^{N}w_{i}(x_{i}-\mu ^{*})^{2}}{V_{1}-(V_{2}/V_{1})}}\end{aligned}}}
,[2]
where
E
[
s
w
2
]
=
σ
actual
2
{\displaystyle \operatorname {E} [s_{\mathrm {w} }^{2}]=\sigma _{\text{actual}}^{2}}
.
The degrees of freedom of the weighted, unbiased sample variance vary accordingly from N − 1 down to 0.
The standard deviation is simply the square root of the variance above.
As a side note, other approaches have been described to compute the weighted sample variance.[3]
Weighted sample covariance
In a weighted sample, each row vector
x
i
{\displaystyle \textstyle {\textbf {x}}_{i}}
(each set of single observations on each of the K random variables) is assigned a weight
w
i
≥
0
{\displaystyle \textstyle w_{i}\geq 0}
.
Then the weighted mean vector
μ
∗
{\displaystyle \textstyle \mathbf {\mu ^{*}} }
is given by
-
μ
∗
=
∑
i
=
1
N
w
i
x
i
∑
i
=
1
N
w
i
<
The final unbiased estimate of sample variance is:
where
E
[
s
w
2
]
=
σ
actual
2
{\displaystyle \operatorname {E} [s_{\mathrm {w} }^{2}]=\sigma _{\text{actual}}^{2}}
.
The degrees of freedom of the weighted, unbiased sample variance vary accordingly from N − 1 down to 0.
The standard deviation is simply the square root of the variance above.
As a side note, other approaches have been described to compute the weighted sample variance.[3]
Weighted sample covariance
In a weighted sample, each row vector
x
i
{\displaystyle \textstyle {\textbf {x}}_{i}}
(each set of single observations on each of the K random variables) is assigned a weight
w
i
≥
0
{\displaystyle \textstyle w_{i}\geq 0}
.
Then the weighted mean vector
μ
∗
{\displaystyle \textstyle \mathbf {\mu ^{*}} }
is given by
-
μ
∗
=
∑
i
=
1
N
w
i
x
i
∑
i
=
1
N
w
i
.
{\displaystyle \mathbf {\mu ^{*}} ={\frac {\sum _{i=1}^{N}w_{i}\mathbf {x} _{i}}{\sum _{i=1}^{N}w_{i}}}.}
[3]
In a weighted sample, each row vector
x
i
{\displaystyle \textstyle {\textbf {x}}_{i}}
(each set of single observations on each of the K random variables) is assigned a weight
w
i
≥
0
{\displaystyle \textstyle w_{i}\geq 0}
.
Then the weighted mean vector
weighted mean vector
μ
∗
{\displaystyle \textstyle \mathbf {\mu ^{*}} }
is given by
And the weighted covariance matrix is given by:[4]
-
C
=
∑
i
=
1
N
w
i
(
x
i
−
μ
∗
)
Similarly to weighted sample variance, there are two different unbiased estimators depending on the type of the weights.
Frequency weights
If the weights are frequency weights, the unbiased weighted estimate of the covariance matrix
C
{\displaystyle \textstyle \mathbf {C} }
, with Bessel's correction, is given by:[4]
-
C
=
∑
i
=
1
N
w
i
(
x
i
−
μ
∗
)
T
(
x
i
If the weights are frequency weights, the unbiased weighted estimate of the covariance matrix
C
{\displaystyle \textstyle \mathbf {C} }
, with Bessel's correction, is given by:[4]
- standardized nor normalized, these processes changing the data's mean and variance and thus leading to a loss of the base rate (the population count, which is a requirement for Bessel's correction).
Reliability weights
In the case of reliability weights, the weights are normalized:
-
V
1
=
∑
i
=
1
N
w
i
=
1.
{\displaystyle V_{1}=\sum _{i=1}^{N}w_{i}=1.}

(If they are not, divide the weights by their sum to normalize prior to calculating
V
1
{\displaystyle V_{1}}
:
-
w
i
′
=
w
i
∑
i
=
1
N
w
i
{\displaystyle w_{i}'={\frac {w_{i}}{\sum _{i=1}^{N}w_{i}}}}

Then the weighted mean vector In the case of reliability weights, the weights are normalized:
-
(If they are not, divide the weights by their sum to normalize prior to calculating
V
1
{\displaystyle V_{1}}
:
-
w
i
′
=
w
i
∑
i
=
1
N
w
i
weighted mean vector
μ
∗
{\displaystyle \textstyle \mathbf {\mu ^{*}} }
can be simplified to
-
μ
∗
=
∑
i
=
1
N
w
i
x
i
.
{\displaystyle \mathbf {\mu ^{*}} =\sum _{i=1}^{N}w_{i}\mathbf {x} _{i}.}

and the unbiased weighted estimate of the
and the unbiased weighted estimate of the covariance matrix
C
{\displaystyle \textstyle \mathbf {C} }
is:[5]
-
C
=
∑
i
=
1
N
w
The reasoning here is the same as in the previous section.
Since we are assuming the weights are normalized, then
V
1
=
1
{\displaystyle V_{1}=1}
and this reduces to:
-
C
=
∑
i
=
1
N
w
i
(
x
i
−
μ
∗
)
T
(
x
i
−
μ
∗
)
1
−
V
2
.
{\displaystyle \mathbf {C} ={\frac {\sum _{i=1}^{N}w_{i}\left(\mathbf {x} _{i}-\mu ^{*}\right)^{T}\left(\mathbf {x} _{i}-\mu ^{*}\right)}{1-V_{2}}}.}

If all weights are the same, i.e.
w
i
/
V
1
=
1
/
N
{\displaystyle \textstyle w_{i}/V_{1}=1/N}
, then the weighted mean and covariance reduce to the unweighted sample mean and covariance above.
Vector-valued estimates
The above generalizes easily to the case of taking the mean of vector-valued estimates. For example, estimates of position on a plane may have less certainty in one direction than another. As in the scalar case, the weighted mean of multiple estimates can provide a maximum likelihood estimate. We simply replace the variance
σ
2
{\displaystyle \sigma ^{2}}
by the covariance matrix
C
{\displaystyle \mathbf {C} }
and the arithmetic inverse by the matrix inverse (both denoted in the same way, via superscripts); the weight matrix then reads:[6]
-
W
i
=
C
i
−
1
.
{\displaystyle \mathbf {W} _{i}=\mathbf {C} _{i}^{-1}.}

The weighted mean in this case is:
-
x
¯
=
C
Since we are assuming the weights are normalized, then
V
1
=
1
{\displaystyle V_{1}=1}
and this reduces to:
If all weights are the same, i.e.
w
i
/
V
1
=
1
/
N
{\displaystyle \textstyle w_{i}/V_{1}=1/N}
, then the weighted mean and covariance reduce to the unweighted sample mean and covariance above.
Vector-valued estimates
The above generalizes easily to the case of taking the mean of vector-valued estimates. For example, estimates of position on a plane may have less certainty in one direction than another. As in the scalar case, the weighted mean of multiple estimates can provide a maximum likelihood estimate. We simply replace the variance
σ
2
{\displaystyle \sigma ^{2}}
by the covariance matrix
C
{\displaystyle \mathbf {C} }
and the arithmetic inverse by the matrix inverse (both denoted in the same way, via superscripts); the weight matrix then reads:[6]
-
W
i
=
C
i
−
1
The above generalizes easily to the case of taking the mean of vector-valued estimates. For example, estimates of position on a plane may have less certainty in one direction than another. As in the scalar case, the weighted mean of multiple estimates can provide a maximum likelihood estimate. We simply replace the variance
σ
2
{\displaystyle \sigma ^{2}}
by the covariance matrix
C
{\displaystyle \mathbf {C} }
and the arithmetic inverse by the matrix inverse (both denoted in the same way, via superscripts); the weight matrix then reads:[6]
-
The weighted mean in this case is: