Weighted mean minimizes squared deviations (source code)

= Weighted mean minimizes squared deviations
{title2=$\bar x_w=\operatorname*{arg\,min}_c\sum_iw_i(x_i-c)^2$}

For a finite list of <real numbers> $x_i$ and nonnegative weights of positive total $W$, the <weighted mean> uniquely minimizes the weighted <sum> of squared deviations
$$
S(c)=\sum_iw_i(x_i-c)^2.
$$
Expanding around $\bar x_w$ and using $\sum_iw_i(x_i-\bar x_w)=0$ gives
$$
\boxed{S(c)=S(\bar x_w)+W(c-\bar x_w)^2.}
$$
Every displacement from the <weighted mean> increases the objective. This is the simplest one-parameter <weighted least squares> problem: represent all entries by one common value.

For the weighted values $90$ and $60$ with weights $2$ and $8$,
$$
S(c)=2(90-c)^2+8(60-c)^2
=1440+10(c-66)^2.
$$
Thus $S(66)=1440$, while $S(75)=2250$. The minimum is defined by this squared-error criterion; a different loss can select a different summary, such as a <median> under unweighted absolute deviations.

\Image[/weighted-mean-squared-error.png]
{title=The weighted mean is the unique minimum of a squared-error objective}
{description=For $S(c)=2(90-c)^2+8(60-c)^2$, the minimum is at $c=66$. Moving to $75$ increases the objective by $10(75-66)^2=810$.}