Yes! The formula for weighted mean in the documentation is wrong - but the result is correct.
More clearly:
In[70]:= nbpoints = 10;
d = RandomReal[{-1, 1}, nbpoints];
w = Table[1, nbpoints];
Proba = w/Total@w; (* Probability*)
UsualMean = Mean@d
WeightedMean =
Mean[WeightedData[d,
Proba]] (*Correct, but different from the documentation of Mean!*)
DocMean = (1/nbpoints) Total[
Proba d](*According to the documentation of Mean for WeightedData *)
Out[74]= -0.268511
Out[75]= -0.268511
Out[76]= -0.0268511
docMean is wrong.
As for the variance, compute :
WeightedVar =
Variance[
WeightedData[d,
Proba]] (* Problematic definition in the documentation, \
for WeightedData*)
Good = Total[Proba (d - WeightedMean)^2]
DocVar = (1/(nbpoints - 1)) Total[
Proba (d -
Mean@d)^2](*According to the documentation of Mean for Weighted\
Data *)
WeightedVar =Good, which is correct, I think ; but DocVar is wrong too, and the problem lies in the documentation, not in the computations - a lesser evil !