user
The   *wisdom of the crowd*   is the collective opinion of a group of individuals rather than that of a single expert.

Wisdom-of-the-crowds research routinely attributes the superiority of crowd averages over individual judgments to the elimination of individual noise,   an explanation that assumes independence of the individual judgments from each other.

Thus the crowd tends to make its best decisions if it is made up of diverse opinions and ideologies.

Scott E. Page introduced the diversity prediction theorem:

:   *The squared error of the collective prediction equals the average squared error minus the predictive diversity*.

Therefore,   when the diversity in a group is large,   the error of the crowd is small.

Definitions
:   :   * Average Individual Error:   Average of the individual squared errors
        * Collective Error:   Squared error of the collective prediction
        * Prediction Diversity:   Average squared distance from the individual predictions to the collective prediction
        * Diversity Prediction Theorem:   *Given a crowd of predictive models*,     then

        :   :   :   :   Collective Error   =   Average Individual Error   ─   Prediction Diversity

Task

For a given   true   value and a number of number of estimates (from a crowd),   show   (here on this page):

:   :   :   * the true value   and   the crowd estimates
            * the average error
            * the crowd error
            * the prediction diversity

Use   (at least)   these two examples:

:   :   :   * a true value of   **49**   with crowd estimates of:    **48   47   51**
            * a true value of   **49**   with crowd estimates of:    **48   47   51   42**

Also see
:   * Wikipedia entry:   Wisdom of the crowd
    * University of Michigan: PDF paper         (exists on a web archive,   the *Wayback Machine*).
assistant
(formerly Perl 6)

```
sub diversity-calc($truth, @pred) {
    my $ae = avg-error($truth, @pred); # average individual error
    my $cp = ([+] @pred)/+@pred;       # collective prediction
    my $ce = ($cp - $truth)**2;        # collective error
    my $pd = avg-error($cp, @pred);    # prediction diversity
    return $ae, $ce, $pd;
}

sub avg-error ($m, @v) { ([+] (@v X- $m) X**2) / +@v }

sub diversity-format (@stats) {
    gather {
        for <average-error crowd-error diversity> Z @stats -> ($label,$value) {
            take $label.fmt("%13s") ~ ':' ~ $value.fmt("%7.3f");
        }
    }
}

.say for diversity-format diversity-calc(49, <48 47 51>);
.say for diversity-format diversity-calc(49, <48 47 51 42>);

```

Output:

```
average-error:  3.000
  crowd-error:  0.111
    diversity:  2.889
average-error: 14.500
  crowd-error:  4.000
    diversity: 10.500

```