##Introduction Research Question: Has the average number of days above 90 degrees F changed from 1948 to 2018 at the same location?

The dataset I chose is the climate70.csv dataset, which takes a small amount of data from a set of locations in the NOAA. It has 197 cases and 7 variables. The variables are: station, latitude, longitude, dx70_1948 (days above 70F in 1948), dx70_2018 (days above 70F in 2018), dx90_1948 (days above 90F in 1948), and dx90_2018 (days above 90F in 2018. This analysis will highlight the dx90_1948 and dx_2018 variables, as the question wants to find the average 90F days from 1948 and 2018. Here is a link to the dataset, which comes from OpenIntro.org:https://www.openintro.org/data/index.php?data=climate70.

##Data Analysis For this analysis, I will be comparing the mean days above 90 degrees F in 1948 and 2018. I will be summarizing the data, creating a histogram to show the change, a boxplot comparing 1948 to 2018, and performing a paired difference in means test.

climate <- read.csv("climate70.csv")

EDA Checked the structure of the dataset and looked at a summary of each column. No cleaning needed as there are no NAs and duplicated are appropriate.

str(climate)
## 'data.frame':    197 obs. of  7 variables:
##  $ station  : chr  "USC00203823" "USC00276818" "USC00186620" "USC00331890" ...
##  $ latitude : num  41.9 44.3 39.4 40.2 37.8 ...
##  $ longitude: num  -84.6 -71.3 -79.4 -81.9 -94.4 ...
##  $ dx70_1948: int  131 80 143 156 216 138 131 194 198 213 ...
##  $ dx70_2018: int  147 99 150 158 175 132 129 188 240 213 ...
##  $ dx90_1948: int  11 1 4 18 59 39 23 17 46 67 ...
##  $ dx90_2018: int  16 1 1 15 51 18 17 3 65 104 ...
summary(climate)
##       station       latitude        longitude         dx70_1948    
##  Length   :197   Min.   :-35.16   Min.   :-154.91   Min.   :  3.0  
##  N.unique :182   1st Qu.: 37.32   1st Qu.:-101.61   1st Qu.:117.0  
##  N.blank  :  0   Median : 41.64   Median : -90.88   Median :149.0  
##  Min.nchar: 11   Mean   : 40.85   Mean   : -78.78   Mean   :157.7  
##  Max.nchar: 11   3rd Qu.: 45.20   3rd Qu.: -79.44   3rd Qu.:197.0  
##                  Max.   : 65.49   Max.   : 147.46   Max.   :365.0  
##    dx70_2018       dx90_1948        dx90_2018     
##  Min.   :  8.0   Min.   :  0.00   Min.   :  0.00  
##  1st Qu.:131.0   1st Qu.:  5.00   1st Qu.: 10.00  
##  Median :149.0   Median : 23.00   Median : 19.00  
##  Mean   :161.8   Mean   : 32.35   Mean   : 35.24  
##  3rd Qu.:188.0   3rd Qu.: 47.00   3rd Qu.: 58.00  
##  Max.   :360.0   Max.   :163.00   Max.   :186.00
colSums(is.na(climate))
##   station  latitude longitude dx70_1948 dx70_2018 dx90_1948 dx90_2018 
##         0         0         0         0         0         0         0
sum(duplicated(climate))
## [1] 15

Made a new dataset climate90 with new variable change90, which shows change in average from 1948 to 2018. Selected only the needed variables in new set, and summarized the mean in 1948, 2018, and change90.

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
climate90 <- climate |> mutate( change90 = dx90_2018 - dx90_1948) |> select(station, dx90_2018, dx90_1948, change90) 
climate90 |> 
  summarise(
  mean1948 = mean(dx90_1948),
  mean2018 = mean(dx90_2018),
  mean_change = mean(change90)
)
##   mean1948 mean2018 mean_change
## 1 32.34518 35.24365    2.898477

Visualization

hist(climate90$change90,
     main = "Change in Days over 90°F( 2018 - 1948)",
     xlab = "Days over 90*F",
     ylab = "Frequency"
     )

boxplot(
  climate90$dx90_1948,
  climate90$dx90_2018,
  names = c("1948","2018"),
  main = "Days above 90°F by year",
  ylab = "Number of Days above 90°F"
)

##Statistical Analysis I will be using a paired difference in means test to find out if there was a change in the average number of days above 90°F from 1948 to 2018.

#Hypothesis: \[ Null: H_0: \mu_{1948} = \mu_{2018} \]

\[ Alternative: H_1: \mu_{1948} \neq \mu_{2018} \]

t.test(
  climate90$dx90_2018,
  climate90$dx90_1948,
  paired = TRUE,
  alternative = "two.sided",
  conf.level = 0.95
)
## 
##  Paired t-test
## 
## data:  climate90$dx90_2018 and climate90$dx90_1948
## t = 2.3702, df = 196, p-value = 0.01875
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  0.4868224 5.3101319
## sample estimates:
## mean difference 
##        2.898477

This paired t-test being used to compare number of days above 90°F in 1948 and 2018 was useful. The results show that t = 2.37, df = 196, and the p-value = 0.01875. Seeing as the p-value is less than aplha, 0.01875 < 0.05, then the null hypothesis should be rejected. There is enough evidence to say that the average days above 90°F changed from 1948 to 2018, with an average of 2.9 more days over 90°F in 2018 than 1948.

##Conclusion and Further Directions I can conclude that the research question was properly answered, and that there was an increase in the number of days above 90°from 1948 to 2018. The histogram showed that most weatheer stations had relatively small changes in the number of days above 90°F from 1948 to 2018 since the data is mostly gathered around 0. The boxplot showed that the mean days above 90°F in 2018 was higher than the mean in 1948 even before a statistical test. The paired t-test gave us reason to reject the null hypothesis since the p-value of 0.01875 was less than the alpha of 0.05. The test concluded that there was an average of 2.9 more days above 90°F in 2018 than 1948, answering the research question. This analysis could be used in the future to analyze more detailed datasets on the trends of high temperature days to be more compreshensive. It could also be used to find if there is any positive correlations between the known causes of climate change (green houser gases, air pollution, deforestation, etc.).

##References OpenIntro.org. climate70: Temperature Summary Data, Geography Limited. https://www.openintro.org/data/index.php?data=climate70