In the Chapter 3 of Think Stats by Allen Downey book. The following is the excerpt from the book:

First, I compute the distribution as observed by students, where the probability associated with each class size is “biased” by the number of students in the class.

def BiasPmf(pmf, label):
  new_pmf = pmf.Copy(label=label)

  for x, p in pmf.Items():
    new_pmf.Mult(x, x)

  return new_pmf

For each class size, x, we multiply the probability by x, the number of students who observe that class size. The result is a new Pmf that represents the biased distribution.

  1. What is the meaning of the bias here?
  2. Is the author skewing the value by a certain factor and thus, creating an artificial "bias"?

If there's a better forum to discuss questions regarding the book material - please let us know.


This exercise is illustrating that the 'average class size' as calculated by the Dean is not the same as the average class size as experienced by a student. The difference can be viewed this way: the Dean's average is the expected class size when picking a class at random, while the student's average is the expected class size when picking a student at random and asking the size of that student's class. To create a student-centric distribution of class sizes, you need to replicate each class size x as many times as the number of students in the class (again, x). In other words:

for x, p in pmf.Items():
    new_pmf.Mult(x, x)

This is the sense in which we are 'biasing' class sizes: to give a student's-eye view of the class distribution. It's a legitimate approach, not anything artificial. Both versions of the average class size are correctly calculated; the difference is in the sampling scheme.

(Note this exercise is a little muddled: what if a student takes more than one class? The code for creating the biased distribution is making the simplifying assumption that each student takes just one class.)

  • $\begingroup$ Thank you. I am having a hard time internalizing this though. Why is there a multiplication happening? $\endgroup$
    – neowulf33
    Sep 18 '17 at 19:16
  • 3
    $\begingroup$ @neowulf33 Example: if a college had just two classes, one with 2 students and one with 3 students, the Dean's data set would be {2, 3}, one value per class. But in the student's view the data set would be {2, 2, 3, 3, 3}, one value per student, i.e., 2 is replicated twice, 3 is replicated thrice. Say the Dean's pmf is p(x). The software achieves replication by replacing each p(x) by x * p(x), and then renormalizes the result. [ Recall Mult(x, c) means 'multiply the probability for value x by the factor c'.] There are other ways to compute the student pmf, e.g. just create a new data set. $\endgroup$
    – grand_chat
    Sep 18 '17 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.