1
$\begingroup$

Currently I'm reading Eloquent Javascript book and at chapter 4. This topic entitled 'The lycanthrope’s log ' is very confusing to me. How important is correlation and coefficient in real world programming?

I'm trying to understand the formula used to find correlation. I've far forgotten maths since I left my high school. Could, someone who've read this book, explain to me in detail, please? Below is the picture I'm wondering about..

enter image description here

$\endgroup$
  • 1
    $\begingroup$ When you say "correlation and coefficient", you appear to be talking about two things -- what coefficient do you mean, besides the correlation? $\endgroup$ – Glen_b -Reinstate Monica Jun 10 '16 at 7:29
3
$\begingroup$

The formula is actually pretty straight forward. Consider the table from your question.

The table states that there were a total 90 observations

Out of all 90 observations:

  1. 76 times, no pizzas or squirrel
  2. 9 times, pizzas but no squirrel
  3. 4 times, squirrel but no pizzas
  4. 1 time, both squirrel and pizza

So we want to find out how Pizzas & Squirrels are related:


Consider the equation along with your table now,

(since squirrel is on the left)

n00 denotes an observation where there was no squirrel or pizza (1)

n01 denotes an observation where there was no squirrel but pizza (2)

n10 denotes an observation where there was squirrel but no pizza (3)

n11 denotes an observation where there was both squirrel but pizza (4)


n0. refers to the sum of all measurements where we have no squirrel

n.0 refers to the sum of all measurements where we have no pizza

n1. refers to the sum of all measurements where we have squirrel

n.1 refers to the sum of all measurements where we have pizza


Now that we know what these values are, let's plug them in to our formula:

$$ \mathit{correlation} = \rho = \frac{ 1 \times 76 - 4 \times 9}{\sqrt{5 \times 85 \times 10 \times 80}}$$

$\endgroup$
  • $\begingroup$ Well, tbh I had to research the thing first :P $\endgroup$ – atefth Jun 10 '16 at 7:13
  • 1
    $\begingroup$ It might be worth noting that if you code the binary variables for "no-squirrel/squirrel" and "no-pizza/pizza" as (0,1) (or indeed any other two distinct values where the "no" part is either lower for both or higher for both) then this is actually the same as the ordinary correlation coefficient. $\endgroup$ – Glen_b -Reinstate Monica Jun 10 '16 at 7:43

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.