In a sample of 100 emails, a rule fires on 40 of them. Of the 50 emails that are spam, the rule fires on 30. The 50 non-spam emails give the other 10 firings. The critical value for 1 degree of freedom at 5% is 3.84. According to a chi-squared test of independence, are the rule and the spam label independent?

Probability and statistics, Hypothesis testing
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can build the expected table from marginals and compute the statistic and degrees of freedom for a contingency table.

Key idea

For an r×c table, Eij=(row i total)(column j total)N, χ2=∑ij(Oij−Eij)2Eij and df=(r−1)(c−1).

Steps

  1. Write the observed table. Rows: spam, not spam. Columns: fires, does not fire. Spam: 30 and 20. Not spam: 10 and 40.
  2. Row totals are 50 and 50. Column totals are 40 and 60. N=100.
  3. Expected counts: E11=50×40/100=20, E12=30, E21=20, E22=30.
  4. Terms: (30−20)2/20=5, (20−30)2/30=3.33, (10−20)2/20=5, (40−30)2/30=3.33.
  5. Sum: χ2=16.67. Degrees of freedom: (2−1)(2−1)=1.
  6. Since 16.67>3.84 (the p-value is about 4×10−5), reject independence. The rule is strongly associated with the spam label.

Common mistakes

How long your answer should be

Half a page, 4 minutes.

Read this

Previous in Probability and statistics: A die is rolled 60 times and faces 1 to 6 appear 5,8,9,8,10,20 times. The critical value for 5 degrees of freedom is 11.07. Is the die fair according to a chi-squared goodness-of-fit test at the 5% level?
Next in Probability and statistics: Model A and model B are compared on the same 5 cross-validation folds. A's accuracy minus B's accuracy, in percentage points, is 2,1,3,0,4. Run a paired t-test of "no difference" at 5% (the two-sided critical value for 4 degrees of freedom is 2.776). Why should you be careful with this test?