Load the tidyverse dataset, and out dataset.
library(tidyverse)
library(pwr)
df_main <- read.csv("climate_change_dataset.csv")
df_main |> head()
#debug
names(df_main)
## [1] "Year" "Country"
## [3] "Avg.Temperature...C." "CO2.Emissions..Tons.Capita."
## [5] "Sea.Level.Rise..mm." "Rainfall..mm."
## [7] "Population" "Renewable.Energy...."
## [9] "Extreme.Weather.Events" "Forest.Area...."
Hypothesis 1: Do countries with less than average CO2 emissions have larger forest areas than countries with above average CO2 emissions?
Null Hypothesis 1: Mean forest area is equal across both groups.
Alternative Hypothesis 1: Countries with below average CO2 emissions have greater forest area.
Below we will start by creating two groups, one group with above average CO2 levels, and one with less than average CO2 emissions. Then we will carry out the Neyman Pearson test and show the results.
#create co2 based groups using the mean
#calculate mean CO2 emissions
mean_co2 <- df_main |>
summarise(avg = mean(`CO2.Emissions..Tons.Capita.`, na.rm = TRUE)) |>
pull(avg)
#create groupeing variable based on mean split
df_h1 <- df_main |>
mutate(
CO2_Group = ifelse(
`CO2.Emissions..Tons.Capita.` < mean_co2,
"Below Average CO2",
"Above Average CO2"
)
)
#chk group sizes
df_h1 |> count(CO2_Group)
#Neyman Pearson test
#we have to pick values here so set:
#alpha = 0.05
#stats power = 0.80
#mineffect size (coheen's d) = 0.3
pwr.t.test(
d = 0.3,
sig.level = 0.05,
power = 0.80,
type = "two.sample",
alternative = "greater"
)
##
## Two-sample t test power calculation
##
## n = 138.0716
## d = 0.3
## sig.level = 0.05
## power = 0.8
## alternative = greater
##
## NOTE: n is number in *each* group
#do one sided t test
t_test_h1 <- t.test(
`Forest.Area....` ~ CO2_Group,
data = df_h1,
#here we are testing if below avg CO2 burn > above CO2 burn
alternative = "greater",
var.equal = FALSE
)
t_test_h1
##
## Welch Two Sample t-test
##
## data: Forest.Area.... by CO2_Group
## t = 1.6479, df = 993.8, p-value = 0.04984
## alternative hypothesis: true difference in means between group Above Average CO2 and group Below Average CO2 is greater than 0
## 95 percent confidence interval:
## 0.001713282 Inf
## sample estimates:
## mean in group Above Average CO2 mean in group Below Average CO2
## 41.45497 39.64189
#hypoth 1 visuals
df_h1 |>
ggplot(aes(
x = CO2_Group,
y = `Forest.Area....`,
fill = CO2_Group
)) +
geom_boxplot() +
labs(
title = "Forest Area (%) by CO2 Emissions Group",
x = "CO2 Emissions Group",
y = "Forest Area (%)"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Insights:Because we see the p value is less than 0.05, we know that there is enough statistical evidence to reject the null hypothesis and conclude that there is evidence that countries with below average CO2 emissions tend to have greater forest areas. This does NOT mean we can accept the alternative hypothesis, just that there is enough statistically significant evidence to support that argument.
We also want to note the p value is exactly 0.04984 which is very close to the cutoff. This means that it barely qualifies as a significant result and the evidence is weak (although present). This could hint at a deeper truth about the dataset, perhaps there is some information overpowering other information or there is bias in the samples. Even a slight augmentation to the data (even a few more samples collect by the creator) could break this very weak relationship.
This test followed the Neyman Pearson framework because we explicitly defined alpha, power, and effect size before testing. For this hypothesis, we choose an alpha of 0.05 as it is the industry standard and used often. It represents a 5% probability of committing a type 1 error. We set statistical power to be 80%. This is also typical and indicates that there is a 20% probability that we fail to observe a true event (type 2 error). A minimum effect size for Cohen’s d = 0.3. This is perfect here because as we saw with how small our p value was, we want to ensure that we are detect very small differences. Setting a d higher then this could obscure those tiny events.
Hypothesis 2: Do countries with above average renewable resource use have fewer extreme weather events?
Null Hypothesis 2: Mean number of extreame weather events is equal between groups.
Alternative Hypothesis 2: Countries with above average renewable energy have fewer extreme weather events.
As before we will first make 2 groups, and then perform the Fisher Test. Lastly a visual will be shown to represent the data.
#create the above and below average groups
#calculate mean renewable energy use
mean_renewable <- df_main |>
summarise(avg = mean(`Renewable.Energy....`, na.rm = TRUE)) |>
pull(avg)
#create grouping variable
df_h2 <- df_main |>
mutate(
Renewable_Group = ifelse(
`Renewable.Energy....` > mean_renewable,
"Abv Avg Renewable",
"Blw Avg Renewable"
)
)
#group size chk
df_h2 |> count(Renewable_Group)
#perform one sided t test for Fisher Test
t_test_h2 <- t.test(
`Extreme.Weather.Events` ~ Renewable_Group,
data = df_h2,
#testing if abv avg renewable < blw avg renewable
alternative = "less",
var.equal = FALSE
)
t_test_h2
##
## Welch Two Sample t-test
##
## data: Extreme.Weather.Events by Renewable_Group
## t = 0.2751, df = 997.17, p-value = 0.6084
## alternative hypothesis: true difference in means between group Abv Avg Renewable and group Blw Avg Renewable is less than 0
## 95 percent confidence interval:
## -Inf 0.5377835
## sample estimates:
## mean in group Abv Avg Renewable mean in group Blw Avg Renewable
## 7.329960 7.252964
#visuals for hypoth 2
df_h2 |>
ggplot(aes(
x = Renewable_Group,
y = `Extreme.Weather.Events`,
fill = Renewable_Group
)) +
geom_boxplot() +
labs(
title = "Extreme Weather Events VS Renewable Energy Group",
x = "Renewable Energy Group",
y = "Extreme Weather Events"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
In the Fisher Test we dont define statistical power or the effect size. We use the p value to determine the evidence against the null hypothesis. Since the p value is greater than 0.05, we know that there is no significant evidence to conclude that having more rewnewable sources decreases the number of extreme weather events. So we accept the null hypothesis by saying that the number of extreme weather events across both groups that use above average renewable resources and below average renewable resources is equal.
We use an alpha value of 0.05 as it is the standard threshold value. This also maintains consistency with the first test (the context is different but the dataset is the same). We commit to the one sided test due to the nature of the hypothesis we proposed. We are interested in whether countries with higher then average renewable energy resources experience fewer extreme weather events.
If we think about this from a more abstracted perspective this result was not unexpected. Renewable energy use is local measurement and extreme weather events are fueled by global factors. It does not matter if a single country is 100% green, if its surrounding neighbors are burning fossil fuels in vast quantities. Afterall, the 100% green country still exists on the same planet as the other countries and the overarching climate of the planet is still heavily impacted by the actions of the many rather than the actions of a few.