Deflategate.html 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. ---
  2. redirect_from:
  3. - "/chapters/12/2/deflategate"
  4. interact_link: content/chapters/12/2/Deflategate.ipynb
  5. kernel_name: python3
  6. has_widgets: false
  7. title: |-
  8. Deflategate
  9. prev_page:
  10. url: /chapters/12/1/AB_Testing.html
  11. title: |-
  12. A/B Testing
  13. next_page:
  14. url: /chapters/12/3/Causality.html
  15. title: |-
  16. Causality
  17. comment: "***PROGRAMMATICALLY GENERATED, DO NOT EDIT. SEE ORIGINAL FILES IN /content***"
  18. ---
  19. <div class="jb_cell tag_remove_input">
  20. <div class="cell border-box-sizing code_cell rendered">
  21. </div>
  22. </div>
  23. <div class="jb_cell">
  24. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  25. <div class="text_cell_render border-box-sizing rendered_html">
  26. <h3 id="Deflategate">Deflategate<a class="anchor-link" href="#Deflategate"> </a></h3><p>On January 18, 2015, the Indianapolis Colts and the New England Patriots played the American Football Conference (AFC) championship game to determine which of those teams would play in the Super Bowl. After the game, there were allegations that the Patriots' footballs had not been inflated as much as the regulations required; they were softer. This could be an advantage, as softer balls might be easier to catch.</p>
  27. <p>For several weeks, the world of American football was consumed by accusations, denials, theories, and suspicions: the press labeled the topic Deflategate, after the Watergate political scandal of the 1970's. The National Football League (NFL) commissioned an independent analysis. In this example, we will perform our own analysis of the data.</p>
  28. <p>Pressure is often measured in pounds per square inch (psi). NFL rules stipulate that game balls must be inflated to have pressures in the range 12.5 psi and 13.5 psi. Each team plays with 12 balls. Teams have the responsibility of maintaining the pressure in their own footballs, but game officials inspect the balls. Before the start of the AFC game, all the Patriots' balls were at about 12.5 psi. Most of the Colts' balls were at about 13.0 psi. However, these pre-game data were not recorded.</p>
  29. <p>During the second quarter, the Colts intercepted a Patriots ball. On the sidelines, they measured the pressure of the ball and determined that it was below the 12.5 psi threshold. Promptly, they informed officials.</p>
  30. <p>At half-time, all the game balls were collected for inspection. Two officials, Clete Blakeman and Dyrol Prioleau, measured the pressure in each of the balls.</p>
  31. <p>Here are the data. Each row corresponds to one football. Pressure is measured in psi. The Patriots ball that had been intercepted by the Colts was not inspected at half-time. Nor were most of the Colts' balls – the officials simply ran out of time and had to relinquish the balls for the start of second half play.</p>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. <div class="jb_cell">
  37. <div class="cell border-box-sizing code_cell rendered">
  38. <div class="input">
  39. <div class="inner_cell">
  40. <div class="input_area">
  41. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">football</span> <span class="o">=</span> <span class="n">Table</span><span class="o">.</span><span class="n">read_table</span><span class="p">(</span><span class="n">path_data</span> <span class="o">+</span> <span class="s1">&#39;deflategate.csv&#39;</span><span class="p">)</span>
  42. <span class="n">football</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
  43. </pre></div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="output_wrapper">
  48. <div class="output">
  49. <div class="jb_output_wrapper }}">
  50. <div class="output_area">
  51. <div class="output_html rendered_html output_subarea ">
  52. <table border="1" class="dataframe">
  53. <thead>
  54. <tr>
  55. <th>Team</th> <th>Blakeman</th> <th>Prioleau</th>
  56. </tr>
  57. </thead>
  58. <tbody>
  59. <tr>
  60. <td>Patriots</td> <td>11.5 </td> <td>11.8 </td>
  61. </tr>
  62. <tr>
  63. <td>Patriots</td> <td>10.85 </td> <td>11.2 </td>
  64. </tr>
  65. <tr>
  66. <td>Patriots</td> <td>11.15 </td> <td>11.5 </td>
  67. </tr>
  68. <tr>
  69. <td>Patriots</td> <td>10.7 </td> <td>11 </td>
  70. </tr>
  71. <tr>
  72. <td>Patriots</td> <td>11.1 </td> <td>11.45 </td>
  73. </tr>
  74. <tr>
  75. <td>Patriots</td> <td>11.6 </td> <td>11.95 </td>
  76. </tr>
  77. <tr>
  78. <td>Patriots</td> <td>11.85 </td> <td>12.3 </td>
  79. </tr>
  80. <tr>
  81. <td>Patriots</td> <td>11.1 </td> <td>11.55 </td>
  82. </tr>
  83. <tr>
  84. <td>Patriots</td> <td>10.95 </td> <td>11.35 </td>
  85. </tr>
  86. <tr>
  87. <td>Patriots</td> <td>10.5 </td> <td>10.9 </td>
  88. </tr>
  89. <tr>
  90. <td>Patriots</td> <td>10.9 </td> <td>11.35 </td>
  91. </tr>
  92. <tr>
  93. <td>Colts </td> <td>12.7 </td> <td>12.35 </td>
  94. </tr>
  95. <tr>
  96. <td>Colts </td> <td>12.75 </td> <td>12.3 </td>
  97. </tr>
  98. <tr>
  99. <td>Colts </td> <td>12.5 </td> <td>12.95 </td>
  100. </tr>
  101. <tr>
  102. <td>Colts </td> <td>12.55 </td> <td>12.15 </td>
  103. </tr>
  104. </tbody>
  105. </table>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="jb_cell">
  114. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  115. <div class="text_cell_render border-box-sizing rendered_html">
  116. <p>For each of the 15 balls that were inspected, the two officials got different results. It is not uncommon that repeated measurements on the same object yield different results, especially when the measurements are performed by different people. So we will assign to each the ball the average of the two measurements made on that ball.</p>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. <div class="jb_cell">
  122. <div class="cell border-box-sizing code_cell rendered">
  123. <div class="input">
  124. <div class="inner_cell">
  125. <div class="input_area">
  126. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">football</span> <span class="o">=</span> <span class="n">football</span><span class="o">.</span><span class="n">with_column</span><span class="p">(</span>
  127. <span class="s1">&#39;Combined&#39;</span><span class="p">,</span> <span class="p">(</span><span class="n">football</span><span class="o">.</span><span class="n">column</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="n">football</span><span class="o">.</span><span class="n">column</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span><span class="o">/</span><span class="mi">2</span>
  128. <span class="p">)</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
  129. <span class="n">football</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
  130. </pre></div>
  131. </div>
  132. </div>
  133. </div>
  134. <div class="output_wrapper">
  135. <div class="output">
  136. <div class="jb_output_wrapper }}">
  137. <div class="output_area">
  138. <div class="output_html rendered_html output_subarea ">
  139. <table border="1" class="dataframe">
  140. <thead>
  141. <tr>
  142. <th>Team</th> <th>Combined</th>
  143. </tr>
  144. </thead>
  145. <tbody>
  146. <tr>
  147. <td>Patriots</td> <td>11.65 </td>
  148. </tr>
  149. <tr>
  150. <td>Patriots</td> <td>11.025 </td>
  151. </tr>
  152. <tr>
  153. <td>Patriots</td> <td>11.325 </td>
  154. </tr>
  155. <tr>
  156. <td>Patriots</td> <td>10.85 </td>
  157. </tr>
  158. <tr>
  159. <td>Patriots</td> <td>11.275 </td>
  160. </tr>
  161. <tr>
  162. <td>Patriots</td> <td>11.775 </td>
  163. </tr>
  164. <tr>
  165. <td>Patriots</td> <td>12.075 </td>
  166. </tr>
  167. <tr>
  168. <td>Patriots</td> <td>11.325 </td>
  169. </tr>
  170. <tr>
  171. <td>Patriots</td> <td>11.15 </td>
  172. </tr>
  173. <tr>
  174. <td>Patriots</td> <td>10.7 </td>
  175. </tr>
  176. <tr>
  177. <td>Patriots</td> <td>11.125 </td>
  178. </tr>
  179. <tr>
  180. <td>Colts </td> <td>12.525 </td>
  181. </tr>
  182. <tr>
  183. <td>Colts </td> <td>12.525 </td>
  184. </tr>
  185. <tr>
  186. <td>Colts </td> <td>12.725 </td>
  187. </tr>
  188. <tr>
  189. <td>Colts </td> <td>12.35 </td>
  190. </tr>
  191. </tbody>
  192. </table>
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. </div>
  200. <div class="jb_cell">
  201. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  202. <div class="text_cell_render border-box-sizing rendered_html">
  203. <p>At a glance, it seems apparent that the Patriots' footballs were at a lower pressure than the Colts' balls. Because some deflation is normal during the course of a game, the independent analysts decided to calculate the drop in pressure from the start of the game. Recall that the Patriots' balls had all started out at about 12.5 psi, and the Colts' balls at about 13.0 psi. Therefore the drop in pressure for the Patriots' balls was computed as 12.5 minus the pressure at half-time, and the drop in pressure for the Colts' balls was 13.0 minus the pressure at half-time.</p>
  204. <p>We can calculate the drop in pressure for each football, by first setting up an array of the starting values. For this we will need an array consisting of 11 values each of which is 12.5, and another consisting of four values each of which is all 13. We will use the NumPy function <code>np.ones</code>, which takes a count as its argument and returns an array of that many elements, each of which is 1.</p>
  205. </div>
  206. </div>
  207. </div>
  208. </div>
  209. <div class="jb_cell">
  210. <div class="cell border-box-sizing code_cell rendered">
  211. <div class="input">
  212. <div class="inner_cell">
  213. <div class="input_area">
  214. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span>
  215. </pre></div>
  216. </div>
  217. </div>
  218. </div>
  219. <div class="output_wrapper">
  220. <div class="output">
  221. <div class="jb_output_wrapper }}">
  222. <div class="output_area">
  223. <div class="output_text output_subarea output_execute_result">
  224. <pre>array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])</pre>
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <div class="jb_cell">
  233. <div class="cell border-box-sizing code_cell rendered">
  234. <div class="input">
  235. <div class="inner_cell">
  236. <div class="input_area">
  237. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">patriots_start</span> <span class="o">=</span> <span class="mf">12.5</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span>
  238. <span class="n">colts_start</span> <span class="o">=</span> <span class="mi">13</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
  239. <span class="n">start</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">patriots_start</span><span class="p">,</span> <span class="n">colts_start</span><span class="p">)</span>
  240. <span class="n">start</span>
  241. </pre></div>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="output_wrapper">
  246. <div class="output">
  247. <div class="jb_output_wrapper }}">
  248. <div class="output_area">
  249. <div class="output_text output_subarea output_execute_result">
  250. <pre>array([12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5,
  251. 13. , 13. , 13. , 13. ])</pre>
  252. </div>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. </div>
  258. </div>
  259. <div class="jb_cell">
  260. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  261. <div class="text_cell_render border-box-sizing rendered_html">
  262. <p>The drop in pressure for each football is the difference between the starting pressure and the combined pressure measurement.</p>
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. <div class="jb_cell">
  268. <div class="cell border-box-sizing code_cell rendered">
  269. <div class="input">
  270. <div class="inner_cell">
  271. <div class="input_area">
  272. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">drop</span> <span class="o">=</span> <span class="n">start</span> <span class="o">-</span> <span class="n">football</span><span class="o">.</span><span class="n">column</span><span class="p">(</span><span class="s1">&#39;Combined&#39;</span><span class="p">)</span>
  273. <span class="n">football</span> <span class="o">=</span> <span class="n">football</span><span class="o">.</span><span class="n">with_column</span><span class="p">(</span><span class="s1">&#39;Pressure Drop&#39;</span><span class="p">,</span> <span class="n">drop</span><span class="p">)</span>
  274. <span class="n">football</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
  275. </pre></div>
  276. </div>
  277. </div>
  278. </div>
  279. <div class="output_wrapper">
  280. <div class="output">
  281. <div class="jb_output_wrapper }}">
  282. <div class="output_area">
  283. <div class="output_html rendered_html output_subarea ">
  284. <table border="1" class="dataframe">
  285. <thead>
  286. <tr>
  287. <th>Team</th> <th>Combined</th> <th>Pressure Drop</th>
  288. </tr>
  289. </thead>
  290. <tbody>
  291. <tr>
  292. <td>Patriots</td> <td>11.65 </td> <td>0.85 </td>
  293. </tr>
  294. <tr>
  295. <td>Patriots</td> <td>11.025 </td> <td>1.475 </td>
  296. </tr>
  297. <tr>
  298. <td>Patriots</td> <td>11.325 </td> <td>1.175 </td>
  299. </tr>
  300. <tr>
  301. <td>Patriots</td> <td>10.85 </td> <td>1.65 </td>
  302. </tr>
  303. <tr>
  304. <td>Patriots</td> <td>11.275 </td> <td>1.225 </td>
  305. </tr>
  306. <tr>
  307. <td>Patriots</td> <td>11.775 </td> <td>0.725 </td>
  308. </tr>
  309. <tr>
  310. <td>Patriots</td> <td>12.075 </td> <td>0.425 </td>
  311. </tr>
  312. <tr>
  313. <td>Patriots</td> <td>11.325 </td> <td>1.175 </td>
  314. </tr>
  315. <tr>
  316. <td>Patriots</td> <td>11.15 </td> <td>1.35 </td>
  317. </tr>
  318. <tr>
  319. <td>Patriots</td> <td>10.7 </td> <td>1.8 </td>
  320. </tr>
  321. <tr>
  322. <td>Patriots</td> <td>11.125 </td> <td>1.375 </td>
  323. </tr>
  324. <tr>
  325. <td>Colts </td> <td>12.525 </td> <td>0.475 </td>
  326. </tr>
  327. <tr>
  328. <td>Colts </td> <td>12.525 </td> <td>0.475 </td>
  329. </tr>
  330. <tr>
  331. <td>Colts </td> <td>12.725 </td> <td>0.275 </td>
  332. </tr>
  333. <tr>
  334. <td>Colts </td> <td>12.35 </td> <td>0.65 </td>
  335. </tr>
  336. </tbody>
  337. </table>
  338. </div>
  339. </div>
  340. </div>
  341. </div>
  342. </div>
  343. </div>
  344. </div>
  345. <div class="jb_cell">
  346. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  347. <div class="text_cell_render border-box-sizing rendered_html">
  348. <p>It looks as though the Patriots' drops were larger than the Colts'. Let's look at the average drop in each of the two groups. We no longer need the combined scores.</p>
  349. </div>
  350. </div>
  351. </div>
  352. </div>
  353. <div class="jb_cell">
  354. <div class="cell border-box-sizing code_cell rendered">
  355. <div class="input">
  356. <div class="inner_cell">
  357. <div class="input_area">
  358. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">football</span> <span class="o">=</span> <span class="n">football</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="s1">&#39;Combined&#39;</span><span class="p">)</span>
  359. <span class="n">football</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s1">&#39;Team&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">average</span><span class="p">)</span>
  360. </pre></div>
  361. </div>
  362. </div>
  363. </div>
  364. <div class="output_wrapper">
  365. <div class="output">
  366. <div class="jb_output_wrapper }}">
  367. <div class="output_area">
  368. <div class="output_html rendered_html output_subarea output_execute_result">
  369. <table border="1" class="dataframe">
  370. <thead>
  371. <tr>
  372. <th>Team</th> <th>Pressure Drop average</th>
  373. </tr>
  374. </thead>
  375. <tbody>
  376. <tr>
  377. <td>Colts </td> <td>0.46875 </td>
  378. </tr>
  379. <tr>
  380. <td>Patriots</td> <td>1.20227 </td>
  381. </tr>
  382. </tbody>
  383. </table>
  384. </div>
  385. </div>
  386. </div>
  387. </div>
  388. </div>
  389. </div>
  390. </div>
  391. <div class="jb_cell">
  392. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  393. <div class="text_cell_render border-box-sizing rendered_html">
  394. <p>The average drop for the Patriots was about 1.2 psi compared to about 0.47 psi for the Colts.</p>
  395. <p>The question now is why the Patriots' footballs had a larger drop in pressure, on average, than the Colts footballs. Could it be due to chance?</p>
  396. <h3 id="The-Hypotheses">The Hypotheses<a class="anchor-link" href="#The-Hypotheses"> </a></h3><p>How does chance come in here? Nothing was being selected at random. But we can make a chance model by hypothesizing that the 11 Patriots' drops look like a random sample of 11 out of all the 15 drops, with the Colts' drops being the remaining four. That's a completely specified chance model under which we can simulate data. So it's the <strong>null hypothesis</strong>.</p>
  397. <p>For the alternative, we can take the position that the Patriots' drops are too large, on average, to resemble a random sample drawn from all the drops.</p>
  398. <h3 id="Test-Statistic">Test Statistic<a class="anchor-link" href="#Test-Statistic"> </a></h3><p>A natural statistic is the difference between the two average drops, which we will compute as "average drop for Patriots - average drop for Colts". Large values of this statistic will favor the alternative hypothesis.</p>
  399. </div>
  400. </div>
  401. </div>
  402. </div>
  403. <div class="jb_cell">
  404. <div class="cell border-box-sizing code_cell rendered">
  405. <div class="input">
  406. <div class="inner_cell">
  407. <div class="input_area">
  408. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">observed_means</span> <span class="o">=</span> <span class="n">football</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s1">&#39;Team&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">average</span><span class="p">)</span><span class="o">.</span><span class="n">column</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
  409. <span class="n">observed_difference</span> <span class="o">=</span> <span class="n">observed_means</span><span class="o">.</span><span class="n">item</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">-</span> <span class="n">observed_means</span><span class="o">.</span><span class="n">item</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
  410. <span class="n">observed_difference</span>
  411. </pre></div>
  412. </div>
  413. </div>
  414. </div>
  415. <div class="output_wrapper">
  416. <div class="output">
  417. <div class="jb_output_wrapper }}">
  418. <div class="output_area">
  419. <div class="output_text output_subarea output_execute_result">
  420. <pre>0.733522727272728</pre>
  421. </div>
  422. </div>
  423. </div>
  424. </div>
  425. </div>
  426. </div>
  427. </div>
  428. <div class="jb_cell">
  429. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  430. <div class="text_cell_render border-box-sizing rendered_html">
  431. <p>This positive difference reflects the fact that the average drop in pressure of the Patriots' footballs was greater than that of the Colts.</p>
  432. </div>
  433. </div>
  434. </div>
  435. </div>
  436. <div class="jb_cell">
  437. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  438. <div class="text_cell_render border-box-sizing rendered_html">
  439. <p>The function <code>difference_of_means</code> takes three arguments:</p>
  440. <ul>
  441. <li>the name of the table of data</li>
  442. <li>the label of the column containing the numerical variable whose average is of interest</li>
  443. <li>the label of the column containing the two group labels</li>
  444. </ul>
  445. <p>It returns the difference between the means of the two groups.</p>
  446. <p>We have defined this function in an earlier section. The definition is repeated here for ease of reference.</p>
  447. </div>
  448. </div>
  449. </div>
  450. </div>
  451. <div class="jb_cell">
  452. <div class="cell border-box-sizing code_cell rendered">
  453. <div class="input">
  454. <div class="inner_cell">
  455. <div class="input_area">
  456. <div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">difference_of_means</span><span class="p">(</span><span class="n">table</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">group_label</span><span class="p">):</span>
  457. <span class="n">reduced</span> <span class="o">=</span> <span class="n">table</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">group_label</span><span class="p">)</span>
  458. <span class="n">means_table</span> <span class="o">=</span> <span class="n">reduced</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">group_label</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">average</span><span class="p">)</span>
  459. <span class="n">means</span> <span class="o">=</span> <span class="n">means_table</span><span class="o">.</span><span class="n">column</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
  460. <span class="k">return</span> <span class="n">means</span><span class="o">.</span><span class="n">item</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">-</span> <span class="n">means</span><span class="o">.</span><span class="n">item</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
  461. </pre></div>
  462. </div>
  463. </div>
  464. </div>
  465. </div>
  466. </div>
  467. <div class="jb_cell">
  468. <div class="cell border-box-sizing code_cell rendered">
  469. <div class="input">
  470. <div class="inner_cell">
  471. <div class="input_area">
  472. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">difference_of_means</span><span class="p">(</span><span class="n">football</span><span class="p">,</span> <span class="s1">&#39;Pressure Drop&#39;</span><span class="p">,</span> <span class="s1">&#39;Team&#39;</span><span class="p">)</span>
  473. </pre></div>
  474. </div>
  475. </div>
  476. </div>
  477. <div class="output_wrapper">
  478. <div class="output">
  479. <div class="jb_output_wrapper }}">
  480. <div class="output_area">
  481. <div class="output_text output_subarea output_execute_result">
  482. <pre>0.733522727272728</pre>
  483. </div>
  484. </div>
  485. </div>
  486. </div>
  487. </div>
  488. </div>
  489. </div>
  490. <div class="jb_cell">
  491. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  492. <div class="text_cell_render border-box-sizing rendered_html">
  493. <p>Notice that the difference has been calculated as Patriots' drops minus Colts' drops as before.</p>
  494. </div>
  495. </div>
  496. </div>
  497. </div>
  498. <div class="jb_cell">
  499. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  500. <div class="text_cell_render border-box-sizing rendered_html">
  501. <h3 id="Predicting-the-Statistic-Under-the-Null-Hypothesis">Predicting the Statistic Under the Null Hypothesis<a class="anchor-link" href="#Predicting-the-Statistic-Under-the-Null-Hypothesis"> </a></h3><p>If the null hypothesis were true, then it shouldn't matter which footballs are labeled Patriots and which are labeled Colts. The distributions of the two sets of drops would be the same. We can simulate this by randomly shuffling the team labels.</p>
  502. </div>
  503. </div>
  504. </div>
  505. </div>
  506. <div class="jb_cell">
  507. <div class="cell border-box-sizing code_cell rendered">
  508. <div class="input">
  509. <div class="inner_cell">
  510. <div class="input_area">
  511. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">shuffled_labels</span> <span class="o">=</span> <span class="n">football</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">with_replacement</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span><span class="o">.</span><span class="n">column</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
  512. <span class="n">original_and_shuffled</span> <span class="o">=</span> <span class="n">football</span><span class="o">.</span><span class="n">with_column</span><span class="p">(</span><span class="s1">&#39;Shuffled Label&#39;</span><span class="p">,</span> <span class="n">shuffled_labels</span><span class="p">)</span>
  513. <span class="n">original_and_shuffled</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
  514. </pre></div>
  515. </div>
  516. </div>
  517. </div>
  518. <div class="output_wrapper">
  519. <div class="output">
  520. <div class="jb_output_wrapper }}">
  521. <div class="output_area">
  522. <div class="output_html rendered_html output_subarea ">
  523. <table border="1" class="dataframe">
  524. <thead>
  525. <tr>
  526. <th>Team</th> <th>Pressure Drop</th> <th>Shuffled Label</th>
  527. </tr>
  528. </thead>
  529. <tbody>
  530. <tr>
  531. <td>Patriots</td> <td>0.85 </td> <td>Colts </td>
  532. </tr>
  533. <tr>
  534. <td>Patriots</td> <td>1.475 </td> <td>Patriots </td>
  535. </tr>
  536. <tr>
  537. <td>Patriots</td> <td>1.175 </td> <td>Patriots </td>
  538. </tr>
  539. <tr>
  540. <td>Patriots</td> <td>1.65 </td> <td>Patriots </td>
  541. </tr>
  542. <tr>
  543. <td>Patriots</td> <td>1.225 </td> <td>Patriots </td>
  544. </tr>
  545. <tr>
  546. <td>Patriots</td> <td>0.725 </td> <td>Patriots </td>
  547. </tr>
  548. <tr>
  549. <td>Patriots</td> <td>0.425 </td> <td>Patriots </td>
  550. </tr>
  551. <tr>
  552. <td>Patriots</td> <td>1.175 </td> <td>Colts </td>
  553. </tr>
  554. <tr>
  555. <td>Patriots</td> <td>1.35 </td> <td>Patriots </td>
  556. </tr>
  557. <tr>
  558. <td>Patriots</td> <td>1.8 </td> <td>Patriots </td>
  559. </tr>
  560. <tr>
  561. <td>Patriots</td> <td>1.375 </td> <td>Colts </td>
  562. </tr>
  563. <tr>
  564. <td>Colts </td> <td>0.475 </td> <td>Patriots </td>
  565. </tr>
  566. <tr>
  567. <td>Colts </td> <td>0.475 </td> <td>Patriots </td>
  568. </tr>
  569. <tr>
  570. <td>Colts </td> <td>0.275 </td> <td>Colts </td>
  571. </tr>
  572. <tr>
  573. <td>Colts </td> <td>0.65 </td> <td>Patriots </td>
  574. </tr>
  575. </tbody>
  576. </table>
  577. </div>
  578. </div>
  579. </div>
  580. </div>
  581. </div>
  582. </div>
  583. </div>
  584. <div class="jb_cell">
  585. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  586. <div class="text_cell_render border-box-sizing rendered_html">
  587. <p>How do all the group averages compare?</p>
  588. </div>
  589. </div>
  590. </div>
  591. </div>
  592. <div class="jb_cell">
  593. <div class="cell border-box-sizing code_cell rendered">
  594. <div class="input">
  595. <div class="inner_cell">
  596. <div class="input_area">
  597. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">difference_of_means</span><span class="p">(</span><span class="n">original_and_shuffled</span><span class="p">,</span> <span class="s1">&#39;Pressure Drop&#39;</span><span class="p">,</span> <span class="s1">&#39;Shuffled Label&#39;</span><span class="p">)</span>
  598. </pre></div>
  599. </div>
  600. </div>
  601. </div>
  602. <div class="output_wrapper">
  603. <div class="output">
  604. <div class="jb_output_wrapper }}">
  605. <div class="output_area">
  606. <div class="output_text output_subarea output_execute_result">
  607. <pre>0.11988636363636407</pre>
  608. </div>
  609. </div>
  610. </div>
  611. </div>
  612. </div>
  613. </div>
  614. </div>
  615. <div class="jb_cell">
  616. <div class="cell border-box-sizing code_cell rendered">
  617. <div class="input">
  618. <div class="inner_cell">
  619. <div class="input_area">
  620. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">difference_of_means</span><span class="p">(</span><span class="n">original_and_shuffled</span><span class="p">,</span> <span class="s1">&#39;Pressure Drop&#39;</span><span class="p">,</span> <span class="s1">&#39;Team&#39;</span><span class="p">)</span>
  621. </pre></div>
  622. </div>
  623. </div>
  624. </div>
  625. <div class="output_wrapper">
  626. <div class="output">
  627. <div class="jb_output_wrapper }}">
  628. <div class="output_area">
  629. <div class="output_text output_subarea output_execute_result">
  630. <pre>0.733522727272728</pre>
  631. </div>
  632. </div>
  633. </div>
  634. </div>
  635. </div>
  636. </div>
  637. </div>
  638. <div class="jb_cell">
  639. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  640. <div class="text_cell_render border-box-sizing rendered_html">
  641. <p>The two teams' average drop values are closer when the team labels are randomly assigned to the footballs than they were for the two groups actually used in the game.</p>
  642. <h3 id="Permutation-Test">Permutation Test<a class="anchor-link" href="#Permutation-Test"> </a></h3><p>It's time for a step that is now familiar. We will do repeated simulations of the test statistic under the null hypothesis, by repeatedly permuting the footballs and assigning random sets to the two teams.</p>
  643. <p>Once again, we will use the function <code>one_simulated_difference</code> defined in an earlier section as follows.</p>
  644. </div>
  645. </div>
  646. </div>
  647. </div>
  648. <div class="jb_cell">
  649. <div class="cell border-box-sizing code_cell rendered">
  650. <div class="input">
  651. <div class="inner_cell">
  652. <div class="input_area">
  653. <div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">one_simulated_difference</span><span class="p">(</span><span class="n">table</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">group_label</span><span class="p">):</span>
  654. <span class="n">shuffled_labels</span> <span class="o">=</span> <span class="n">table</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">with_replacement</span> <span class="o">=</span> <span class="kc">False</span>
  655. <span class="p">)</span><span class="o">.</span><span class="n">column</span><span class="p">(</span><span class="n">group_label</span><span class="p">)</span>
  656. <span class="n">shuffled_table</span> <span class="o">=</span> <span class="n">table</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">.</span><span class="n">with_column</span><span class="p">(</span>
  657. <span class="s1">&#39;Shuffled Label&#39;</span><span class="p">,</span> <span class="n">shuffled_labels</span><span class="p">)</span>
  658. <span class="k">return</span> <span class="n">difference_of_means</span><span class="p">(</span><span class="n">shuffled_table</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="s1">&#39;Shuffled Label&#39;</span><span class="p">)</span>
  659. </pre></div>
  660. </div>
  661. </div>
  662. </div>
  663. </div>
  664. </div>
  665. <div class="jb_cell">
  666. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  667. <div class="text_cell_render border-box-sizing rendered_html">
  668. <p>We can now use this function to create an array <code>differences</code> that contains 10,000 values of the test statistic simulated under the null hypothesis.</p>
  669. </div>
  670. </div>
  671. </div>
  672. </div>
  673. <div class="jb_cell">
  674. <div class="cell border-box-sizing code_cell rendered">
  675. <div class="input">
  676. <div class="inner_cell">
  677. <div class="input_area">
  678. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">differences</span> <span class="o">=</span> <span class="n">make_array</span><span class="p">()</span>
  679. <span class="n">repetitions</span> <span class="o">=</span> <span class="mi">10000</span>
  680. <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">repetitions</span><span class="p">):</span>
  681. <span class="n">new_difference</span> <span class="o">=</span> <span class="n">one_simulated_difference</span><span class="p">(</span><span class="n">football</span><span class="p">,</span> <span class="s1">&#39;Pressure Drop&#39;</span><span class="p">,</span> <span class="s1">&#39;Team&#39;</span><span class="p">)</span>
  682. <span class="n">differences</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">differences</span><span class="p">,</span> <span class="n">new_difference</span><span class="p">)</span>
  683. </pre></div>
  684. </div>
  685. </div>
  686. </div>
  687. </div>
  688. </div>
  689. <div class="jb_cell">
  690. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  691. <div class="text_cell_render border-box-sizing rendered_html">
  692. <h3 id="Conclusion-of-the-Test">Conclusion of the Test<a class="anchor-link" href="#Conclusion-of-the-Test"> </a></h3><p>To calculate the empirical P-value, it's important to recall the alternative hypothesis, which is that the Patriots' drops are too large to be the result of chance variation alone.</p>
  693. <p>Larger drops for the Patriots favor the alternative hypothesis. So the P-value is the chance (computed under the null hypothesis) of getting a test statistic equal to our observed value of 0.733522727272728 or larger.</p>
  694. </div>
  695. </div>
  696. </div>
  697. </div>
  698. <div class="jb_cell">
  699. <div class="cell border-box-sizing code_cell rendered">
  700. <div class="input">
  701. <div class="inner_cell">
  702. <div class="input_area">
  703. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">empirical_P</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">count_nonzero</span><span class="p">(</span><span class="n">differences</span> <span class="o">&gt;=</span> <span class="n">observed_difference</span><span class="p">)</span> <span class="o">/</span> <span class="mi">10000</span>
  704. <span class="n">empirical_P</span>
  705. </pre></div>
  706. </div>
  707. </div>
  708. </div>
  709. <div class="output_wrapper">
  710. <div class="output">
  711. <div class="jb_output_wrapper }}">
  712. <div class="output_area">
  713. <div class="output_text output_subarea output_execute_result">
  714. <pre>0.0043</pre>
  715. </div>
  716. </div>
  717. </div>
  718. </div>
  719. </div>
  720. </div>
  721. </div>
  722. <div class="jb_cell">
  723. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  724. <div class="text_cell_render border-box-sizing rendered_html">
  725. <p>That's a pretty small P-value. To visualize this, here is the empirical distribution of the test statistic under the null hypothesis, with the observed statistic marked on the horizontal axis.</p>
  726. </div>
  727. </div>
  728. </div>
  729. </div>
  730. <div class="jb_cell">
  731. <div class="cell border-box-sizing code_cell rendered">
  732. <div class="input">
  733. <div class="inner_cell">
  734. <div class="input_area">
  735. <div class=" highlight hl-ipython3"><pre><span></span><span class="n">Table</span><span class="p">()</span><span class="o">.</span><span class="n">with_column</span><span class="p">(</span><span class="s1">&#39;Difference Between Group Averages&#39;</span><span class="p">,</span> <span class="n">differences</span><span class="p">)</span><span class="o">.</span><span class="n">hist</span><span class="p">()</span>
  736. <span class="n">plots</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">observed_difference</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
  737. <span class="n">plots</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s1">&#39;Prediction Under the Null Hypothesis&#39;</span><span class="p">)</span>
  738. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Observed Difference:&#39;</span><span class="p">,</span> <span class="n">observed_difference</span><span class="p">)</span>
  739. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Empirical P-value:&#39;</span><span class="p">,</span> <span class="n">empirical_P</span><span class="p">)</span>
  740. </pre></div>
  741. </div>
  742. </div>
  743. </div>
  744. <div class="output_wrapper">
  745. <div class="output">
  746. <div class="jb_output_wrapper }}">
  747. <div class="output_area">
  748. <div class="output_subarea output_stream output_stdout output_text">
  749. <pre>Observed Difference: 0.733522727272728
  750. Empirical P-value: 0.0043
  751. </pre>
  752. </div>
  753. </div>
  754. </div>
  755. <div class="jb_output_wrapper }}">
  756. <div class="output_area">
  757. <div class="output_png output_subarea ">
  758. <img src="../../../images/chapters/12/2/Deflategate_31_1.png"
  759. >
  760. </div>
  761. </div>
  762. </div>
  763. </div>
  764. </div>
  765. </div>
  766. </div>
  767. <div class="jb_cell">
  768. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  769. <div class="text_cell_render border-box-sizing rendered_html">
  770. <p>As in previous examples of this test, the bulk of the distribution is centered around 0. Under the null hypothesis, the Patriots' drops are a random sample of all 15 drops, and therefore so are the Colts'. Therefore the two sets of drops should be about equal on average, and therefore their difference should be around 0.</p>
  771. <p>But the observed value of the test statistic is quite far away from the heart of the distribution. By any reasonable cutoff for what is "small", the empirical P-value is small. So we end up rejecting the null hypothesis of randomness, and conclude that the Patriots drops were too large to reflect chance variation alone.</p>
  772. <p>The independent investigative team analyzed the data in several different ways, taking into account the laws of physics. The final report said,</p>
  773. <blockquote><p>"[T]he average pressure drop of the Patriots game balls exceeded the average pressure drop of the Colts balls by 0.45 to 1.02 psi, depending on various possible assumptions regarding the gauges used, and assuming an initial pressure of 12.5 psi for the Patriots balls and 13.0 for the Colts balls."</p>
  774. <p>-- <em>Investigative report commissioned by the NFL regarding the AFC Championship game on January 18, 2015</em></p>
  775. </blockquote>
  776. <p>Our analysis shows an average pressure drop of about 0.73 psi, which is close to the center of the interval "0.45 to 1.02 psi" and therefore consistent with the official analysis.</p>
  777. </div>
  778. </div>
  779. </div>
  780. </div>
  781. <div class="jb_cell">
  782. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  783. <div class="text_cell_render border-box-sizing rendered_html">
  784. <p>Remember that our test of hypotheses does not establish the reason <em>why</em> the difference is not due to chance. Establishing causality is usually more complex than running a test of hypotheses.</p>
  785. <p>But the all-important question in the football world was about causation: the question was whether the excess drop of pressure in the Patriots' footballs was deliberate. If you are curious about the answer given by the investigators, here is the <a href="https://nfllabor.files.wordpress.com/2015/05/investigative-and-expert-reports-re-footballs-used-during-afc-championsh.pdf">full report</a>.</p>
  786. </div>
  787. </div>
  788. </div>
  789. </div>