title: “Global CO2 Emissions from Fossil Fuels from 1751-2010”
author: “Xavier Tuominen”
date: “2024-11-18”
output: html_document
Introduction This report provides descriptive statistics for selected columns in the data frame, with values measured in million metric tons.
#url of data
url <- "https://datahub.io/core/co2-fossil-global/r/global.csv"
#reads data from url
data <- read.csv(url)
#displays data
head(data)
## Year Total Gas.Fuel Liquid.Fuel Solid.Fuel Cement Gas.Flaring Per.Capita
## 1 1751 3 0 0 3 0 0 NA
## 2 1752 3 0 0 3 0 0 NA
## 3 1753 3 0 0 3 0 0 NA
## 4 1754 3 0 0 3 0 0 NA
## 5 1755 3 0 0 3 0 0 NA
## 6 1756 3 0 0 3 0 0 NA
mean_total <- mean(data$Total, na.rm = TRUE)
sd_total = sd(data$Total, na.rm = TRUE)
cat("The mean of total CO2 is ", mean_total, ".\n", sep = "")
## The mean of total CO2 is 1402.788.
cat("The standard deviation of total CO2 is ", sd_total, ".\n", sep = "")
## The standard deviation of total CO2 is 2253.099.
mean_total_per_capita <- mean(data$Per.Capita, na.rm = TRUE)
sd_total_per_capita = sd(data$Per.Capita, na.rm = TRUE)
cat("The mean of total CO2 per capita is ", mean_total_per_capita, ".\n", sep = "")
## The mean of total CO2 per capita is 1.054754.
cat("The standard deviation of total CO2 per capita is ", sd_total_per_capita, ".\n", sep = "")
## The standard deviation of total CO2 per capita is 0.17863.
count <- 0
max_num = nrow(data) - 1
for(i in 1:max_num)
{
if(data$Total[i] > data$Total[i+1])
{
count <- count + 1
}
}
probability <- count / nrow(data)
cat("The probability that total CO2 emissions increased is ", probability, ".\n", sep = "")
## The probability that total CO2 emissions increased is 0.1076923.
count <- 0
max_num = nrow(data) - 1
GAS_FLARING_TARGET <- 40
GAS_FUEL_TARGET <- 1000
for(i in 1:nrow(data))
{
if(data$Gas.Flaring[i] > GAS_FLARING_TARGET && data$Gas.Fuel[i] > GAS_FUEL_TARGET)
{
count <- count + 1
}
}
probability <- count / nrow(data)
cat("The probability that gas flaring emissions is over 40 and gas fuel emissions is over 1000 is ", probability, ".\n", sep = "")
## The probability that gas flaring emissions is over 40 and gas fuel emissions is over 1000 is 0.04615385.
mean_total <- mean(data$Total, na.rm = TRUE)
sd_total <- sd(data$Total, na.rm = TRUE)
confidence_level <- 0.95
sample_size <- nrow(data)
value <- qt((1 + confidence_level) / 2, sample_size)
error_margin <- value * (sd_total / sqrt(sample_size))
lower_interval <- mean_total - error_margin
upper_interval <- mean_total + error_margin
cat("Confidence intervals of total CO2 emissions with a confidence of ", confidence_level, "%. Has a lower confidence interval of: ", lower_interval, "and an upper confidence of ", upper_interval, ".\n", sep = "")
## Confidence intervals of total CO2 emissions with a confidence of 0.95%. Has a lower confidence interval of: 1127.639and an upper confidence of 1677.937.