library(rio)
SS=import("safeandsecurity.xlsx")
ML=import("militarisation.xlsx")
OC=import("ongoinconflicts.xlsx")
str(SS)
## 'data.frame':    163 obs. of  17 variables:
##  $ Country: chr  "Afghanistan" "Albania" "Algeria" "Angola" ...
##  $ iso3c  : chr  "AFG" "ALB" "DZA" "AGO" ...
##  $ 2008   : num  3.39 2.29 2.56 2.46 2.37 ...
##  $ 2009   : num  3.59 2.21 2.54 2.39 2.52 ...
##  $ 2010   : num  3.4 2.18 2.52 2.3 2.53 ...
##  $ 2011   : num  3.41 2.18 2.69 2.38 2.63 ...
##  $ 2012   : num  3.63 2.21 2.67 2.36 2.54 ...
##  $ 2013   : num  3.72 2.23 2.68 2.48 2.59 ...
##  $ 2014   : num  3.63 2.27 2.54 2.39 2.49 ...
##  $ 2015   : num  3.89 2.25 2.41 2.38 2.61 ...
##  $ 2016   : num  3.85 2.19 2.42 2.38 2.67 ...
##  $ 2017   : num  3.86 2.23 2.31 2.44 2.58 ...
##  $ 2018   : num  4.03 2.11 2.31 2.34 2.58 ...
##  $ 2019   : num  4.09 2.15 2.33 2.35 2.72 ...
##  $ 2020   : num  4.15 2.15 2.37 2.38 2.72 ...
##  $ 2021   : num  4.18 2.14 2.44 2.48 2.61 ...
##  $ 2022   : num  4.13 2.12 2.3 2.41 2.66 ...
str(ML)
## 'data.frame':    163 obs. of  17 variables:
##  $ Country: chr  "Afghanistan" "Albania" "Algeria" "Angola" ...
##  $ iso3c  : chr  "AFG" "ALB" "DZA" "AGO" ...
##  $ 2008   : num  2.21 1.75 2.03 1.83 1.4 ...
##  $ 2009   : num  2.23 1.79 2.12 1.84 1.39 ...
##  $ 2010   : num  2.27 1.79 2.14 1.74 1.38 ...
##  $ 2011   : num  2.19 1.91 2.14 1.77 1.34 ...
##  $ 2012   : num  2.32 1.87 2.14 1.97 1.33 ...
##  $ 2013   : num  2.55 1.91 2.14 1.91 1.51 ...
##  $ 2014   : num  2.51 1.82 2.03 2.08 1.59 ...
##  $ 2015   : num  2.47 1.85 2.12 1.97 1.7 ...
##  $ 2016   : num  2.42 1.76 2.08 2.04 1.59 ...
##  $ 2017   : num  2.44 1.75 2.15 1.81 1.56 ...
##  $ 2018   : num  2.48 1.72 2.18 1.88 1.76 ...
##  $ 2019   : num  2.42 1.66 2.25 1.75 1.77 ...
##  $ 2020   : num  2.61 1.63 2.24 1.83 1.66 ...
##  $ 2021   : num  2.57 1.66 2.25 1.78 1.78 ...
##  $ 2022   : num  2.47 1.67 2.04 1.71 1.61 ...
str(OC)
## 'data.frame':    163 obs. of  17 variables:
##  $ Country: chr  "Afghanistan" "Albania" "Algeria" "Angola" ...
##  $ iso3c  : chr  "AFG" "ALB" "DZA" "AGO" ...
##  $ 2008   : num  3.38 1.24 2.23 1.73 1.4 ...
##  $ 2009   : num  3.42 1.24 2.29 1.84 1.6 ...
##  $ 2010   : num  3.22 1.24 2.3 1.84 1.6 ...
##  $ 2011   : num  3.21 1.24 2.51 1.84 1.4 ...
##  $ 2012   : num  3.21 1.24 2.29 1.84 1.4 ...
##  $ 2013   : num  3.25 1.24 2.22 1.73 1.6 ...
##  $ 2014   : num  3.25 1.24 2.2 1.63 1.4 ...
##  $ 2015   : num  3.25 1.22 2.22 1.44 1.4 ...
##  $ 2016   : num  3.47 1.23 2.18 1.42 1.4 ...
##  $ 2017   : num  3.6 1.22 2.17 1.41 1.4 ...
##  $ 2018   : num  3.64 1.22 2.16 1.59 1.2 ...
##  $ 2019   : num  3.64 1.21 2.16 1.64 1.2 ...
##  $ 2020   : num  3.64 1.41 2.12 1.64 1.2 ...
##  $ 2021   : num  3.64 1.4 2.09 1.66 1.2 ...
##  $ 2022   : num  3.65 1.4 2.07 1.67 1.2 ...
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
ML=select(ML, c(2, 17))

names(ML)=c("country", "mili2022")
OC=select(OC, c(2,17))
names(OC)=c("country","ongoing2022")
SS=select(SS,c(2,17))
names(SS)=c("country","ss2022")
merge1=inner_join(ML,OC)
## Joining, by = "country"
peace=inner_join(merge1,SS)
## Joining, by = "country"
names(peace)
## [1] "country"     "mili2022"    "ongoing2022" "ss2022"
r1=lm(ss2022 ~ mili2022, data = peace)
summary(r1)
## 
## Call:
## lm(formula = ss2022 ~ mili2022, data = peace)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.30327 -0.42834  0.04095  0.39354  1.52883 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.4761     0.2200   6.709 3.17e-10 ***
## mili2022      0.5006     0.1149   4.357 2.34e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.598 on 161 degrees of freedom
## Multiple R-squared:  0.1055, Adjusted R-squared:  0.09991 
## F-statistic: 18.98 on 1 and 161 DF,  p-value: 2.342e-05
r2=lm(ss2022 ~ mili2022+ongoing2022,data = peace)
summary(r2)
## 
## Call:
## lm(formula = ss2022 ~ mili2022 + ongoing2022, data = peace)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.84391 -0.29822 -0.01298  0.27144  1.39927 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.16236    0.16049   7.243 1.75e-11 ***
## mili2022    -0.01016    0.09261  -0.110    0.913    
## ongoing2022  0.69696    0.05681  12.268  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4306 on 160 degrees of freedom
## Multiple R-squared:  0.539,  Adjusted R-squared:  0.5333 
## F-statistic: 93.55 on 2 and 160 DF,  p-value: < 2.2e-16
anova(r1,r2)
## Analysis of Variance Table
## 
## Model 1: ss2022 ~ mili2022
## Model 2: ss2022 ~ mili2022 + ongoing2022
##   Res.Df    RSS Df Sum of Sq     F    Pr(>F)    
## 1    161 57.570                                 
## 2    160 29.665  1    27.904 150.5 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1