2025-06-05

\[Reasoning\ and\ Explanation\]

What is hypothesis testing?

Hypothesis testing is a process done in Statistics to determine
if a data set behaves the way we expect.

Why is hypothesis testing done?

Hypothesis testing is done to determine if a parameter is acting as
expected, or if there is a significant difference in how it behaves.

\[Creating\ a\ Hypothesis\] To create a hypothesis, first, we need data. For this example I will use the CO2 data set, which measures the carbon dioxide uptake in chilled and nonchilled plants. With a data set, we now create a null hypothesis and an alternative hypothesis.

The null hypothesis should state that a parameter should have no effect
on another parameter. For example, chilling the plants should have noeffect
on the uptake. I can measure this by taking the mean of the differences in 
uptake, and I would expect this value to be zero, which is written 

\[H_0: \mu=0\] in Statistics.

\[Alternative\ Hypothesis\]

The alternative hypothesis states that a parameter will have an effect on another. For the example, we’d expect the mean of differences between chilled and nonchilled plants to be any other value, which is written \[H_a: \mu \neq 0\] In Statistics.

\[Test\ of\ Significance\]

To test the hypotheses, we must do a test of significance. This is a procedure that compares the data with our claim. The test of significance for a mean requires us to make a test statistic called z. The formula for z is: \[z = {estimate - hypothesized\ value \over standard\ deviation}\ or\ {\bar{x} -\mu_0\over \sigma / \sqrt{n}}\] The square root dividing the standard deviation is due to the expectation that we take a random sample from our data.

\[Calculations\] Now we perform all calculations to get to the test statistic (z).

p1 = filter(CO2, Treatment == 'nonchilled')
p2 = filter(CO2, Treatment == 'chilled')
p3 = mutate(p1, nch_uptake = uptake) %>% mutate(p2, ch_uptake = uptake)
p3 = mutate(p3, Differences = nch_uptake - ch_uptake)

example = sample(p3$Differences, 24)

stan_dev = sd(example) 

mean = mean(example)

z = (mean - 0) / (stan_dev / sqrt(24))

z =

## [1] 6.167897

\[P-Value\] With our test statistic or z-value we can figure out if the calculated value is significant or not. We do this by calculating a P-Value; a probability of how likely our event is to happen.

Level of Significance: We must determine a value for which the P-value must be smaller. We’ll use the value 0.05 as it is the most common.

To determine the P-Value we must first plot the distribution of our parameter to see if it is normal.

\[Normal\ Distribution\] As seen in the graph on the last slide, our distribution is not normal, If it was normal it’d look like this:

\[Not\ Normal,\ What\ Now?\] Since our distribution is not normal we cannot obtain a P-Value. We’d need to take more random samples and get a larger data set. For practice, let’s see what the p-value would have been if the distribution was normal. To do that we need to go back to our alternative hypothesis. It was \(H_a: \mu \neq 0\)

Our alternative hypothesis is two-sided, because it expects that the mean
is any number other than the predicted one. This means the P-Value is equal
to: 

\(P(Z\leq z\ or\ Z\geq z) = 2P(Z\geq z)\)

A one-sided hypothesis expects the mean to be a number either greater than
or less than the predicted. The P-Value would be equal to either 

\(P(Z\leq z)\) or \(P(Z\geq z)\)

\[P-Value\ and\ Visualization\] Our P-Value will equal the area under the normal curve at z and -z.