Message Boards Message Boards

0
|
157 Views
|
6 Replies
|
4 Total Likes
View groups...
Share
Share this post:

WeightedData variances are wrong in Mathematica

Posted 18 hours ago

Variances of WeightedData are wrong in Mathematica. Mathematica lacks of quality testing.

Moreover, Mean and Variance of WeightedData are wrong in the documentation.

https://reference.wolfram.com/language/ref/Mean.html

https://reference.wolfram.com/language/ref/Variance.html

enter image description here

POSTED BY: Paolo Zavarise
6 Replies

Variance of WeightedData gives the population variance, while Variance on a set of raw observations gives the unbiased sample variance.

POSTED BY: David Trimas
Posted 13 hours ago

Does this make sense? I don't think so.

The rule is: equal weights = without weights.

POSTED BY: Paolo Zavarise

I also think there is a problem with WeightedData and the documentation... With the same data generation:

Mean@d
Mean[WeightedData[d, 
  w]] (*Correct, but different from the documentation of Mean!*)
Mean[d w]/Total[w] (*From the documentation of Mean for WeightedData *)

As fo the variance, the problem seems linked with unbiasedness :

Variance@d  (*unbiased*)
Mean[(d - Mean@d)^2] (nbpoints/(nbpoints - 1))(*unbiased*)
Variance[
 WeightedData[d, 
  w]]  (*  Problematic definition in the documentation, \
for  WeightedData*)
Mean[(d - Mean@d)^2]  (* biased *)
POSTED BY: Claude Mante

To add to David's point, data will be treated as population data if wrapped in EmpiricalDistribution[]:

Variance[EmpiricalDistribution@data]
POSTED BY: Michael Rogers
Posted 6 hours ago

It's good that you pointed this out and it would be helpful if the specific documentation errors were described. For example the documentation for Mean with weighted data shows

Weighted mean definition in the documentation

The $\frac{1}{n}$ should not be in that definition.

POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract