2024-04-05

Hypothesis Testing Basics

⬩A statistical test to see if a particular hypothesis is sufficiently supported by data

⬩Null Hypothesis (H0): Statement being tested

⬩Alternative Hypothesis (H1): Statement to be adopted in the event H0 is rejected

⬩P-value: Under the assumption of the null hypothesis, the probability of obtaining a result equal to or more extreme than what was actually observed

⬩We will reject or fail to reject the null hypothesis based on the p-value

T-Value

A t-value is used when the variance within a population is unknown.

\(t = \frac{\bar{x} - \mu}{\frac{s}{\sqrt{n}}}\)

where \(\bar{x}\) = sample mean, \(\mu\) = assumed mean, s = sample standard deviation, and n = sample size.

Z-Value

A z-value is used when variance is known.

\(z_\bar{x} = \frac{\bar{x} - \mu}{\frac{\sigma}{\sqrt{n}}}\)

where \(\bar{x}\) = sample mean, \(\mu\) = assumed mean, \(\sigma\) = population standard deviation, and n = sample size.

Single Tail

A single-tail analysis is used when the null hypothesis uses a statement of ‘greater than’ or ‘less than’

Two Tails

Two tails are used when the null hypothesis uses a statement of ‘equal to’ or ‘not equal to’

Example

This is an example using miles per gallon by transmission type from R’s mtcars data set. We are using α = 0.95 (95% confidence) with a null hypothesis that MPG is the same for both transmission types.

t.test(mtcars$mpg~mtcars$am, mu=0, conf.level = 0.95,
       alternative = "two.sided", var.equal=F)
    Welch Two Sample t-test

data:  mtcars$mpg by mtcars$am
t = -3.7671, df = 18.332, p-value = 0.001374
alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
95 percent confidence interval:
 -11.280194  -3.209684
sample estimates:
mean in group 0 mean in group 1 
       17.14737        24.39231 

Since the P-value is less than 0.05 (that is, 1 - α), we reject the null hypothesis.

Errors

Type I errors occur when a null hypothesis is rejected that is actually true in the population. Type II errors occur when an investigator fails to reject a null hypothesis that is actually false in the population.

One way to lessen the probability of producing type I and II errors is to use a larger sample size. A large sample is less likely to significantly differ from the population. The plot below illustrates how using fewer observations could lead to such an error. We can see that the difference in mean MPG by transmission type becomes more pronounced with a larger sample.