2024-02-02
library(magrittr)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Introduction
Hypothesis Testing is a statistical method that is used to determine whether a specific theory is supported or refuted by evidence from sample data.
The example sample data that will be used is the relationship between the ozone levels and the current month by using the air quality data set.
The accepted month with the highest average levels of ozone is July however this data set will be checked to see if it supports this accepted month or not.
Plan for Hypothesis Testing
In order to determine this, the average ozone levels for each month will have to be determined.
The equation for the Average is \(\mu = {(Sum of Observations)\over Total Amount of Observations}\)
In this equation \(\mu\) is the mean/average of the sample.
Then once the average is determined, the z score will have to be determined, then the probability for the sample data will be determined using a two tailed p-value table.
Finally, the probability will be compared with the standard significance level in order to determine the result of the hypothesis testing.
Plotly Plot
First ggplot Plot
gg_plot_1 = ggplot(data = airquality, aes(x = Month, y=Ozone)) +
geom_smooth() + ggtitle("Ozone versus Month Graph")
gg_plot_1

Second ggplot Plot
gg_plot_2 = ggplot(data = airquality, aes(x = Month, y = Ozone)) +
geom_col() + ggtitle("Ozone versus Month Graph")
gg_plot_2

Calculations Part 1
ozone_airquality_calculate <- airquality
airquality %>%
group_by(Month) %>%
summarize(mean=mean(Ozone, na.rm=TRUE), standard_deviation=sd(Ozone, na.rm=TRUE))
## # A tibble: 5 × 3
## Month mean standard_deviation
## <int> <dbl> <dbl>
## 1 5 23.6 22.2
## 2 6 29.4 18.2
## 3 7 59.1 31.6
## 4 8 60.0 39.7
## 5 9 31.4 24.1
Calculations Part 2
\(\mu\) of May = 23.6 ppb
\(\mu\) of June = 29.4 ppb
\(\mu\) of July = 59.1 ppb
\(\mu\) of August = 60 ppb
\(\mu\) of September = 31.4 ppb
This data set does not support the accepted month with the highest average levels of ozone and instead supports the notion that August is the month with the highest average levels of ozone.
do average of July in calculation as x and rewrite z score, sigma
Calculations Part 3
- Now the z-score will have to be determined for this new notion that August is the month with the highest average levels of ozone.
- The equation for the z-score is \(Z\) = \({(x - \mu)\over \sigma}\)
- \(\mu\) is the mean of the sample, \(\sigma\) is the standard deviation of the sample, x is the observed value of the sample, and finally Z is the standard score of the sample.
- Since July is the accepted month with the highest average levels of ozone, x = 59.1 ppb.
- Now that August is the month that is supported for having the highest average levels of ozone \(\mu\) = 60 ppb.
- Finally, since August is the month supported by the data set it’s standard or deviation or \(\sigma\) = 39.7 ppb.
Calculations Part 4
- \(Z\) = \({(x - \mu)\over \sigma}\)
- \(Z\) = \({(59.1 ppb - 60 ppb)\over 39.7 ppb}\)
- \(Z\) = \({(-.09 ppb)\over 39.7 ppb}\)
- \(Z\) = \({-0.02267}\)
Conclusion
- Finally, the probability that this air quality data could be due to random chance must be determined.
- When I used a two tailed p-value table, I determined that the probability is p = 0.491.
- This greatly exceeds the standard signifigance level of p = 0.05.
- Due to this, the hypothesis that August is the month with the highest average levels of ozone and not the accepted month of July is rejected.
- So the accepted month with the highest average levels of ozone is still July.