library(haven)
library(foreign) 
library(readr)
library(dplyr)
library(ggplot2)
library(broom)
library(car)
library(MASS) 
library(lmtest)
library(zoo)
library(nortest)
library(plotrix)
library(scales)
library(tableone)
library(Weighted.Desc.Stat)
library(mitools)
library(survey)
library(VGAM)
library(stargazer)
library(sandwich)
library(pastecs)
library(muhaz)
library(ggpubr)
library(survminer)
library(eha)
library(reshape2)
library(data.table)
library(magrittr)
library(mediation)
library(sensitivity)

Datasets: World Bank Indicators

gg<-read.csv("C:\\Users\\Jaire\\OneDrive\\Desktop\\Research\\Data\\gg2.csv")

outcome

-GDP growth (country-level)

predictors

-Energy consumption per capita -Fossil fuel consumption (% of total energy)

causal mediation analyses (CMA)

med.fit<- lm(gg$ep.pcap ~ gg$fosf.use.p, data = gg)
out.fit<- lm(gg$gdpg.p ~ gg$fosf.use.p + gg$ep.pcap,data = gg)
med.out<- mediate(med.fit, out.fit, treat = "gg$fosf.use.p", mediator = "gg$ep.pcap",
robustSE = TRUE, sims = 10000)

summary(med.out)
## 
## Causal Mediation Analysis 
## 
## Quasi-Bayesian Confidence Intervals
## 
##                Estimate 95% CI Lower 95% CI Upper p-value
## ACME            -0.0451      -0.3618         0.22    0.73
## ADE              0.0878      -0.0869         0.26    0.32
## Total Effect     0.0427      -0.2782         0.32    0.71
## Prop. Mediated   0.4038      -7.8107         8.42    0.66
## 
## Sample Size Used: 19 
## 
## 
## Simulations: 10000
plot(med.out)

interpretation

The results show an indirect negative affect of electricity use per capita on the relationship between the percent estimate of GDP growth and the percent estimate of fossil fuel consumption, (ACME = -0.0428, p >0.05), with no significant direct effect of fossil fuel consumption on the percent estimate of GDP growth (ADE = 0.0870, p >0.05), and no significant total effect (ACME+ADE = 0.0441, p >0.05).

Additionally, the proportion mediated (38.7%, p >0.05) shows how much of the total effect is explained by the indirect effect of electricity use per capita on the relationship between the percent estimate of GDP growth and the percent estimate of fossil fuel consumption. The sample sized used after 10,000 Monte Carlo simulations was n=19 countries.

sensitivity analysis

sens.out<- medsens(med.out, rho.by = 0.1, effect.type = "direct", sims = 1000)
summary(sens.out)
## 
## Mediation Sensitivity Analysis for Average Direct Effect
## 
## Sensitivity Region
## 
##        Rho     ADE 95% CI Lower 95% CI Upper R^2_M*R^2_Y* R^2_M~R^2_Y~
##  [1,] -0.9 -0.2560      -0.6304       0.1183         0.81       0.5923
##  [2,] -0.8 -0.1347      -0.4099       0.1406         0.64       0.4680
##  [3,] -0.7 -0.0761      -0.3063       0.1541         0.49       0.3583
##  [4,] -0.6 -0.0379      -0.2404       0.1646         0.36       0.2632
##  [5,] -0.5 -0.0093      -0.1925       0.1739         0.25       0.1828
##  [6,] -0.4  0.0141      -0.1545       0.1827         0.16       0.1170
##  [7,] -0.3  0.0344      -0.1228       0.1915         0.09       0.0658
##  [8,] -0.2  0.0527      -0.0952       0.2005         0.04       0.0292
##  [9,] -0.1  0.0699      -0.0704       0.2101         0.01       0.0073
## [10,]  0.0  0.0865      -0.0477       0.2207         0.00       0.0000
## [11,]  0.1  0.1032      -0.0263       0.2327         0.01       0.0073
## [12,]  0.2  0.1204      -0.0059       0.2467         0.04       0.0292
## 
## Rho at which ADE = 0: -0.5
## R^2_M*R^2_Y* at which ADE = 0: 0.25
## R^2_M~R^2_Y~ at which ADE = 0: 0.1828