# Research Analysis
# Correllation analysis
# Correlation with NO2 ----------------------------------------------------

# Step 1: Install and load necessary packages
if (!requireNamespace("scales", quietly = TRUE)) install.packages("scales")
if (!requireNamespace("ggplot2", quietly = TRUE)) install.packages("ggplot2")
if (!requireNamespace("officer", quietly = TRUE)) install.packages("officer")
if (!requireNamespace("magrittr", quietly = TRUE)) install.packages("magrittr")
if (!requireNamespace("svglite", quietly = TRUE)) install.packages("svglite")
if (!requireNamespace("rsvg", quietly = TRUE)) install.packages("rsvg")

# Load libraries
library(scales)
library(ggplot2)
library(officer)
library(magrittr)
library(svglite)
library(rsvg)

# Step 2: Read and clean the data
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")

# Convert potentially problematic columns to numeric to handle possible conversion failures which result in NAs
data$cases <- as.numeric(as.character(data$cases))
data$meanNO2 <- as.numeric(as.character(data$meanNO2))

# Remove rows with NA values in the columns of interest to ensure clean data for analysis
data <- data |> 
  filter(!is.na(cases) & !is.na(meanNO2))

# Inspect data to ensure it's ready for plotting
summary(data$cases)
summary(data$meanNO2)
unique(data$Date)  # Ensure the Date column is as expected

# Step 3: Perform correlation analysis
pearson_correlation <- cor(data$cases, data$meanNO2, method = "pearson")
spearman_correlation <- cor(data$cases, data$meanNO2, method = "spearman")
kendall_correlation <- cor(data$cases, data$meanNO2, method = "kendall")

# Print the correlation results
cat("Pearson Correlation: ", pearson_correlation, "\n")
cat("Spearman Correlation: ", spearman_correlation, "\n")
cat("Kendall Correlation: ", kendall_correlation, "\n")

# Step 4: Create the plot (first without faceting to diagnose any issues)
p <- ggplot(data, aes(x = cases, y = meanNO2)) +
  geom_point(color = "grey30", size = 0.5, shape = 21, fill = "white", stroke = 0.5) +  
  geom_smooth(method = "lm", col = "blue") +
  theme_bw() +
  labs(title = "Correlation Analysis\nThe under 5 URTI cases and the mean Nitrogen dioxide pollutant, 2020-2022",
       subtitle = paste("Pearson:", round(pearson_correlation, 3), 
                        "| Spearman:", round(spearman_correlation, 3), 
                        "| Kendall:", round(kendall_correlation, 3)),
       #caption = "Data sourced from TROPOMI/Sentinel-5P. Analysis conducted using R. \nData cleaning involved removal of NAs and normalization where necessary.\nAuthor; Kipterer John Kapoi@2024",
       x = "Under 5 URTI Cases",
       y = "Mean Nitrogen dioxide")

# Display the plot without faceting
print(p)

# If the plot works without faceting, try faceting again
p <- p + facet_wrap(~ Date, ncol = 12)

# Display the faceted plot
print(p)

# Step 5: Save the plot as an SVG file
#ggsave("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/NO2_plot2.PNG", plot = p, width = 8, height = 6, dpi = 300)

# Step 6: Create and save the PowerPoint presentation with the plot
# Create a new PowerPoint presentation
ppt <- read_pptx()

# Add a new slide with the title and content layout
ppt <- add_slide(ppt, layout = "Title and Content", master = "Office Theme")

# Add the SVG plot to the slide
ppt <- ppt %>%
  ph_with(value = external_img("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/NO2_plot.svg", 
                               width = 8, height = 6), 
          location = ph_location_fullsize())

# Save the PowerPoint presentation
print(ppt, target = "C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/NO2_plot_presentation2.pptx")


#----------------------------------------------------------

## Load required libraries
library(officer)
library(ggplot2)
library(magrittr)

# Reading the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")

# Convert potentially problematic columns to numeric to handle possible conversion failures which result in NAs
data$cases <- as.numeric(as.character(data$cases))
data$meanNO2 <- as.numeric(as.character(data$meanNO2))

# Remove rows with NA values in the columns of interest to ensure clean data for analysis
data <- data %>%
  filter(!is.na(cases) & !is.na(meanNO2))

# Adding an artificial grouping variable for faceting based on the number of cases
data$group <- as.factor((seq_along(data$cases) - 1) %% 12 + 1)

# Perform correlation analysis
pearson_correlation <- cor(data$cases, data$meanNO2, method = "pearson")
spearman_correlation <- cor(data$cases, data$meanNO2, method = "spearman")
kendall_correlation <- cor(data$cases, data$meanNO2, method = "kendall")

# Print the correlation results
cat("Pearson Correlation: ", pearson_correlation, "\n")
cat("Spearman Correlation: ", spearman_correlation, "\n")
cat("Kendall Correlation: ", kendall_correlation, "\n")

# Visualize the correlation with a scatter plot
p <- ggplot(data, aes(x = cases, y = meanNO2)) +
  geom_point(color = "grey30", size = 1.5, shape = 21, fill = "white", stroke = 0.5) +  # Add white outline
  geom_smooth(method = "lm", col = "blue") +
  theme_bw() +
  labs(title = "Correlation Analysis\nThe under 5 URTI cases and the mean Nitrogen dioxide pollutant, 2020-2022",
       subtitle = paste("Pearson:", round(pearson_correlation, 3), 
                        "| Spearman:", round(spearman_correlation, 3), 
                        "| Kendall:", round(kendall_correlation, 3)),
       #caption = "Data sourced from TROPOMI/Sentinel-5P. Analysis conducted using R. \nData cleaning involved removal of NAs and normalization where necessary.\nAuthor; Kipterer John Kapoi@2024",
       x = "Under 5 URTI Cases",
       y = "Mean Nitrogen dioxide") +
  facet_wrap(~ Date, ncol = 12)  # Adjusted for proper faceting by group

# Display the plot
print(p)

# Save the plot as a PNG image
ggsave("correlation_plot.png", plot = p, width = 10, height = 6)

# Create a PowerPoint presentation
ppt <- read_pptx()

# Add a slide with title and content
ppt <- ppt %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_with_text(type = "title", str = "Correlation Analysis Output") %>%
  ph_with_text(type = "body", str = paste("Pearson Correlation:", round(pearson_correlation, 3))) %>%
  ph_with_text(type = "body", str = paste("Spearman Correlation:", round(spearman_correlation, 3)), append = TRUE) %>%
  ph_with_text(type = "body", str = paste("Kendall Correlation:", round(kendall_correlation, 3)), append = TRUE)

# Add a slide with the plot
ppt <- ppt %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_with_img(type = "body", src = "correlation_plot.png", width = 7, height = 4)

# Save the PowerPoint presentation
print(ppt, target = "Correlation_Analysis_Output.pptx")





# Correlation with SO2 ----------------------------------------------------
library(tidyverse)

# Reading the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")

# Convert potentially problematic columns to numeric to handle possible conversion failures which result in NAs
data$cases <- as.numeric(as.character(data$cases))
data$meanCO <- as.numeric(as.character(data$meanSO2))

# Remove rows with NA values in the columns of interest to ensure clean data for analysis
data <- data %>%
  filter(!is.na(cases) & !is.na(meanSO2))

# Adding an artificial grouping variable for faceting based on the number of cases (if it makes sense, otherwise choose another method)
data$group <- as.factor((seq_along(data$cases) - 1) %% 12 + 1)

# Perform correlation analysis
pearson_correlation <- cor(data$cases, data$meanSO2, method = "pearson")
spearman_correlation <- cor(data$cases, data$meanSO2, method = "spearman")
kendall_correlation <- cor(data$cases, data$meanSO2, method = "kendall")

# Print the correlation results
cat("Pearson Correlation: ", pearson_correlation, "\n")
cat("Spearman Correlation: ", spearman_correlation, "\n")
cat("Kendall Correlation: ", kendall_correlation, "\n")

# Visualize the correlation with a scatter plot
p <- ggplot(data, aes(x = cases, y = meanSO2)) +
  geom_point(color = "grey30", size = 1.5, shape = 21, fill = "white", stroke = 0.5) +  # Add white outline
  geom_smooth(method = "lm", col = "blue") +
  theme_bw() +
  labs(title = "Correlation Analysis\nThe under 5 URTI cases and the mean Sulphur dioxide pollutant, 2020-2022",
       subtitle = paste("Pearson:", round(pearson_correlation, 3), 
                        "| Spearman:", round(spearman_correlation, 3), 
                        "| Kendall:", round(kendall_correlation, 3)),
      # caption = "Data sourced from TROPOMI/Sentinel-5P. Analysis conducted using R. \nData cleaning involved removal of NAs and normalization where necessary.\nAuthor; Kipterer John Kapoi@2024",
       x = "Under 5 URTI Cases",
       y = "Mean Sulphur dioxide") +
  facet_wrap(~ Date, ncol = 12)  # Adjusted for proper faceting by group

# Display the plot
print(p)

# Correlation with mean CO ------------------------------------------------

library(tidyverse)


# Reading the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")

# Convert potentially problematic columns to numeric to handle possible conversion failures which result in NAs
data$cases <- as.numeric(as.character(data$cases))
data$meanCO <- as.numeric(as.character(data$meanCO))

# Remove rows with NA values in the columns of interest to ensure clean data for analysis
data <- data |> 
  filter(!is.na(cases) & !is.na(meanCO))

# Adding an artificial grouping variable for faceting based on the number of cases (if it makes sense, otherwise choose another method)
data$group <- as.factor((seq_along(data$cases) - 1) %% 12 + 1)

# Perform correlation analysis
pearson_correlation <- cor(data$cases, data$meanCO, method = "pearson")
spearman_correlation <- cor(data$cases, data$meanCO, method = "spearman")
kendall_correlation <- cor(data$cases, data$meanCO, method = "kendall")

# Print the correlation results
cat("Pearson Correlation: ", pearson_correlation, "\n")
cat("Spearman Correlation: ", spearman_correlation, "\n")
cat("Kendall Correlation: ", kendall_correlation, "\n")

# Visualize the correlation with a scatter plot
ggplot(data, aes(x = cases, y = meanCO)) +
  geom_point(color = "grey30", size = 1.5, shape = 21, fill = "white", stroke = 0.5) +  # Add white outline
  geom_smooth(method = "lm", col = "blue") +
  theme_bw() +
  labs(title = "Correlation Analysis\nThe under 5 URTI cases and the mean Carbon Monoxide pollutant, 2020-2022",
       subtitle = paste("Pearson:", round(pearson_correlation, 3), 
                        "| Spearman:", round(spearman_correlation, 3), 
                        "| Kendall:", round(kendall_correlation, 3)),
       #caption = "Data sourced from TROPOMI/Sentinel-5P. Analysis conducted using R. \nData cleaning involved removal of NAs and normalization where necessary.\nAuthor; Kipterer John Kapoi@2024",
       x = "Under 5 URTI Cases",
       y = "Mean Carbon Monoxide") +
  facet_wrap(~ Date, ncol = 12)  # Adjusted for proper faceting by group

# Display the plot
print(p)


# # Correlation with mean AOD  ------------------------------ --------

library(tidyverse)

# Reading the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")

# Convert potentially problematic columns to numeric to handle possible conversion failures which result in NAs
data$cases <- as.numeric(as.character(data$cases))
data$meanCO <- as.numeric(as.character(data$meanAOD))

# Remove rows with NA values in the columns of interest to ensure clean data for analysis
data <- data %>%
  filter(!is.na(cases) & !is.na(meanAOD))

# Adding an artificial grouping variable for faceting based on the number of cases (if it makes sense, otherwise choose another method)
data$group <- as.factor((seq_along(data$cases) - 1) %% 12 + 1)

# Perform correlation analysis
pearson_correlation <- cor(data$cases, data$meanAOD, method = "pearson")
spearman_correlation <- cor(data$cases, data$meanAOD, method = "spearman")
kendall_correlation <- cor(data$cases, data$meanAOD, method = "kendall")

# Print the correlation results
cat("Pearson Correlation: ", pearson_correlation, "\n")
cat("Spearman Correlation: ", spearman_correlation, "\n")
cat("Kendall Correlation: ", kendall_correlation, "\n")

# Visualize the correlation with a scatter plot
p <- ggplot(data, aes(x = cases, y = meanAOD)) +
  geom_point(color = "grey30", size = 1.5, shape = 21, fill = "white", stroke = 0.5) +  # Add white outline
  geom_smooth(method = "lm", col = "blue") +
  theme_bw() +
  labs(title = "Correlation Analysis\nThe under 5 URTI cases and the mean AOD pollutant, 2020-2022",
       subtitle = paste("Pearson:", round(pearson_correlation, 3), 
                        "| Spearman:", round(spearman_correlation, 3), 
                        "| Kendall:", round(kendall_correlation, 3)),
       #caption = "Data sourced from MODIS. Analysis conducted using R. \nData cleaning involved removal of NAs and normalization where necessary.\nAuthor; Kipterer John Kapoi@2024",
       x = "Under 5 URTI Cases",
       y = "Mean Aerosol Oprical Depth") +
  facet_wrap(~ Date, ncol = 12)  # Adjusted for proper faceting by group

# Display the plot
print(p)


# Seasonal decomposition for NO2 and cases --------------------------------

# Load necessary libraries
library(tidyverse)
library(forecast) # For STL decomposition and forecasting functions, if needed in other parts

# Reading and preparing the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")
data$Date <- as.Date(data$Date) # Convert 'Date' to Date format

# Assume a relationship for secondary axis scaling (adjust based on actual data)
scale_factor <- max(data$cases) / max(data$meanNO2)

# Create a plot with NO2 levels, cases, and secondary axis for 'cases'
p <- ggplot(data, aes(x = Date)) +
  geom_line(aes(y = meanNO2, color = "NO2 Levels")) + # NO2 levels
  geom_point(aes(y = meanNO2, color = "NO2 Levels")) +
  geom_line(aes(y = cases / scale_factor, color = "Cases")) + # Cases adjusted by scale factor
  geom_point(aes(y = cases / scale_factor, color = "Cases")) +
  scale_y_continuous(sec.axis = sec_axis(~ . * scale_factor, name = "Cases")) +
  scale_color_manual(values = c("NO2 Levels" = "blue", "Cases" = "red"), name = "Data Type") +
  labs(title = "NO2 Levels and Cases Over Time",
       subtitle = "An analysis of NO2 levels and case counts from 2020 to 2022",
       #caption = "Data source: KHIS2 and TROPOMI/Sentinel-5P\nAnalysis by: Kipterer John Kapoi\n Date: April 2024",
       x = "Date", y = "Level") +
  theme_bw() +
  
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1, color = "black", size = 12),
        axis.text.y = element_text(color = "black", size = 12), # Make y-axis values black and legible
        axis.title.x = element_text(color = "black", size = 14), # Make x-axis title black and legible
        axis.title.y = element_text(color = "black", size = 14), # Make y-axis title black and legible
        legend.position = "bottom", # Position the legend at the bottom
        legend.text = element_text(size = 12), # Increase legend text size
        legend.title = element_text(size = 14))  # Increase legend title size

# Display the plot
print(p)



# Seasonal decomposition for SO2 and cases --------------------------------

# Load necessary libraries
library(tidyverse)
library(forecast) # For STL decomposition and forecasting functions, if needed in other parts

# Reading and preparing the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")
data$Date <- as.Date(data$Date) # Convert 'Date' to Date format

# Assume a relationship for secondary axis scaling (adjust based on actual data)
scale_factor <- max(data$cases) / max(data$meanSO2)

# Create a plot with NO2 levels, cases, and secondary axis for 'cases'
p <- ggplot(data, aes(x = Date)) +
  geom_line(aes(y = meanSO2, color = "SO2 Levels")) + # SO2 levels
  geom_point(aes(y = meanSO2, color = "SO2 Levels")) +
  geom_line(aes(y = cases / scale_factor, color = "Cases")) + # Cases adjusted by scale factor
  geom_point(aes(y = cases / scale_factor, color = "Cases")) +
  scale_y_continuous(sec.axis = sec_axis(~ . * scale_factor, name = "Cases")) +
  scale_color_manual(values = c("SO2 Levels" = "blue", "Cases" = "red"), name = "Data Type") +
  labs(title = "SO2 Levels and Cases Over Time",
       subtitle = "An analysis of SO2 levels and case counts from 2020 to 2022",
       #caption = "Data source: KHIS2 and TROPOMI/Sentinel-5P\nAnalysis by: Kipterer John Kapoi\n Date: April 2024",
       x = "Date", y = "Level") +
  theme_bw() +
  
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1, color = "black", size = 12), # Make x-axis values black and legible
        axis.text.y = element_text(color = "black", size = 12), # Make y-axis values black and legible
        axis.title.x = element_text(color = "black", size = 14), # Make x-axis title black and legible
        axis.title.y = element_text(color = "black", size = 14), # Make y-axis title black and legible
        legend.position = "bottom", # Position the legend at the bottom
        legend.text = element_text(size = 12), # Increase legend text size
        legend.title = element_text(size = 14))  # Increase legend title size

# Display the plot
print(p)


# Seasonal decomposition for CO and cases  --------------------------------

# Load necessary libraries
library(tidyverse)
library(forecast) # For STL decomposition and forecasting functions, if needed in other parts

# Reading and preparing the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")
data$Date <- as.Date(data$Date) # Convert 'Date' to Date format

# Assume a relationship for secondary axis scaling (adjust based on actual data)
scale_factor <- max(data$cases) / max(data$meanCO)

# Create a plot with NO2 levels, cases, and secondary axis for 'cases'
p <- ggplot(data, aes(x = Date)) +
  geom_line(aes(y = meanCO, color = "CO Levels")) + # CO levels
  geom_point(aes(y = meanCO, color = "CO Levels")) +
  geom_line(aes(y = cases / scale_factor, color = "Cases")) + # Cases adjusted by scale factor
  geom_point(aes(y = cases / scale_factor, color = "Cases")) +
  scale_y_continuous(sec.axis = sec_axis(~ . * scale_factor, name = "Cases")) +
  scale_color_manual(values = c("CO Levels" = "blue", "Cases" = "red"), name = "Data Type") +
  labs(title = "CO Levels and Cases Over Time",
       subtitle = "An analysis of CO levels and case counts from 2020 to 2022",
       #caption = "Data source: KHIS2 and TROPOMI/Sentinel-5P\nAnalysis by: Kipterer John Kapoi\nDate: April 2024",
       x = "Date", y = "Level") +
  theme_bw() +
  
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1, color = "black", size = 12), # Make x-axis values black and legible
        axis.text.y = element_text(color = "black", size = 12), # Make y-axis values black and legible
        axis.title.x = element_text(color = "black", size = 14), # Make x-axis title black and legible
        axis.title.y = element_text(color = "black", size = 14), # Make y-axis title black and legible
        legend.position = "bottom", # Position the legend at the bottom
        legend.text = element_text(size = 12), # Increase legend text size
        legend.title = element_text(size = 14))  # Increase legend title size

# Display the plot
print(p)


# Seasonal decomposition for AOD and cases  -------------------------------

# Load necessary libraries
library(tidyverse)
library(forecast) # For STL decomposition and forecasting functions, if needed in other parts

# Reading and preparing the dataset
data <- read.csv("C:/Users/ADMIN/Documents/Texila American University/Thesis/Thesis_data/Tropomi_data/Final data/pollutant_data1.csv")
data$Date <- as.Date(data$Date) # Convert 'Date' to Date format

# Assume a relationship for secondary axis scaling (adjust based on actual data)
scale_factor <- max(data$cases) / max(data$meanAOD)

# Create a plot with NO2 levels, cases, and secondary axis for 'cases'
p <- ggplot(data, aes(x = Date)) +
  geom_line(aes(y = meanAOD, color = "AOD Levels")) + # AOD levels
  geom_point(aes(y = meanAOD, color = "AOD Levels")) +
  geom_line(aes(y = cases / scale_factor, color = "Cases")) + # Cases adjusted by scale factor
  geom_point(aes(y = cases / scale_factor, color = "Cases")) +
  scale_y_continuous(sec.axis = sec_axis(~ . * scale_factor, name = "Cases")) +
  scale_color_manual(values = c("AOD Levels" = "blue", "Cases" = "red"), name = "Data Type") +
  labs(title = "AOD Levels and Cases Over Time",
       subtitle = "An analysis of AOD levels and case counts from 2020 to 2022",
      # caption = "Data source: KHIS2 and MODIS/006/MCD19A2_GRANULES\nAnalysis by: Kipterer John Kapoi\nDate: April 2024",
       x = "Date", y = "Level") +
  theme_bw() +
  
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1, color = "black", size = 12), # Make x-axis values black and legible
        axis.text.y = element_text(color = "black", size = 12), # Make y-axis values black and legible
        axis.title.x = element_text(color = "black", size = 14), # Make x-axis title black and legible
        axis.title.y = element_text(color = "black", size = 14), # Make y-axis title black and legible
        legend.position = "bottom", # Position the legend at the bottom
        legend.text = element_text(size = 12), # Increase legend text size
        legend.title = element_text(size = 14))  # Increase legend title size

# Display the plot
print(p)

# Multivariate Analysis
# Load necessary libraries
 library(tidyverse)
 library(broom)
 library(flextable)
 
 # Perform multivariate linear regression
 multivariate_model <- lm(cases ~ meanSO2 + meanCO + meanAOD + meanNO2, data = data)
 
 # Extract results and 95% confidence intervals
 model_results <- tidy(multivariate_model, conf.int = TRUE) %>%
   select(term, estimate, std.error, statistic, p.value, conf.low, conf.high) %>%  # Organize the columns
   mutate(across(c(estimate, std.error, statistic, p.value, conf.low, conf.high), round, 4))  # Round values to 4 decimal places
 
 # Format the table for better presentation
 flex_table <- flextable(model_results) %>%
   set_caption("Multivariate Linear Regression Results: Effect on Cases with 95% Confidence Interval") %>%
   autofit() %>%
   theme_vanilla()
 
 # Display the table
 print(flex_table)
 
 
 #Univariate nalysis
 
 # Load necessary libraries
 library(tidyverse)
 library(broom)
 library(flextable)
 
 # Define a function to perform univariate linear regression and extract results
 univariate_model <- function(data, predictor) {
   model <- lm(cases ~ data[[predictor]], data = data)  # Univariate model
   tidy(model, conf.int = TRUE) %>% # Extract estimates with 95% confidence interval
     mutate(Variable = predictor) %>% # Add variable name
     select(Variable, term, estimate, std.error, statistic, p.value, conf.low, conf.high) %>%  # Organize the columns
     mutate(across(c(estimate, std.error, statistic, p.value, conf.low, conf.high), round, 4))  # Round to 4 decimal places
 }
 
 # Apply the function to each mean variable
 so2_results <- univariate_model(data, "meanSO2")
 co_results <- univariate_model(data, "meanCO")
 aod_results <- univariate_model(data, "meanAOD")
 no2_results <- univariate_model(data, "meanNO2")
 
 # Combine all results into one data frame
 combined_results <- bind_rows(so2_results, co_results, aod_results, no2_results)
 
 # Format the table for better presentation
 flex_table <- flextable(combined_results) %>%
   set_caption("Univariate Linear Regression Results: Effect on Cases with 95% Confidence Interval") %>%
   autofit() %>%
   theme_vanilla()
 
 # Display the table
 print(flex_table)