1. Introduction
#1: Unveiling an Environmental Crisis: Analyzing Climate Change's Biggest Contributors to Combat the Future
  1. Problem Statement
#2: Comparing different factors like CO2 Emissions and Global Population; with the Temperature Anomaly and how they increase over time, showing a correlation between them
  1. Objectives
#3:  The objective of this project is to showcase climate change’s most prominent transgressors and the annual impact they have on global temperatures.
  1. Methods
##Step 1: Describe the Variables
#- Anomaly: The temperature anomaly, which is the sudden increase in overall global temperature over the last few decades.
#- CO2 Emissions: CO2(Carbon Dioxide) is a greenhouse gas, emitted from a multitude of things like cars, boats, planes, and even farm animals like cows or pigs. This gas increases the global temperature and deteriorates the ozone layer in our atmosphere.
#- Global Population: The total number of people accounted for on earth, which can influence the amount of cars and other products needed to sustain this number of people.

# µ1 = mean temperature over time
#µ2 = mean CO2 emissions over time
# µ3 = mean global population over time

## Install & Load Libraries
#install.packages("tidyr")
#install.packages("ggplot2")

library(readxl)
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.3.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
data = read_excel(file.choose())
data
## # A tibble: 72 × 4
##     Year Anomaly `Annual CO2 emissions` `Global Population`
##    <dbl>   <dbl>                  <dbl>               <dbl>
##  1  1950   -0.13                   2.37          2499322000
##  2  1951   -0.03                   2.51          2543130400
##  3  1952    0.05                   2.50          2590271000
##  4  1953    0.1                    2.52          2640278800
##  5  1954   -0.09                   2.52          2691979300
##  6  1955   -0.12                   2.71          2746072000
##  7  1956   -0.16                   2.83          2801002800
##  8  1957    0.06                   2.86          2857866800
##  9  1958    0.09                   2.89          2916108000
## 10  1959    0.07                   2.98          2970292200
## # ℹ 62 more rows
## Summarize Data
summary(data)
##       Year         Anomaly        Annual CO2 emissions Global Population  
##  Min.   :1950   Min.   :-0.1700   Min.   :2.372        Min.   :2.499e+09  
##  1st Qu.:1968   1st Qu.: 0.0575   1st Qu.:3.609        1st Qu.:3.529e+09  
##  Median :1986   Median : 0.2750   Median :4.163        Median :4.906e+09  
##  Mean   :1986   Mean   : 0.3242   Mean   :3.999        Mean   :5.008e+09  
##  3rd Qu.:2003   3rd Qu.: 0.6125   3rd Qu.:4.449        3rd Qu.:6.414e+09  
##  Max.   :2021   Max.   : 1.0300   Max.   :4.878        Max.   :7.909e+09
model <- lm(Anomaly ~ `Annual CO2 emissions` + `Global Population`, data = data)
model
## 
## Call:
## lm(formula = Anomaly ~ `Annual CO2 emissions` + `Global Population`, 
##     data = data)
## 
## Coefficients:
##            (Intercept)  `Annual CO2 emissions`     `Global Population`  
##             -3.560e-01              -1.159e-01               2.283e-10
summary(model)
## 
## Call:
## lm(formula = Anomaly ~ `Annual CO2 emissions` + `Global Population`, 
##     data = data)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.181980 -0.073034  0.006198  0.084063  0.217411 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            -3.560e-01  8.007e-02  -4.446 3.27e-05 ***
## `Annual CO2 emissions` -1.159e-01  3.193e-02  -3.630  0.00054 ***
## `Global Population`     2.283e-10  1.330e-11  17.174  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09763 on 69 degrees of freedom
## Multiple R-squared:  0.9136, Adjusted R-squared:  0.9111 
## F-statistic: 364.9 on 2 and 69 DF,  p-value: < 2.2e-16
##Step 2: Clean the Data
fittedValues = predict(model)
mape = mean(abs((data$Anomaly - fittedValues)/data$Anomaly))
mape
## [1] 0.7254913
pairs(~Anomaly + `Annual CO2 emissions`+ `Global Population`, data = data)

##Step 3: Descriptive Statistics and Visual Analysis
plot(data$Year, data$Anomaly, main = "Global Temperature Anomaly Change Over Time", xlab = "Year", ylab = "Temperature Anomaly (in Celsius)")
  abline(lm(Anomaly~Year, data = data),col='red')

##Step 4: Data Analysis
#Our MAPE is pretty high, at r round(mape, 2) %, which indicates a large variation between the residuals of our data. 
mape = mean(abs((data$Anomaly - fittedValues)/data$Anomaly))
mape
## [1] 0.7254913
coefficients <- coef(model)
coefficients
##            (Intercept) `Annual CO2 emissions`    `Global Population` 
##          -3.559752e-01          -1.159123e-01           2.283384e-10
#Our coefficients indicate that the initial temperature anomaly before any factors included is negative, and our b1, Annual CO2 emissions, is also negative, which indicates that they both contribute towards lower overal temperature anomalies. However, this matters more in context with our b2 coefficient, Global Population, which is positive and has a large factor on our data given its much larger numerical values in comparison. 

##Step 5: Statistical Assumptions
# u1≠u2≠u3
#We assume that the variables of Temperature, CO2 emissions, and global population, to not equal to each other
#We assume that the variables are independent of each other
# We assume that the relationship between temperature over time and CO2 emissions/global population is a positive linear correlation
#We assume that there is no exact linear relationship between the independent variables
  1. Interpretations
#We can interpret that increasing CO2 emissions and global population correspond to rising #temperature, in line with the greenhouse effect.
#We can interpret that each variable contributes uniquely to temperature changes.
#Both CO2 emissions and Global Population have a positive correlation with temperature #throughout the years we analyzed. 
#Both independent variables are significant as their p-values are less than alpha (0.00 for both < #alpha), which supports our claim that Annual CO2 emissions and Global Population have an #effect on temperature anomalies, and our R-squared and adjusted R-squared values are high, #91%, which indicates that our data includes most of the factors that are affecting our dependent #variable. 
  1. Conclusion & Recommendation
### Conclusion:
#As time goes forward, we can see that temperatures will increase along with greenhouse gas emissions and the global population. As a result, we can see the correlation between temperature and the independent variables included in the data.
#We also have observed that Global Greenhouse Gas Emissions and Global Population were statistically significant -> p-value < 0.05(a)

### Recommendations
#We have 3 business recommendations to provide in order to guide those who are in the environmental field.

# 1. Carpooling is an essential factor in reducing greenhouse gas emissions from cars at this point in time since it is steadily increasing. Cars are the most dominant way to travel in this day and age.

# 2. Governments need to take action to incorporate policies and rules that help reduce the amount of greenhouse gases able to be produced. This means, more EV expenditure, potential restrictions on gas somehow, and more collective policies on helping the emissions issue.

# 3. Investing in green technology is clearly one of the best decisions in the evidence of analytics and it reveals that it is essential at this point. To lessen their carbon footprint, the management must have thought about allocating funds to technologies that are eco-friendly and beneficial for all.