#Install
#install.packages("tidyverse")
#Libraries
library(tidyverse)
library(psych)
library(readr)
library(ggplot2)
library(purrr)
library(scales)
library(dplyr)
#Read File
dataRDU<- read_delim("rdu-weather-history.csv", ";", escape_double = FALSE, trim_ws = TRUE)
Rows: 1977 Columns: 7── Column specification ───────────────────────────────────────────────────────────────────
Delimiter: ";"
dbl (6): tmin, tmax, prcp, snow, snwd, awnd
date (1): date
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(dataRDU)
#Summarize Data
summary(dataRDU)
date tmin tmax prcp snow
Min. :2017-01-01 Min. : 4.00 Min. : 27.0 Min. :0.0000 Min. :0.00000
1st Qu.:2018-05-10 1st Qu.:37.00 1st Qu.: 60.0 1st Qu.:0.0000 1st Qu.:0.00000
Median :2019-09-16 Median :52.00 Median : 74.0 Median :0.0000 Median :0.00000
Mean :2019-09-16 Mean :51.09 Mean : 72.3 Mean :0.1358 Mean :0.01284
3rd Qu.:2021-01-22 3rd Qu.:66.00 3rd Qu.: 86.0 3rd Qu.:0.0600 3rd Qu.:0.00000
Max. :2022-05-31 Max. :78.00 Max. :102.0 Max. :4.9600 Max. :7.00000
snwd awnd
Min. :0.00000 Min. : 0.000
1st Qu.:0.00000 1st Qu.: 3.800
Median :0.00000 Median : 5.800
Mean :0.01695 Mean : 6.075
3rd Qu.:0.00000 3rd Qu.: 7.800
Max. :5.90000 Max. :20.360
NA's :1 NA's :4
#Hypothesis #1
dataRDU$date <- as.Date(dataRDU$date)
dataRDU$year <- as.numeric(format(dataRDU$date, "%Y"))
average_temperatures <- dataRDU %>%
group_by(year) %>%
summarize(avg_tmin = mean(tmin, na.rm = TRUE),
avg_tmax = mean(tmax, na.rm = TRUE))
#Line Plot Comparison
ggplot(average_temperatures, aes(x = year)) +
geom_line(aes(y = avg_tmin), color = "blue") +
geom_line(aes(y = avg_tmax), color = "red") +
xlab("Year") +
ylab("Average Temperature (F)") +
ggtitle("Trend in Average Daily Temperatures Over the Years")
#Hypothesis #2
dataRDU <- dataRDU %>%
mutate(next_day_tmin = lag(tmin))
ggplot(dataRDU, aes(x = prcp, y = next_day_tmin)) +
geom_point() +
xlab("Precipitation (Millimeters)") +
ylab("Next Day's Minimum Temperature (Degrees)") +
ggtitle("Hypothesis #2") +
geom_smooth(method = "lm", se = FALSE, color = "blue")
#Hypothesis #3
dataRDU$date <- as.Date(dataRDU$date)
dataRDU$month <- as.integer(format(dataRDU$date, "%m"))
average_wind_speed <- dataRDU %>%
group_by(month) %>%
summarize(avg_awnd = mean(awnd, na.rm = TRUE))
#Plot
ggplot(average_wind_speed, aes(x = month, y = avg_awnd)) +
geom_line() +
xlab("Month") +
ylab("Average Wind Speed (Knots)") +
ggtitle("Seasonal Variations in Wind Speed") +
scale_x_continuous(breaks = 1:12, labels = month.abb)
#Hypothesis #4
event_subset <- dataRDU %>%
filter(prcp == 1)
no_event_subset <- dataRDU %>%
filter(prcp == 0)
#T-Test
t_test_result <- t.test(event_subset$awnd, no_event_subset$awnd, var.equal = FALSE)
t.test(event_subset$awnd, no_event_subset$awnd)
Welch Two Sample t-test
data: event_subset$awnd and no_event_subset$awnd
t = -0.79095, df = 1.0095, p-value = 0.573
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-14.83996 13.06405
sample estimates:
mean of x mean of y
4.700000 5.587956
cat(t_test_result$t.statistic)
cat("p-value:", t_test_result$p.value, "\n")
p-value: 0.5729674
cat("t-statistic:", t_test_result$statistic, "\n")
t-statistic: -0.7909505
maxTempWind <- select(dataRDU, c("awnd", "tmax"))
pairs(maxTempWind)
ggplot(data = dataRDU, mapping = aes(x = awnd,
y = tmax))+
geom_point()
ggplot(data = dataRDU, mapping = aes(x = awnd,
y = tmax))+
geom_line()
ggplot(data = dataRDU, mapping = aes(x = awnd,
y = tmax))+
geom_line()+
labs(title = "Effect of Temperature(Degrees) on Wind Speed(Knots)",
subtitle = "Source: fedesoriano. (April 2022). Wind Speed Prediction Dataset.",
x= "Wind Speed in Knots",
y= "Maximum Temperature in Degrees Degrees")
ggplot(data = dataRDU, mapping = aes(x = awnd,
y = tmax))+
geom_smooth()+
labs(title = "Effect of Temperature(F) on Wind Speed(Kt)",
x= "Wind Speed in Knots",
y= "Maximum Temperature in Degrees ")
avgTempMax<- mean(dataRDU$tmax)
avgTempMax
[1] 72.29894
avgTempMin <- mean(dataRDU$tmin)
avgTempMin
[1] 51.08801