#Install & update necessary packages and libraries
install.packages("readxl")
library("readxl")
update.packages("readxl")


#DESCRIPTIVE STATISTICS

##EPU_Index_Developed


#Load the Excel data
EPU_Index <- read_xlsx("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU Index")


#Select the subset of developed countries
EPU_Index_Developed <- EPU_Index[341:672, 3:15]
View(EPU_Index_Developed)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data <- unlist(EPU_Index_Developed)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data <- as.numeric(Vector_data)          
is.numeric(Numeric_data)                         #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data, na.rm = TRUE)     #min function requires numeric data
max_value <- max(Numeric_data, na.rm = TRUE)     
mean_value <- mean(Numeric_data, na.rm = TRUE)
sd_value <- sd(Numeric_data, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##EPU_Index_Emerging


#Select the subset of emerging countries
EPU_Index_Emerging <- EPU_Index[679:1010, 3:10]
View(EPU_Index_Emerging)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_2 <- unlist(EPU_Index_Emerging)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_2 <- as.numeric(Vector_data_2)          
is.numeric(Numeric_data_2)                       #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_2, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_2, na.rm = TRUE)     
mean_value <- mean(Numeric_data_2, na.rm = TRUE)
sd_value <- sd(Numeric_data_2, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Share_Price_Index_Developed


#Load the Excel data
Stocks <- read_xlsx("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Stocks")

#Select the subset of developed countries
Share_Price_Index_Developed <- Stocks[1355:1686, 3:15]
View(Share_Price_Index_Developed)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_3 <- unlist(Share_Price_Index_Developed)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_3 <- as.numeric(Vector_data_3)          
is.numeric(Numeric_data_3)                         #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_3, na.rm = TRUE)     #min function requires numeric data
max_value <- max(Numeric_data_3, na.rm = TRUE)     
mean_value <- mean(Numeric_data_3, na.rm = TRUE)
sd_value <- sd(Numeric_data_3, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Share_Price_Index_Emerging


#Select the subset of emerging countries
Share_Price_Index_Emerging <- Stocks[1693:2024, 3:10]
View(Share_Price_Index_Emerging)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_4 <- unlist(Share_Price_Index_Emerging)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_4 <- as.numeric(Vector_data_4)          
is.numeric(Numeric_data_4)                       #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_4, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_4, na.rm = TRUE)     
mean_value <- mean(Numeric_data_4, na.rm = TRUE)
sd_value <- sd(Numeric_data_4, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Bond_Price_Index_Developed


#Load the Excel data
Bonds <- read_xlsx("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Bonds")

#Select the subset of developed countries
Bond_Price_Index_Developed <- Bonds[491:606, 3:15]
View(Bond_Price_Index_Developed)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_5 <- unlist(Bond_Price_Index_Developed)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_5 <- as.numeric(Vector_data_5)          
is.numeric(Numeric_data_5)                       #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_5, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_5, na.rm = TRUE)     
mean_value <- mean(Numeric_data_5, na.rm = TRUE)
sd_value <- sd(Numeric_data_5, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##Bond_Price_Index_Emerging


#Select the subset of emerging countries
Bond_Price_Index_Emerging <- Bonds[613:728, 3:10]
View(Bond_Price_Index_Emerging)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_6 <- unlist(Bond_Price_Index_Emerging)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_6 <- as.numeric(Vector_data_6)          
is.numeric(Numeric_data_6)                       #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_6, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_6, na.rm = TRUE)     
mean_value <- mean(Numeric_data_6, na.rm = TRUE)
sd_value <- sd(Numeric_data_6, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Share_Index_Excess_Returns_Developed


#Select the subset of developed countries
Share_Index_Excess_Returns_Developed <- Stocks[2708:3038, 3:15]
View(Share_Index_Excess_Returns_Developed)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_7 <- unlist(Share_Index_Excess_Returns_Developed)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_7 <- as.numeric(Vector_data_7)          
is.numeric(Numeric_data_7)                       #check if Numeric_data is numeric : YES
Numeric_data_7_clean <- na.omit(Numeric_data_7)  #to omit NA values   
is.numeric(Numeric_data_7_clean)

#Computation of key statistics
min_value <- min(Numeric_data_7, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_7, na.rm = TRUE)     
mean_value <- mean(Numeric_data_7, na.rm = TRUE)
sd_value <- sd(Numeric_data_7, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Share_Index_Excess_Returns_Emerging


#Select the subset of emerging countries
Share_Index_Excess_Returns_Emerging <- Stocks[3046:3376, 3:10]
View(Share_Index_Excess_Returns_Emerging)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_8 <- unlist(Share_Index_Excess_Returns_Emerging)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_8 <- as.numeric(Vector_data_8)          
is.numeric(Numeric_data_8)                       #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_8, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_8, na.rm = TRUE)     
mean_value <- mean(Numeric_data_8, na.rm = TRUE)
sd_value <- sd(Numeric_data_8, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Bond_Index_Excess_Returns_Developed


#Select the subset of developed countries
Bond_Index_Excess_Returns_Developed <- Bonds[980:1094, 3:15]
View(Bond_Index_Excess_Returns_Developed)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_9 <- unlist(Bond_Index_Excess_Returns_Developed)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_9 <- as.numeric(Vector_data_9)          
is.numeric(Numeric_data_9)                       #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_9, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_9, na.rm = TRUE)     
mean_value <- mean(Numeric_data_9, na.rm = TRUE)
sd_value <- sd(Numeric_data_9, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Bond_Index_Excess_Returns_Emerging


#Select the subset of emerging countries
Bond_Index_Excess_Returns_Emerging <- Bonds[1102:1216, 3:10]
View(Bond_Index_Excess_Returns_Emerging)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_10 <- unlist(Bond_Index_Excess_Returns_Emerging)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_10 <- as.numeric(Vector_data_10)          
is.numeric(Numeric_data_10)                       #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_10, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_10, na.rm = TRUE)     
mean_value <- mean(Numeric_data_10, na.rm = TRUE)
sd_value <- sd(Numeric_data_10, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value)


##Fama_French_Factors_Developed

##SMB


#Load the Excel data
Fama_French_Factors <- read_xlsx("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Fama-French Factors")

#Select the SMB factor for the subset of developed countries
Fama_French_factors_Developed_SMB <- Fama_French_Factors[342:673, 3:3]
View(Fama_French_factors_Developed_SMB)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_11 <- unlist(Fama_French_factors_Developed_SMB)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_11 <- as.numeric(Vector_data_11)          
is.numeric(Numeric_data_11)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_11, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_11, na.rm = TRUE)     
mean_value <- mean(Numeric_data_11, na.rm = TRUE)
sd_value <- sd(Numeric_data_11, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


#HML


#Select the HML factor for the subset of developed countries
Fama_French_factors_Developed_HML <- Fama_French_Factors[342:673, 4:4]
View(Fama_French_factors_Developed_HML)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_12 <- unlist(Fama_French_factors_Developed_HML)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_12 <- as.numeric(Vector_data_12)          
is.numeric(Numeric_data_12)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_12, na.rm = TRUE)   #min function requires numeric data
max_value <- max(Numeric_data_12, na.rm = TRUE)     
mean_value <- mean(Numeric_data_12, na.rm = TRUE)
sd_value <- sd(Numeric_data_12, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##RMW


#Select the RMW factor for the subset of developed countries
Fama_French_factors_Developed_RMW <- Fama_French_Factors[342:673, 5:5]
View(Fama_French_factors_Developed_RMW)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_13 <- unlist(Fama_French_factors_Developed_RMW)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_13 <- as.numeric(Vector_data_13)          
is.numeric(Numeric_data_13)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_13, na.rm = TRUE)  #min function requires numeric data
max_value <- max(Numeric_data_13, na.rm = TRUE)     
mean_value <- mean(Numeric_data_13, na.rm = TRUE)
sd_value <- sd(Numeric_data_13, na.rm = TRUE)

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##CMA


#Select the RMW factor for the subset of developed countries
Fama_French_factors_Developed_CMA <- Fama_French_Factors[342:673, 6:6]
View(Fama_French_factors_Developed_CMA)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_14 <- unlist(Fama_French_factors_Developed_CMA)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_14 <- as.numeric(Vector_data_14)          
is.numeric(Numeric_data_14)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_14, na.rm = TRUE)  #min function requires numeric data
max_value <- max(Numeric_data_14, na.rm = TRUE)     
mean_value <- mean(Numeric_data_14, na.rm = TRUE)
sd_value <- sd(Numeric_data_14, na.rm = TRUE) 

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##Emerging Countries


##SMB


#Select the SMB factor for the subset of emerging countries
Fama_French_factors_Emerging_SMB <- Fama_French_Factors[342:673, 12:12]
View(Fama_French_factors_Emerging_SMB)

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_15 <- unlist(Fama_French_factors_Emerging_SMB)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_15 <- as.numeric(Vector_data_15)          
is.numeric(Numeric_data_15)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_15, na.rm = TRUE)  #min function requires numeric data
max_value <- max(Numeric_data_15, na.rm = TRUE)     
mean_value <- mean(Numeric_data_15, na.rm = TRUE)
sd_value <- sd(Numeric_data_15, na.rm = TRUE) 

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##HML

#Select the HML factor for the subset of emerging countries
Fama_French_factors_Emerging_HML <- Fama_French_Factors[342:673, 13:13]
View(Fama_French_factors_Emerging_HML) 

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_16 <- unlist(Fama_French_factors_Emerging_HML)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_16 <- as.numeric(Vector_data_16)          
is.numeric(Numeric_data_16)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_16, na.rm = TRUE)  #min function requires numeric data
max_value <- max(Numeric_data_16, na.rm = TRUE)     
mean_value <- mean(Numeric_data_16, na.rm = TRUE)
sd_value <- sd(Numeric_data_16, na.rm = TRUE) 

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##RMW

#Select the RMW factor for the subset of emerging countries
Fama_French_factors_Emerging_RMW <- Fama_French_Factors[342:673, 14:14]
View(Fama_French_factors_Emerging_RMW) 

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_17 <- unlist(Fama_French_factors_Emerging_RMW)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_17 <- as.numeric(Vector_data_17)          
is.numeric(Numeric_data_17)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_17, na.rm = TRUE)  #min function requires numeric data
max_value <- max(Numeric_data_17, na.rm = TRUE)     
mean_value <- mean(Numeric_data_17, na.rm = TRUE)
sd_value <- sd(Numeric_data_17, na.rm = TRUE) 

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##CMA

#Select the CMA factor for the subset of emerging countries
Fama_French_factors_Emerging_CMA <- Fama_French_Factors[342:673, 15:15]
View(Fama_French_factors_Emerging_CMA) 

#Convert list in vector data                     #as.numeric requires a vector of values
Vector_data_18 <- unlist(Fama_French_factors_Emerging_CMA)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_18 <- as.numeric(Vector_data_18)          
is.numeric(Numeric_data_18)                      #check if Numeric_data is numeric : YES

#Computation of key statistics
min_value <- min(Numeric_data_18, na.rm = TRUE)  #min function requires numeric data
max_value <- max(Numeric_data_18, na.rm = TRUE)     
mean_value <- mean(Numeric_data_18, na.rm = TRUE)
sd_value <- sd(Numeric_data_18, na.rm = TRUE) 

#Print key statistics
print(min_value)
print(max_value)
print(mean_value)
print(sd_value) 


##VARIABLES TRANSFORMATIONS?


#FREQUENCY HISTOGRAMS

#Share_Index_Excess_Returns_Developed
Numeric_data_7                     #Numeric set of share_index_excess_returns_developed       

Share_Index_Excess_Returns_Developed_Histogram <- hist(Numeric_data_7)

#Share_Index_Excess_Returns_Emerging
Numeric_data_8                     #Numeric set of share_index_excess_returns_emerging
Share_Index_Excess_Returns_Emerging_Histogram <- hist(Numeric_data_8)

#Bond_Index_Excess_Returns_Developed
Numeric_data_9                     #Numeric set of bond_index_excess_returns_developed
Bond_Index_Excess_Returns_Developed_Histogram <- hist(Numeric_data_9)

#BER_Emerging
Numeric_data_10                    #Numeric set of bond_index_excess_returns_emerging
Bond_Index_Excess_Returns_Emerging_Histogram <- hist(Numeric_data_10)

#EPU_Index_Developed
Numeric_data
EPU_Index_Developed_Histogram <- hist(Numeric_data)

#EPU_Index_Emerging
Numeric_data_2
EPU_Index_Emerging_Histogram <- hist(Numeric_data_2)

#SMB_Developed
Numeric_data_11
SMB_Developed_Histogram <- hist(Numeric_data_11)

#HML_Developed
Numeric_data_12
HML_Developed_Histogram <- hist(Numeric_data_12)

#RMW_Developed
Numeric_data_13
RMW_Developed_Histogram <- hist(Numeric_data_13)

#CMA_Developed
Numeric_data_14
CMA_Developed_Histogram <- hist(Numeric_data_14)

#SMB_Emerging
Numeric_data_15
SMB_Emerging_Histogram <- hist(Numeric_data_15)

#HML_Emerging
Numeric_data_16
HML_Emerging_Histogram <- hist(Numeric_data_16)

#RMW_Emerging
Numeric_data_17
RMW_Emerging_Histogram <- hist(Numeric_data_17)

#CMA_Emerging
Numeric_data_18
CMA_Emerging_Histogram <- hist(Numeric_data_18)


#DATA STATIONARITY TESTS

install.packages("tseries")                 #Install & update necessary package for ADF test
library("tseries")
update.packages("tseries")

#EPU_Index_Developed            
adf.test(Numeric_data)

#EPU_Index_Emerging
adf.test(Numeric_data_2)
         
#Share_Index_Excess_Returns_Developed
adf.test(Numeric_data_7_clean)

#Share_Index_Excess_Returns_Emerging
adf.test(Numeric_data_8)

#Bond_Index_Excess_Returns_Developed
adf.test(Numeric_data_9)

#Bond_Index_Excess_Returns_Emerging
adf.test(Numeric_data_10)

##Developed countries

#SMB
adf.test(Numeric_data_11)

#HML
adf.test(Numeric_data_12)

#RMW
adf.test(Numeric_data_13)

#CMA
adf.test(Numeric_data_14)


##Emerging countries 

#SMB
adf.test(Numeric_data_15)

#HML
adf.test(Numeric_data_16)

#RMW
adf.test(Numeric_data_17)

#CMA
adf.test(Numeric_data_18)


##MULTIVARIATE LINEAR REGRESSIONS

#LOAD DATA FOR REGRESSION ANALYSIS (numeric)
SER_Developed <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Share_Excess_Returns_Developed")
SER_Emerging <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Share_Excess_Returns_Emerging")
BER_Developed <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet ="Bond_Excess_Returns_Developed")
BER_Emerging <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Bond_Excess_Returns_Emerging")
EPU_Developed <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Index_Developed")
EPU_Emerging <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Index_Emerging")
SMB_Developed <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "SMB_Developed")
HML_Developed <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "HML_Developed")
RMW_Developed <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "RMW_Developed")
CMA_Developed <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "CMA_Developed")
SMB_Emerging <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "SMB_Emerging")
HML_Emerging <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "HML_Emerging")
RMW_Emerging <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "RMW_Emerging")
CMA_Emerging <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "CMA_Emerging")


##Share_Index_Excess_Returns_Developed
Regression_SER_DEV_Data <- cbind(SER_Developed, EPU_Developed, SMB_Developed, HML_Developed, RMW_Developed, CMA_Developed)                                                #create a single data frame for regression 1


Regression_1 <- lm(Australia_SER+Canada_SER+Germany_SER+Spain_SER+France_SER+UK_SER+Greece_SER+Ireland_SER+Italy_SER+Japan_SER+Sweden_SER+Singapore_SER+US_SER            #Run regression 1 on SER of developed countries
                   ~ log10(Australia_EPU+Canada_EPU+Germany_EPU+Spain_EPU+France_EPU+UK_EPU+Greece_EPU+Ireland_EPU+Italy_EPU+Japan_EPU+Sweden_EPU+Singapore_EPU+US_EPU)
                   + SMB_Developed
                   + HML_Developed
                   + RMW_Developed
                   + CMA_Developed, data = Regression_SER_DEV_Data, na.action = na.omit)
summary(Regression_1)                   #to have the summary of Regression_1

#CORRELATION MATRIX (EXPLANATORY VARIABLES) - REGRESSION 1 
Corr_Mat_Regression_1_Data <- cbind(Numeric_data, Numeric_data_11, Numeric_data_12, Numeric_data_13, Numeric_data_14)                                                     #1 single data frame of Regression_1_Explanatory variables 
Corr_Matrix_Regression_1 <- cor(Corr_Mat_Regression_1_Data)                                                                                                               #compute the correlation matrix                                                                                                           
View(Corr_Matrix_Regression_1) 
View(EPU_Index_Developed)


##Share_Index_Excess_Returns_Emerging
Regression_SER_EMR_Data <- cbind(SER_Emerging, EPU_Emerging, SMB_Emerging, HML_Emerging, RMW_Emerging, CMA_Emerging)    #create a single data frame for regression 2


Regression_2 <- lm(Brazil_SER+Chile_SER+China_SER+India_SER+Mexico_SER+Pakistan_SER+Russia_SER+Korea_SER                #Run regression 2
                   ~ log10(Brazil_EPU+Chile_EPU+China_EPU+India_EPU+Mexico_EPU+Pakistan_EPU+Russia_EPU+Korea_EPU)
                   + SMB_Emerging
                   + HML_Emerging
                   + RMW_Emerging
                   + CMA_Emerging, data = Regression_SER_EMR_Data, na.action = na.omit)
summary(Regression_2)                  #to have the summary of Regression_2

#CORRELATION MATRIX (EXPLANATORY VARIABLES) - REGRESSION 2
Corr_Mat_Regression_2_Data <- cbind(Numeric_data_2, Numeric_data_15, Numeric_data_16, Numeric_data_17, Numeric_data_18)                                                #1 single data frame of Regression_1_Explanatory variables 
Corr_Matrix_Regression_2 <- cor(Corr_Mat_Regression_2_Data)       #compute the correlation matrix                                                                                                           
View(Corr_Matrix_Regression_2)


#Load the date-adjusted data for bond_excess_returns regressions
EPU_Developed_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Index_Developed_Short")
EPU_Emerging_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Index_Emerging_Short")
SMB_Developed_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "SMB_Developed_Short")
SMB_Emerging_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "SMB_Emerging_Short")
HML_Developed_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "HML_Developed_Short")
HML_Emerging_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "HML_Emerging_Short")
RMW_Developed_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "RMW_Developed_Short")
RMW_Emerging_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "RMW_Emerging_Short")
CMA_Developed_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "CMA_Developed_Short")
CMA_Emerging_Bond_Reg <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "CMA_Emerging_Short")


##Numeric conversion of date-adjusted data for bond_excess_returns
##EPU_Developed_Bond_Reg

#Exclude columns "Year" & "Month"

EPU_Developed_Bond_Reg_Excluded <- EPU_Developed_Bond_Reg[,!names(EPU_Developed_Bond_Reg) %in% c("Year", "Month")]

#Convert list in vector data                    #as.numeric requires a vector of values

Vector_data_19 <- unlist(EPU_Developed_Bond_Reg_Excluded)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_19 <- as.numeric(Vector_data_19)          
is.numeric(Numeric_data_19) 


##EPU_Emerging_Bond_Reg

#Exclude columns "Year" & "Month"

EPU_Emerging_Bond_Reg_Excluded <- EPU_Emerging_Bond_Reg[,!names(EPU_Emerging_Bond_Reg) %in% c("Year", "Month")]

#Convert list in vector data                    #as.numeric requires a vector of values

Vector_data_20 <- unlist(EPU_Emerging_Bond_Reg_Excluded)

#Numeric data conversion                         #to convert the vector in numeric data
Numeric_data_20 <- as.numeric(Vector_data_20)          
is.numeric(Numeric_data_20) 


##SMB_Developed_Bond_Reg

#Exclude columns "Year" & "Month"
SMB_Developed_Bond_Reg_Excluded <- SMB_Developed_Bond_Reg[,!names(SMB_Developed_Bond_Reg) %in% c("Year", "Month")]
is.numeric(SMB_Developed_Bond_Reg_Excluded)

##SMB_Emerging_Bond_Reg

#Exclude columns "Year" and "Month"
SMB_Emerging_Bond_Reg_Excluded <- SMB_Emerging_Bond_Reg[,!names(SMB_Emerging_Bond_Reg) %in% c("Year", "Month")]
is.numeric(SMB_Emerging_Bond_Reg_Excluded)

##HML_Developed_Bond_Reg

#Exclude columns "Year" and "Month"
HML_Developed_Bond_Reg_Excluded <- HML_Developed_Bond_Reg[,!names(HML_Developed_Bond_Reg) %in% c("Year", "Month")]
is.numeric(HML_Developed_Bond_Reg_Excluded)

##HML_Emerging_Bond_Reg

#Exclude columns "Year" and "Month"
HML_Emerging_Bond_Reg_Excluded <- HML_Emerging_Bond_Reg[,!names(HML_Emerging_Bond_Reg) %in% c("Year", "Month")]
is.numeric(HML_Emerging_Bond_Reg_Excluded)

##RMW_Developed_Bond_Reg

#Exclude columns "Year" & "Month"
RMW_Developed_Bond_Reg_Excluded <- RMW_Developed_Bond_Reg[,!names(RMW_Developed_Bond_Reg) %in% c("Year", "Month")]
is.numeric(RMW_Developed_Bond_Reg_Excluded)

##RMW_Emerging_Bond_Reg

#Exclude columns "Year" & "Month"
RMW_Emerging_Bond_Reg_Excluded <- RMW_Emerging_Bond_Reg[,!names(RMW_Emerging_Bond_Reg) %in% c("Year", "Month")]
is.numeric(RMW_Emerging_Bond_Reg_Excluded) 

##CMA_Developed_Bond_Reg

#Exclude columns "Year" & "Month"
CMA_Developed_Bond_Reg_Excluded <- CMA_Developed_Bond_Reg[,!names(CMA_Developed_Bond_Reg) %in% c("Year", "Month")]
is.numeric(CMA_Developed_Bond_Reg_Excluded)  


##CMA_Emerging_Bond_Reg

#Exclude columns "Year" & "Month"
CMA_Emerging_Bond_Reg_Excluded <- CMA_Emerging_Bond_Reg[,!names(CMA_Emerging_Bond_Reg) %in% c("Year", "Month")]
is.numeric(CMA_Emerging_Bond_Reg_Excluded)   


##DATA STATIONARITY TESTS

install.packages("tseries")                 #Install & update necessary package for ADF test
library("tseries")
update.packages("tseries")

#EPU_Developed_Bond_Reg
adf.test(Numeric_data_19)

#EPU_Emerging_Bond_Reg
adf.test(Numeric_data_20)

#SMB_Developed_Bond_Reg
adf.test(SMB_Developed_Bond_Reg_Excluded)

#SMB_Emerging_Bond_Reg
adf.test(SMB_Emerging_Bond_Reg_Excluded)

#HML_Developed_Bond_Reg
adf.test(HML_Developed_Bond_Reg_Excluded)

#HML_Emerging_Bond_Reg
adf.test(HML_Emerging_Bond_Reg_Excluded)

#RMW_Developed_Bond_Reg
adf.test(RMW_Developed_Bond_Reg_Excluded)

#RMW_Emerging_Bond_Reg
adf.test(RMW_Emerging_Bond_Reg_Excluded)

#CMA_Developed_Bond_Reg
adf.test(CMA_Developed_Bond_Reg_Excluded)

#CMA_Emerging_Bond_Reg
adf.test(CMA_Emerging_Bond_Reg_Excluded)

##FREQUENCY HISTOGRAMMS

#EPU_Developed_Bond_Reg
hist(Numeric_data_19)

#EPU_Emerging_Bond_Reg
hist(Numeric_data_20)

#SMB_Developed_Bond_Reg
hist(SMB_Developed_Bond_Reg_Excluded)

#HML_Developed_Bond_Reg
hist(HML_Developed_Bond_Reg_Excluded)

#RMW_Developed_Bond_Reg
hist(RMW_Developed_Bond_Reg_Excluded)

#CMA_Developed_Bond_Reg
hist(log(CMA_Developed_Bond_Reg_Excluded))

#SMB_Emerging_Bond_Reg
hist(SMB_Emerging_Bond_Reg_Excluded)

#HML_Emerging_Bond_Reg
hist(HML_Emerging_Bond_Reg_Excluded)

#RMW_Emerging_Bond_Reg
hist(RMW_Emerging_Bond_Reg_Excluded)

#CMA_Emerging_Bond_Reg
hist(CMA_Emerging_Bond_Reg_Excluded)


##Bond_Index_Excess_Returns_Developed
Regression_BER_DVP_Data <- cbind(BER_Developed,EPU_Developed_Bond_Reg,SMB_Developed_Bond_Reg,HML_Developed_Bond_Reg,RMW_Developed_Bond_Reg,CMA_Developed_Bond_Reg)            #create a single data frame for regression 3

Regression_3 <- lm(Australia_BER+Canada_BER+Germany_BER+Spain_BER+France_BER+UK_BER+Greece_BER+Ireland_BER+Italy_BER+Japan_BER+Sweden_BER+Singapore_BER+US_BER                #run regression 3
                   ~ log10(Australia_EPU+Canada_EPU+Germany_EPU+Spain_EPU+France_EPU+UK_EPU+Greece_EPU+Ireland_EPU+Italy_EPU+Japan_EPU+Sweden_EPU+Singapore_EPU+US_EPU)
                   + SMB_Developed
                   + HML_Developed
                   + RMW_Developed
                   + CMA_Developed, data = Regression_BER_DVP_Data, na.action = na.omit)
summary(Regression_3)          #to have the summary of Regression_3 

#CORRELATION MATRIX (EXPLANATORY VARIABLES) - REGRESSION 3
Corr_Mat_Regression_3_Data <- cbind(Numeric_data_19, SMB_Developed_Bond_Reg_Excluded, HML_Developed_Bond_Reg_Excluded, RMW_Developed_Bond_Reg_Excluded, CMA_Developed_Bond_Reg_Excluded)                                                #1 single data frame of Regression_1_Explanatory variables 
Corr_Matrix_Regression_3 <- cor(Corr_Mat_Regression_3_Data)       #compute the correlation matrix                                                                                                           
View(Corr_Matrix_Regression_3)


##Bond_Index_Excess_Returns_Emerging
Regression_BER_EMR_Data <- cbind(BER_Emerging,EPU_Emerging_Bond_Reg,SMB_Emerging_Bond_Reg,HML_Emerging_Bond_Reg,RMW_Emerging_Bond_Reg,CMA_Emerging_Bond_Reg)                  #create a single data frame for regression 4

Regression_4 <- lm(Brazil_BER+Chile_BER+China_BER+India_BER+Mexico_BER+Pakistan_BER+Russia_BER+Korea_BER                                                                      #run regression 4
                   ~ log10(Brazil_EPU+Chile_EPU+China_EPU+India_EPU+Mexico_EPU+Pakistan_EPU+Russia_EPU+Korea_EPU)
                   + SMB_Emerging
                   + HML_Emerging
                   + RMW_Emerging
                   + CMA_Emerging, data = Regression_BER_EMR_Data, na.action = na.omit)
summary(Regression_4)                 #to have the summary of Regression_4

#CORRELATION MATRIX (EXPLANATORY VARIABLES) - REGRESSION 4
Corr_Mat_Regression_4_Data <- cbind(Numeric_data_20, SMB_Emerging_Bond_Reg_Excluded, HML_Emerging_Bond_Reg_Excluded, RMW_Emerging_Bond_Reg_Excluded, CMA_Emerging_Bond_Reg_Excluded)                                                #1 single data frame of Regression_1_Explanatory variables 
Corr_Matrix_Regression_4 <- cor(Corr_Mat_Regression_4_Data)       #compute the correlation matrix                                                                                                           
View(Corr_Matrix_Regression_4)


##CORRELATION REGRESSIONS

#Load Share-Bond Excess Returns Correlations for developed & emerging countries + EPU_DEV_FREQ_ADJ_CORR + EPU_EME_FREQ_ADJ_CORR
Correlations_DVP <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Correlations_DEV_2")
Correlations_EME <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Correlations_EME_2")
Correlations_EME_LN <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "Correlations_EME_2_LN")
EPU_Developed_FREQ_CORR <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Index_Dev_Short_CORR_2")
EPU_Developed_FREQ_CORR_DIFF <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Dev_Short_CORR_2_DIF")
EPU_Emerging_FREQ_CORR <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Index_Eme_Short_CORR_2")
EPU_Emerging_FREQ_CORR_DIFF <- read_excel("C:\\Users\\Yann Hanse\\Documents\\Master's thesis\\Working Directory\\Master's thesis - Spreadsheet.xlsx", sheet = "EPU_Index_Eme_Short_CORR_2_DIFF")

#Exclude column "Year Ranges"
Correlations_DVP_Excluded <- Correlations_DVP[,!names(Correlations_DVP) %in% c("Year Ranges")]
Correlations_EME_Excluded <- Correlations_EME[,!names(Correlations_EME) %in% c("Years")]
Correlations_EME_LN_Excluded <- Correlations_EME_LN[,!names(Correlations_EME_LN) %in% c("Years")]
EPU_Developed_FREQ_CORR_Excluded <- EPU_Developed_FREQ_CORR[,!names(EPU_Developed_FREQ_CORR) %in% c("Year")]
EPU_Developed_FREQ_CORR_DIFF_Excluded <- EPU_Developed_FREQ_CORR_DIFF[,!names(EPU_Developed_FREQ_CORR_DIFF) %in% c("Year")]
EPU_Emerging_FREQ_CORR_Excluded <- EPU_Emerging_FREQ_CORR[,!names(EPU_Emerging_FREQ_CORR) %in% c("Years")]
EPU_Emerging_FREQ_CORR_DIFF_Excluded <- EPU_Emerging_FREQ_CORR_DIFF[,!names(EPU_Emerging_FREQ_CORR_DIFF) %in% c("Years")]

#Convert to numeric data
#Convert list in vector data                                                                                                   #as.numeric requires a vector of values
Vector_data_21 <- unlist(Correlations_DVP_Excluded)
Vector_data_22 <- unlist(Correlations_EME_Excluded)
Vector_data_23 <- unlist(EPU_Developed_FREQ_CORR_Excluded)
Vector_data_24 <- unlist(EPU_Emerging_FREQ_CORR_Excluded)
Vector_data_25 <- unlist(Correlations_EME_LN_Excluded) 
Vector_data_27 <- unlist(EPU_Developed_FREQ_CORR_DIFF_Excluded)
Vector_data_28 <- unlist(EPU_Emerging_FREQ_CORR_DIFF_Excluded)

#Numeric data conversion                                                                                                       #to convert the vector in numeric data
Numeric_data_21 <- as.numeric(Vector_data_21)   
is.numeric(Numeric_data_21)
Numeric_data_22 <- as.numeric(Vector_data_22)
is.numeric(Numeric_data_22)
Numeric_data_23 <- as.numeric(Vector_data_23)
is.numeric(Numeric_data_23)
Numeric_data_24 <- as.numeric(Vector_data_24)
is.numeric(Numeric_data_24)
Numeric_data_25 <- as.numeric(Vector_data_25)
is.numeric(Numeric_data_25)
Numeric_data_27 <- as.numeric(Vector_data_27)
is.numeric(Numeric_data_27)
Numeric_data_28 <- as.numeric(Vector_data_28)
is.numeric(Numeric_data_28)

#Remove "N/A values"
Numeric_data_25_clean <- na.omit(Numeric_data_25)

#DATA STATIONARITY TESTS
#Correlations_DVP
adf.test(Numeric_data_21)

#Correlations_EMR
adf.test(Numeric_data_22)
adf.test(Numeric_data_25_clean)                          #LN transformation for stationarity

#EPU_Developed_FREQ_CORR
adf.test(Numeric_data_23)                             
adf.test(Numeric_data_27)                                #differencing transformation for stationarity

#EPU_Emerging_FREQ_CORR
adf.test(Numeric_data_24)
adf.test(Numeric_data_28)                                #differencing transformation for stationarity

#FREQUENCY HISTOGRAMS
#Correlations_DVP
hist(Numeric_data_21)

#Correlations_EMR
hist(Numeric_data_22)                                    #normal
hist(Numeric_data_25_clean)                              #ln


##Regression_Correlations_DEV

Regression_COR_DVP_Data <- cbind(Correlations_DVP, EPU_Developed_FREQ_CORR_DIFF)

Regression_5 <- lm(Australia_CORR+Canada_CORR+Germany_CORR+Spain_CORR+France_CORR+UK_CORR+Greece_CORR+Ireland_CORR+Italy_CORR+Japan_CORR+Sweden_CORR+Singapore_CORR+US_CORR                                                                      #run regression 5
                   ~ log10(Australia_EPU_Diff+Canada_EPU_Diff+Germany_EPU_Diff+Spain_EPU_Diff+France_EPU_Diff+UK_EPU_Diff+Greece_EPU_Diff+Ireland_EPU_Diff+Italy_EPU_Diff+Japan_EPU_Diff+Sweden_EPU_Diff+Singapore_EPU_Diff+US_EPU_Diff)
                   , data = Regression_COR_DVP_Data, na.action = na.omit) 
summary(Regression_5)                                                                                                            #to have the summary of Regression_5


##Regression_Correlations_EMR

Regression_CORR_EMR_Data <- cbind(Correlations_EME_LN, EPU_Emerging_FREQ_CORR_DIFF)                                              #create a single data frame for regression 6

Regression_6 <- lm(Brazil_CORR+Chile_CORR+China_CORR+India_CORR+Mexico_CORR+Pakistan_CORR+Russia_CORR+Korea_CORR                                                                      #run regression 6
                   ~ log10(Brazil_EPU_DIFF+Chile_EPU_DIFF+China_EPU_DIFF+India_EPU_DIFF+Mexico_EPU_DIFF+Pakistan_EPU_DIFF+Russia_EPU_DIFF+Korea_EPU_DIFF) 
                   , data = Regression_CORR_EMR_Data, na.action = na.omit)
summary(Regression_6)                                                                                                    #to have the summary of Regression_6


##ASSUMPTIONS TESTS

##Regression_1: SER_Developed

#MULTICOLLINEARITY - FARRAR-GLAUBER TEST
install.packages("mctest")                             #Install and load necessary packages
library("mctest")

mctest(Regression_1) 

#HOMOSCEDASTIC VARIANCE - GOLDFELD-QUANDT TEST
install.packages("lmtest")                             #Install and load necessary packages 
library("lmtest")

gqtest(Regression_1) 

#NORMALITY OF THE RESIDUALS - JARQUE-BERA TEST
install.packages("desk")                               #Install & load necessary packages
library("desk")

Resid_Reg_1 <- residuals(Regression_1)                 #Extract the residuals of Regression_1
jb.test(Resid_Reg_1)                                   #Jarque-Bera test on residuals of Regression_1

#AUTO-CORRELATION OF THE RESIDUALS - DURBIN-WATSON TEST
#install & load necessary packages
install.packages("car")
library(car)

durbinWatsonTest(Resid_Reg_1)                           #Durbin-Watson test on residuals


##Regression_2: SER_Emerging

#MULTICOLLINEARITY - FARRAR-GLAUBER TEST
install.packages("mctest")                             #Install and load necessary packages
library("mctest")

mctest(Regression_2)

#HOMOSCEDASTIC VARIANCE - GOLDFELD-QUANDT TEST
install.packages("lmtest")                              #Install and load necessary packages 
library("lmtest")

gqtest(Regression_2)

#NORMALITY OF THE RESIDUALS - JARQUE-BERA TEST
install.packages("desk")                                #Install & load necessary packages
library("desk")

Resid_Reg_2 <- residuals(Regression_2)                  #Extract the residuals of Regression 2
jb.test(Resid_Reg_2)                                    #Jarque-Bera test on the residuals of Regression 2

#NON-NORMALITY DETECTED - TROUBLESHOOTING               
hist(Resid_Reg_2)                                       #histogram of residuals
qqplot(Resid_Reg_2, Resid_Reg_2)                        #qqplot


#AUTO-CORRELATION OF THE RESIDUALS - DURBIN-WATSON TEST
install.packages("car")
library(car)

durbinWatsonTest(Resid_Reg_2)                           #Durbin-Watson test on residuals


##Regression_3: BER_Developed

#MULTICOLLINEARITY - FARRAR-GLAUBER TEST

mctest(Regression_3)

#HOMOSCEDASTIC VARIANCE - WHITE TEST
install.packages("whitestrap")                                         #Install & load necessary packages
library("whitestrap")

white_test(Regression_3)     

#NORMALITY OF THE RESIDUALS - JARQUE-BERA TEST

Resid_Reg_3 <- residuals(Regression_3)                                 #Extract the residuals of Regression 3

jb.test(Resid_Reg_3)                                                   #Jarque-Bera test on the residuals of Regression 3
  
#AUTO-CORRELATION OF THE RESIDUALS - DURBIN-WATSON TEST
durbinWatsonTest(Resid_Reg_3)                                          #Durbin-Watson test on the residuals


##Regression_4: BER_Emerging

#MULTICOLLINEARITY - FARRAR-GLAUBER TEST
mctest(Regression_4)

#HOMOSCEDASTIC VARIANCE - WHITE TEST
install.packages("whitestrap")                                         #Install & load necessary packages
library("whitestrap")

white_test(Regression_4)  

#NORMALITY OF THE RESIDUALS - JARQUE-BERA TEST
Resid_Reg_4 <- residuals(Regression_4)                                #Extract the residuals of Regression 4
jb.test(Resid_Reg_4)                                                  #Jarque-Bera test on the residuals of Regression 4

#AUTO-CORRELATION OF THE RESIDUALS - DURBIN-WATSON TEST
durbinWatsonTest(Resid_Reg_4)                                         #Durbin-Watson test on the residuals 


##Regression 5: Correlations_Developed: Simple linear regression

#LINEARITY - SCATTERPLOT WITH REGRESSION LINE
plot(Numeric_data_23, Numeric_data_21, main = "Scatterplot with regression line - 2015-2024 for Developed Countries", xlab= "EPU Indexes", ylab="Share-Bond Excess Returns Correlations")            #creation of the scatter plot with plot() function
regression_line <- lm(Numeric_data_21 ~ Numeric_data_23)                                                                                                                                             #creation of the regression line

abline(regression_line, col = "green")                                                                                                                                                               #add the regression line on the scatter plot (add a straight line to the plot)                         

#HOMOSCEDASTIC VARIANCE - WHITE TEST
white_test(Regression_5)

#NORMALITY OF THE RESIDUALS - JARQUE-BERA TEST 
install.packages("desk")                                              #Install & load necessary packages
library("desk")

Resid_Reg_5 <- residuals(Regression_5)                                #Extract the residuals of Regression 5
jb.test(Resid_Reg_5)                                                  #Jarque-Bera test on the residuals of Regression 5

#AUTO-CORRELATION OF THE RESIDUALS - DURBIN-WATSON TEST
install.packages("car")
library(car)


durbinWatsonTest(Resid_Reg_5)                                         #Durbin-Watson test on the residuals                             


##Regression 6: Correlations_Emerging

#LINEARITY - SCATTERPLOT WITH REGRESSION LINE
plot(Numeric_data_24, Numeric_data_22, main = "Scatterplot with regression line - 2015-2024 for Emerging Countries", xlab= "EPU Indexes", ylab="Share-Bond Excess Returns Correlations")            #creation of the scatter plot with plot() function
regression_line <- lm(Numeric_data_22 ~ Numeric_data_24)                                                                                                                                             #creation of the regression line

abline(regression_line, col = "green")  

#HOMOSCEDASTIC VARIANCE - WHITE TEST
library(whitestrap)
white_test(Regression_6)

#NORMALITY OF THE RESIDUALS - JARQUE-BERA TEST
install.packages("desk")                                              #Install & load necessary packages
library("desk")

Resid_Reg_6 <- residuals(Regression_6)                                #Extract the residuals of Regression 6
jb.test(Resid_Reg_6)                                                  #Jarque-Bera test on the residuals of Regression 6

#AUTO-CORRELATION OF THE RESIDUALS - DURBIN-WATSON TEST 
install.packages("car")
library(car)

durbinWatsonTest(Resid_Reg_6)                                         #Durbin-Watson test on the residuals 




