I know this is an old one but I keep encountring the same question over and over. Apparently, there is no consensus as to the definition of the standard error of the weighted mean. Even different statistical softwares use different definitions. However, the most coherent answer that I keep seeing is this for an unbiased estimation of the standard error on a weighted mean:
$$
se= \frac{\sigma_w}{\sqrt{\sum_i^n w_i}}
$$
where the $\sigma_w$ is the unbiased estimator of the standard deviation of your random variable $X$ and $\sum_i^n w_i$ is the sum of the individual weights that contribute to your unbiased estimation of $X$. The unbiased estimator of the standard deviation of your random variable with degres of freedom $=1$ is the following:
$$
\sigma_w = \sqrt{\frac{\sum_i^n w_i x_i}{\sum_i^n w_i - 1}}
$$
Here's a link to a note that compares how it is computed in SPSS vs WinCross.
Python's statsmodels
implemented a class that computes all sorts of weighted statistics including the standard deviation and standard error (method under the name std_mean
here in their source code. As we can see from their implementation, they use either a biased estimation of the standard error if the degres of freedom is equal to $0$ like so:
$$
se= \frac{\sigma_w}{\sqrt{\sum_i^n w_i-1}}
$$
or an unbiased estimator of the standard error (which is your case) if the degres of freedom parameter is given which activates a condition to apply a degres of freedom correction to the standard deviation first like so:
$$
\sigma_w \leftarrow \sigma_w \times \sqrt{\frac{\sum_i^n w_i- ddof}{\sum_i^n w_i}}
$$
For $ddof=1$ and if you plugin the new value of the corrected $\sigma_w$ in the biased estimation of the standard error, then you get the formula for the unbiased estimation of the standard error of the weighted mean $se = \sigma_w/\sqrt{\sum_i^n w_i}$
Here's how to numerically verify your estimators using manual definitions vs statsmodels
's implementation if you use python:
# make sure you install statsmodels using pip install statsmodels
import numpy as np
from statsmodels.stats.weightstats import DescrStatsW
# define the x measurements and their weights
x = np.array([10, 12, 15.2, 12.5, 11])
w = np.array([100, 120, 108, 80, 98])
# calculate the unbiased estimators of avg, std and se (with ddof=1)
sum_w = np.sum(w)
avg_w = np.sum(w * x) / sum_w
std_w = np.sqrt(np.sum(w*(x-avg_w)**2) / (sum_w-1))
se_w = std_w / np.sqrt(sum_w)
# calculate the weighted stats using scipy's formula (with ddof=1)
weighted_stats = DescrStatsW(x, weights=w, ddof=1)
print('manual weighted avg = %0.5f' %avg_w)
print('manual weighted std = %0.5f' %std_w)
print('manual weighted se = %0.5f' %se_w)
print('statsmodels weighted avg = %0.5f' %weighted_stats.mean)
print('statsmodels weighted std = %0.5f' %weighted_stats.std)
print('statsmodels weighted se = %0.5f' %weighted_stats.std_mean)
>>> OUTPUT:
manual weighted avg = 12.17312
manual weighted std = 1.78484
manual weighted se = 0.07935
statsmodels weighted avg = 12.17312
statsmodels weighted std = 1.78484
statsmodels weighted se = 0.07935
[self-study]
tag & read its wiki. $\endgroup$