1. Why we conduct a t test?

  • A t-test is a statistical test that is used to compare the means of two groups.
  • It is often used in hypothesis testing to determine whether a process or treatment actually has an effect on the population of interest, or whether two groups are different each other.
  • The Central Limit Theorem suggests that even if the original variables themselves are not normally distributed, distribution of samples converges to normal as the number of samples increases.
    → This is the theoretical foundation that we can conduct statistical inference and hypothesis test using a normal distribution.
  • However, it is not always the case that we can have access to sizable data.
  • t test provides us a solution of this small N problem in hypothesis testing.

2. What type of t-test should we use?

When you conduct a t-test, you need to consider two things:
(1) whether the groups being compared come from a single population or two different populations
(3) whether you want to test the difference in a specific direction or both directions

One-sample, two-sample, or paired t-test?

  • If the groups come from a single population (for example, measuring before and after an medical treatment), perform a paired t-test.
  • If the groups come from two different populations (for exmaple, comparing which hamberger tastes better between McDonald’s and In-N-Out Burger), perform a two-sample t-test.
  • If there is one group being compared against a standard value (for example, comparing your test score to the averaged test score of your friends in the same class), perform a one-sample t-test.

One-tailed or two-tailed t-test?

  • If you only care whether the two populations are different from one another, perform a two-tailed t-test.
  • If you want to know whether one population mean is greater than or less than the other, perform a one-tailed t-test.
  • A one-tailed t-test is way harder to be passed.

3. Statistical significance

Denoted as Details
significance level α The probability of the study rejecting the null hypothesis
significance probability p-value The probability of obtaining a result at least as extreme, given that the null hypothesis is true.
  • In statistical hypothesis testing, a result has statistical significance when it is very unlikely to have occurred given the null hypothesis.
  • The null hypothesis (often denoted \(H_0\) ) is a default hypothesis that a quantity to be measured is zero (null).
  • The alternative hypothesis (often denoted \(H_1\) ) is a position that states something is happening, a new theory is preferred instead of an old one (null hypothesis).
  • A study’s defined significance level, denoted by \(α\), is the probability of the study rejecting the null hypothesis, given that the null hypothesis was assumed to be true.
  • Significance probability, the p-value of a result (\(p\)), is the probability of obtaining a result at least as extreme, given that the null hypothesis is true.
  • The result is statistically significant, by the standards of the study, when \(p≤α\).
  • The significance level for a study is chosen before data collection, and is typically set to 5% or much lower—depending on the field of study.

3.1 Process of t test

  • Let’s suppose you drew 10 numbers (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) from the population (population mean \(μ\) = 5.5)
  • The sample mean = 5.5
    (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)/10 = 5.5
  • What we want to know:
    Whether or not the population mean is 5.
  • To confirm this, we need to conduct t test.
Process of t test
  • Show null hypothesis: \(H_0\)
  • Show alternative hypothesis: \(H_1\)
  • Calculate t value
  • Identify the critical values
  • Check if your t value is within the rejection area
  • Conclusion
  • Process of t test in this case

    • \(H_0\): the population mean = 5
    • What we want to know is “The sample mean is 5.5. With this result, can we conclude that the population mean is 5?”
    • \(H_1\): the population mean is not 5
    • \(H_0\) and \(H_1\) are mutually exclusive
    • Calculate \(t value\) with the following equation:

    \[T = \frac{\bar{x} - μ_0}{SE} = \frac{\bar{x} - μ_0}{u_x / \sqrt{n}}\]

    • \(\bar{x}\) : Sample mean (= 5.5)
    • \(μ_0\) : The value we want to estimate (= 5)
    • \(n\) : Sample size (= 10)
    • \(u_x\): unbiased standard deviation
    • \(SE\) : standard Error: SE

    \(u_x^2\) can be calculated with the following eauation:

    \[u_x^2 = \frac{\sum_{i=1}^n (x_i - \bar{x})^2}{n-1}\]

    • \(u_x\) = 3.03
    • If we plug in \(μ_0\) = 5 in the equation above, we get the following t value:

    \[T = \frac{\bar{x} - μ_0}{u_x / \sqrt{n}}\]

    \[ = \frac{{5.5} - 5}{3.03 / \sqrt{10}}\]

    \[ = 0.522\]

    • We want to know whether or not the population mean is 5.

    Point estimation

    • Point estimation involves the use of sample data to calculate a single value (known as a point estimate) which is to serve as a “best guess” or “best estimate” of an unknown population parameter (for example, the population mean).
    • We estimate the sample mean, 0.522, and infer whether the population mean is 5.

    • Numbers in each cell is the critical value for 7 levels of significance level.
    • We reject the null hypothesis when the t value we get from our sample (0.522 in this case) is larger than the critical value (which we are trying to identify here).
    • \(v\) is the degree of freedom: the number of sample size - 1
      → 9 in this case (= 10 - 1)
    • \(α\) is significance level:
    • Usually we use the significance level \((α = 0.05)\) for one-tailed t-test.
      → We use the significance level \((α = 0.025)\) for two-tailed t-test here.
    • See the intersection of \((α = 0.025)\) & \(v=9\) in the table
    • The value 2.262 is the critical value

    • If the t value we get from our sample (0.05) lies between -2.26 and 2.26, then we fail to reject the null hypothesis.
    • If the t value we get from our sample (0.05) lies out of this range, then we reject the null hypothesis.
    • 0.05 lies between -2.26 and 2.26
      → we cannot reject the null hypothesis : population mean is 5

      → Based on the sample we get, the population mean CAN BE 5.

    3.3 t test on R

    • We draw the 10 values from a population, 1, 2, …, 10
    • We do not know its population mean
    score <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    • We want to know if the population mean = 5 or not
    • Null hypothesis: the population mean = 5
    t.test(score, mu = 5)
    
        One Sample t-test
    
    data:  score
    t = 0.52223, df = 9, p-value = 0.6141
    alternative hypothesis: true mean is not equal to 5
    95 percent confidence interval:
     3.334149 7.665851
    sample estimates:
    mean of x 
          5.5 
    • See the row 3:
    • \(t\) = 0.52223, p-value = 0.6141
    • p-value = 0.6141 means the p-value in a two-tailed ttest
    • See the row 4: alternative hypothesis: true mean is not equal to 5
    • p-value (0.6141) is larger than 0.05
      → We cannot reject the null hypothesis: the population mean = 5
      → Based on the sample we get, the population mean CAN BE 5.

    3.5 EXERCISE

    • We conducted a survey to 10 Waseda students who bought cell phones.
    • The followings are the information we got.
    • The averaged price of a cell phone is 65,000 yen
    • Standard deviation = 10,000 yen.

    Question: Can you say that the population mean of the price of a cell phone is 50,000 yen? Calculate t value both by hand and on R can check if you get the same results.

    3.6 EXERCISE

    • Tom opened a case near the Waseda campus, named Printemps.
    • Total sales for the last 8 days are the followings:

    45, 39, 42, 57, 28, 33, 40, 52(unit: 10,000 yen)

    Question: Can you say that the population mean of the cafe Printems is 500,000 yen? Calculate t value both by hand and on R can check if you get the same results.

    4. Estimation on Population Propotion

    内閣支持29%、不支持52%(NHK世論調査)記事

    • This article reports the result of a survey conducted by NHK (August 10, 2021)
    • The survey was conducted on August 2021.
    • Cabinet support rate for the Suga Administration is 29%
    • N = 1214

    Question: Can you say that the cabinet rate for the Suga Administration is less than 30%?

    • This is similar to ttest, but we should not use it.
    • We need to use proportion test on R: prop.test() function
    • Since 29% of 12114 respondents support the Suga Administration, 352 of 1214 supported the Suga Administration
    prop.test(c(352), c(1214))
    
        1-sample proportions test with continuity correction
    
    data:  c(352) out of c(1214), null probability 0.5
    X-squared = 213.41, df = 1, p-value < 2.2e-16
    alternative hypothesis: true p is not equal to 0.5
    95 percent confidence interval:
     0.2647212 0.3165265
    sample estimates:
            p 
    0.2899506 
    • Null hypothesis: the cabinet support rate in population = 0.5 (50%)
      → p-value < 2.2e-16 (= 0.00000000000000022)
    • We can reject the null hypothesis
      → The cabinet support rate in population is not 50%
    • See 95 percent confidence interval: 0.2647212 --- 0.3165265 → The true cabinet support rate in population must be somewhere between 26.47% ~ 31.66%
    • 30% is within the range of 95% confidence interval.
    • We cannot say that the cabinet rate for the Suga Administration is less than 30%.

    What if 300 respondents supported the Suga administration?

    prop.test(c(300), c(1214))
    
        1-sample proportions test with continuity correction
    
    data:  c(300) out of c(1214), null probability 0.5
    X-squared = 309.53, df = 1, p-value < 2.2e-16
    alternative hypothesis: true p is not equal to 0.5
    95 percent confidence interval:
     0.2232793 0.2725771
    sample estimates:
           p 
    0.247117 
    • See 95 percent confidence interval: 0.2232793 --- 0.2725771 → The true cabinet support rate in population must be smaller than 30%.
    • 30% is out of the range of 95% confidence interval.
    • We can say that the cabinet rate for the Suga Administration is less than 30%.
    参考文献
  • 宋財泫 (Jaehyun Song)・矢内勇生 (Yuki Yanai)「私たちのR: ベストプラクティスの探究」
  • 土井翔平(北海道大学公共政策大学院)「Rで計量政治学入門」
  • 矢内勇生(高知工科大学)授業一覧
  • 浅野正彦, 矢内勇生.『Rによる計量政治学』オーム社、2018年
  • 浅野正彦, 中村公亮.『初めてのRStudio』オーム社、2018年
  • Winston Chang, R Graphics Cookbook, O’Reilly Media, 2012.
  • Kieran Healy, DATA VISUALIZATION, Princeton, 2019
  • Kosuke Imai, Quantitative Social Science: An Introduction, Princeton University Press, 2017