3/26/2020

What is Hypothesis Testing?

Hypothesis testing is the process by which an alternate hypothesis is tested and compared against an initial null hypothesis.

This null hypothesis is only rejected when the probability (p-value) falls below a predetermined significance level (α).

The p-value is the probability of obtaining a sample statistic as different or more different from the parameter specified in the null hypothesis, given that the null hypothesis is true.

The significiance value is the highest level at which the null hypothesis is rejected.

Types of Hypothesis Testing

The most common types of hypothesis testing are:

  1. Z test: Used to validate that a sample belongs to a given population.

  2. T test: Used to compare the means of two given samples.

  3. Chi-Square test: Used to compare categorical variables.

These tests can be performed on any basic TI calculator. The formulas for conducting the tests are given in a future slide.

Process For Conducting a Hypothesis Test

  1. State your initial claims: what is the null hypothesis, and what is the alternate hypothesis.
  2. Specify your significance level, α. This value is usually 0.05.
  3. Identify the critical value.
  4. Calculate the value of the test statistic.
  5. Compute the probability value, or the p-value.
  6. Draw a conclusion about the null hypothesis.

Formulae for Hypothesis Testing

   Z-test:

\[ z = {\bar{x} - \mu \over {\sigma \over \sqrt{n}}} \]

   T-test:

\[ t = {\bar{x} - \mu \over {s \over \sqrt{n}}} \]

   χ2-test:

\[ \chi_c^2 = {\sum{(O_i - E_i)^2 \over E_i}} \\ O = \text{observed value(s)} \\ E = \text{expected value(s)} \\ c = \text{degrees of freedom} \]

Type I, Type II Errors, and Power

  • Type I Error: occurs when one rejects the null hypothesis despite it being true; this value is equal to the significance level, α.
  • Type II Error: occurs when one does not reject the null hypothesis despite it being false; this value is known as β.
  • Power: the power of a test is the probability of rejecting the null hypothesis when it is false; power = 1 - β.

Example Hypothesis Test

Blood glucose levels for obese patients have a mean of 100 with a standard deviation of 15. A researcher thinks that a diet high in raw cornstarch will have a positive or negative effect on blood glucose levels. A sample of 30 patients who have tried the raw cornstarch diet have a mean glucose level of 140. Test the hypothesis that the raw cornstarch had an effect.

\(\text{Null Hypothesis:}\;H_o: \mu = 100\)
\(\text{Alternate Hypothesis:}\;H_A: \mu \neq 100\)

\(\text{Significance Level:}\;\alpha = 0.05\)
\(\text{Because this is a two-tailed test, divide alpha level by 2:}\;{\alpha \over 2} = 0.025\)
\(\text{Z-score for this}\;\alpha\;\text{level:}\;1.96\)
\(\text{Compute the test statistic:}\)

\(Z = {{\bar{x} - \mu_0} \over {\sigma \over \sqrt{n}}}\)
\(Z = {(140 - 100) \over {15 \over {\sqrt{30}}}} = 14.60\)

\[\text{Because the test statistic is greater than 1.96, there is sufficient evidence to}\;\textit{reject}\\\;\text{the null hypothesis.}\; \text{Hence, we can conclude that there is sufficient evidence}\;\\\text{that raw cornstarch has an effect on the blood sugar of obese patients.}\]

Normal Distribution Plot where the Z-score is Calculated

T-Test Example

Determine whether the sample mean, $330.6, indicates that this year’s average energy cost is significantly different from last year’s average energy cost of $260.

##      Variable Total.Count  Mean SE.Mean StDev
## 1 Energy Cost          25 330.6    30.8 154.2

Our sample mean, 330.6, falls within the critical region, which indicates that it is statistically significant at the 0.05 level. The p-value for this problem is 0.03112. This represents the likelihood of obtaining a sample mean that is as extreme as the sample mean in both tails of the distribution.

Code For The Last Slide

df <- data.frame("Variable" = "Energy Cost",
                 "Total Count"= 25,
                 "Mean" = 330.6,
                 "SE Mean" = 30.8,
                 "StDev" = 154.2)
head(df)

custom <- function(x) {dt((x - 260) / 44, 24)}
ggplot(data.frame(x = c(120, 400)), aes(x = x)) +
  stat_function(fun = custom) +
    # stat_function(fun = dt, args = list(df = 24))
  scale_x_continuous(breaks = seq(110,410,30)) +
  stat_function(fun = custom,
                aes(fill = "0.025"),
                xlim = c(120,196),
                geom = "area") +
  stat_function(fun = custom,
                aes(fill = "0.025"),
                xlim = c(324,400),
                geom = "area") +
  geom_vline(xintercept = 330.6, size = 0.8) +
  geom_text(aes(x = 343, label = "330.6", y = 0.2)) + 
  ggtitle("Two-Tailed Critical Region for a Significance Level of 0.05")

Demonstration of \(\LaTeX\) Math

\(\text{Proof of Binomial Theorem:}\) \(\text{Proof by Induction:}\) \[ (a+b)^n = \sum_{k=0}^n {n \choose k} x^{n - k} y^k \] \[ = ({n \choose 0} a^nb^0 + {n \choose 1}a^{n-1}b^1 + {n \choose 2}a^{n-2}b^2 +...+{n \choose n}a^0b^n)(a + b) \] \[ = ({n \choose 0} a^{n+1}b^0 + {n \choose 1}a^{n}b^1 + {n \choose 2}a^{n-1}b^2 +...+{n \choose n}a^1b^n) + ({n \choose 0} a^nb^1 + {n \choose 1}a^{n-1}b^2 + {n \choose 2}a^{n-2}b^3 +...+{n \choose n}a^0b^{n+1}) \] \[ = ({n \choose 0} a^{n+1}b^0 + ({n \choose 0} + {n \choose 1}) (a^{n}b^1) + ({n \choose 1} + {n \choose 2})(a^{n-1}b^2)\;+... +\;({n \choose {n - 1}} + {n \choose n})(a^1b^n)\;+ {n \choose n}a^0b^{n+1})\] \[ = {n + 1 \choose 0}a^{n+1}b^0 + {n+1 \choose 1}a^nb^1 + {n + 1 \choose 2}a^{n-1}b^2 +...+{n +1 \choose n}a^1b^n + {n + 1 \choose n + 1}a^0b^{n + 1} \] \[ = \sum_{k=0}^{n+1}{n+1 \choose k}a^{(n+1) -k}b^k \]

The theorem holds under \(n + 1\), so it must be valid.

3D Plot of Coronavirus Cases: Total Cases vs. Deaths vs. Recoveries