{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#Chapter 11. Null Hypothesis Significance Testing" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Contents\n", "### 11.1 NHST for the bias of a coin\n", "### 11.2 Prior knowledge about the coin\n", "### 11.3 Confidence interval and highest density interval\n", "### 11.4 Multiple comparisons\n", "### 11.5 What a sampling distribution is good for\n", "## -----------------------------------------------------------------------------------------------------------------------------" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " In null hypothesis significance testing(NHST), the goal of inference is to decide whether a particular value of a model parameter can be rejected. \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For example, we might want to know whether a coin is fair, which in NHST becomes the question of whether we can reject the hypothesis that the bias of the coin has the specific value 0.5.\n", " To make the logic of NHST concrete, suppose we have a coin that we want to test for fairness. We decide that we will conduct an experiment wherein we flip the coin N = 26 times, and we observe how many times it comes up heads. If the coin is fair, it should usually come up heads about 13 times out of 26 flips. Only rarely will it come up with far\n", "fewer or far greater than 13 heads. \n", " Suppose we now conduct our experiment: We flip the coin N = 26 times and we happen to observe z = 8 heads. All we need to do is figure out the probability of getting that few heads if the coin were truly fair. If the probability of getting so few heads is sufficiently tiny, then we doubt that the coin is truly fair.\n", "Notice that this reasoning depends on the notion of repeating the intended experiment, because we are computing the probability of getting 8 heads if we were to repeat an experiment with N = 26. In other words, we are figuring out the probability of getting 8 heads relative to the space of all possible outcomes when N = 26. Why do we restrict consideration to N = 26? Because that was the intention of the experimenter." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The problem with NHST is that the interpretation of the observed outcome depends on the space of possible outcomes when the experiment is repeated. Why is that a problem? Because the definition of the space of possible outcomes depends on the intentions of the experimenter. \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " ## Intention!!!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " If the experimenter intended to flip the coin exactly N = 26 times, then the space of possibilities is all samples with N = 26. But if the experimenter intended to flip the coin for one minute (and merely happened to make 26 flips during that time) then the space of possibilities is all samples that could occur when flipping the coin for one minute. Some of those possibilities would have N = 26, but some would have N = 23, and some would have N = 32, etc. On the other hand, the experimenter might have intended to flip the coin until observing 8 heads, and it just happened to take 26 flips to get there. In this case, the space of possibilities is all samples that have the 8th head as the last flip. Notice that for any of those intended experiments (fixed N, fixed time, or fixed z), the actually-observed data are the same: z = 8 and N = 26. But the probability of the observed\n", "data is different relative to each experiment space. The space of possibilities is determined by what the experimenter had in mind while flipping the coin." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Do the observed data depend on what the experimenter had in mind? " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " \n", " ### We certainly hope not! \n", " A good experiment is founded on the principle that the data are insulated from experimenter’s intentions. The coin “knows” only that it was flipped 26 times, regardless of what the experimenter had in mind while doing the flipping. Therefore our conclusion about the coin should not depend on what the experimenter had in mind while flipping it. This chapter explains some of the gory details of NHST, to bring mathematical rigor to the above comments, and to bring rigor mortis to NHST. You’ll see how NHST is committed to the notion that the covert intentions of the experimenter are crucial to interpreting the\n", "data, even though the data are not supposed to be influenced by the covert intentions of the experimenter.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 11.1 NHST for the bias of a coin\n", "### 11.1.1 When the experimenter intends to fix N\n", "Now for some of the mathematical details of NHST. Suppose we intend to flip a coin N = 26 times and we happen to observe z = 8 heads. This result seems to suggest that the coin is biased, because the result is less than the 13 heads that we would expect to get from a fair coin. But someone who is skeptical about the claim that the coin is biased, i.e., a defender of the null hypothesis that the coin is fair, would argue that the seemingly biased result could have happened merely by chance from a genuinely fair coin. Because a “false alarm”(제 1종 오류), i.e., rejection of a null hypothesis when it is really true, is considered to be very costly in scientific practice, we decide that we will only reject the null hypothesis if the probability that it could generate the result is very small, conventionally less than 5%. In other words, to reject the null hypothesis, we need to show that the probability of getting something as extreme as z = 8, when N = 26, is less than 5%.(유의수준)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is the probability of getting a particular number of heads when N is fixed? The\n", "answer is provided by the binomial probability distribution, which states that the probability\n", "of getting z heads out of N flips is" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##\n", "where the notation\n", "\u0010Nz\n", "\u0011\n", "will be defined below. The binomial distribution is derived by the\n", "following logic. Consider any specific sequence of N flips with z heads. The probability of\n", "that specific sequence is simply the product of the individual flips, which is the product of\n", "Bernoulli probabilities\n", "Q\n", "i θyi (1 − θ)1−yi = θz(1 − θ)N−z, which we first saw in Section 5.1,\n", "p. 66. But there are many different specific sequences with z heads. \n", "Let’s count how many\n", "ways there are. Consider allocating z heads to N flips in the sequence. The first head could\n", "go in any one of the N slots. The second head could go in any one of the remaining N − 1\n", "slots. The third head could go in any one of the remaining N − 2 slots. And so on, until the\n", "zth head could go in any one of the remaining N−(z−1) slots. Multiplying those possibilities\n", "together means that there are N · (N − 1) · . . . · (N − (z − 1)) ways of allocating z heads to N\n", "flips. As an algebraic convenience, notice that N · (N − 1) · . . . · (N − (z − 1)) = N!/(N − z)!.\n", "\n", "In this counting of the allocations, we’ve counted different orderings of the same allocation\n", "separately. For example, putting the 1st head in the 1st slot and the 2nd head in the second\n", "slot was counted as a different allocation than putting the 1st head in the 2nd slot and the\n", "2nd head in the 1st slot. In the space of possible outcomes, there is no meaningful difference\n", "in these allocations, because they both have a head in the 1st and 2nd slots. Therefore we\n", "get rid of this duplicate counting by dividing out by the number of ways of permuting the\n", "z heads among their z slots. The number of permutations of z items is z!. Putting this all together, the number of ways of allocating z heads among N flips, without duplicate\n", "counting of equivalent allocations, is N!/[(N − z)!z!]. This factor is also called the number\n", "of ways of choosing z items from N possibilities, or “N choose z” for \u0010 short, and is denoted Nz\n", "\u0011\n", "\n", "##\n", "\n", ". Thus, the overall probability of getting z heads in N flips is the probability of any\n", "particular sequence of z heads in N flips times the number of ways of choosing z slots from\n", "among the N possible flips. The product appears in Equation 11.1. An illustration of a\n", "binomial probability distribution is provided in the right panel of Figure 11.1, for N = 26\n", "and θ = .5. Notice that the abscissa ranges from z = 0 to z = 26, because in N = 26 flips it\n", "is possible to get anywhere from no heads to all heads.\n", "\n", "## Bernoulli -> Binomial\n", "\n", "\n", "**The binomial probability distribution in Figure 11.1 is also called a sampling distribution(or Empirical distribution).**\n", "Sampling with replacement(ex. Bootstrapping)\n", "Sampling without replacement\n", "\n", "##\n", "This terminology stems from the idea that any set of N flips is a representative sample\n", "of the behavior of the coin. If we were to repeatedly run experiments with a fair coin, such\n", "that in every experiment we flip the coin exactly N times, then, in the long run, the probability\n", "of getting each possible z would be the distribution shown in Figure 11.1. To describe\n", "it carefully, we would call it “the probability distribution of the possible sample outcomes”,\n", "but that’s usually just abbreviated as “the sampling distribution”.\n", "The left side of Figure 11.1 shows the null hypothesis. It shows the probability distribution\n", "for the two states of the coin. According to the null hypothesis, the coin is fair, whereby\n", "p(y = heads) = θ = .5. The two panels in the figure are connected by an implication arrow\n", "to denote that fact that when the sample size N is fixed, the sampling distribution on the\n", "right is implied.\n", "##\n", "\n", " Our goal is to determine whether the probability of getting the observed\n", "result, z = 8, is tiny enough that we can reject the null hypothesis. By using the binomial probability formula in Equation 11.1, we determine that the probability of getting exactly z = 8 heads in N = 26 flips is 2.3%." ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "0.0232797116041184" ], "text/latex": [ "0.0232797116041184" ], "text/markdown": [ "0.0232797116041184" ], "text/plain": [ "[1] 0.02327971" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dbinom(8, 26, 0.5, log = FALSE)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "