Clear memory

rm(list=ls())

Load data: Civil Society Data (csdata)

csdata <- read.csv("/Users/dasha/Desktop/CSDATA1.csv")

Check for missing values

is.na(csdata)
##        Country  Year CSO_Growth No_IGO_Memberships Rmtnc_Inflow_GDP Democracy
##   [1,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##   [2,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##   [3,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##   [4,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##   [5,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##   [6,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##   [7,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##   [8,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##   [9,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [10,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [11,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [12,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [13,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [14,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [15,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [16,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [17,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [18,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [19,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [20,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [21,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [22,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [23,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [24,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [25,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [26,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [27,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [28,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [29,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [30,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [31,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [32,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [33,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [34,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [35,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [36,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [37,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [38,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [39,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [40,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [41,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [42,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [43,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [44,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [45,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [46,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [47,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [48,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [49,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [50,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [51,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [52,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [53,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [54,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [55,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [56,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [57,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [58,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [59,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [60,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [61,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [62,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [63,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [64,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [65,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [66,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [67,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [68,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [69,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [70,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [71,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [72,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [73,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [74,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [75,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [76,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [77,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [78,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [79,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [80,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [81,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [82,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [83,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [84,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [85,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [86,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [87,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [88,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [89,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [90,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [91,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [92,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
##  [93,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [94,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [95,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [96,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [97,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [98,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##  [99,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [100,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [101,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [102,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [103,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [104,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [105,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [106,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [107,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
## [108,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
## [109,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [110,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [111,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [112,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [113,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [114,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [115,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [116,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [117,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [118,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [119,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [120,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [121,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [122,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [123,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [124,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [125,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [126,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [127,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [128,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [129,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [130,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [131,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [132,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [133,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [134,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [135,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [136,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [137,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [138,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [139,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [140,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [141,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [142,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [143,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [144,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [145,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [146,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [147,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [148,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [149,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
## [150,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
## [151,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [152,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [153,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [154,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [155,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [156,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [157,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [158,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [159,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [160,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [161,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [162,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [163,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [164,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [165,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [166,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [167,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [168,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [169,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [170,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [171,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [172,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [173,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [174,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [175,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [176,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [177,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [178,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [179,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [180,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [181,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [182,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [183,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [184,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [185,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [186,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [187,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [188,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [189,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
## [190,]   FALSE FALSE      FALSE              FALSE            FALSE      TRUE
## [191,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [192,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [193,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [194,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [195,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [196,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [197,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [198,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [199,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
## [200,]   FALSE FALSE      FALSE              FALSE            FALSE     FALSE
##          GDP GDP_Per_Capita Population
##   [1,] FALSE          FALSE      FALSE
##   [2,] FALSE          FALSE      FALSE
##   [3,] FALSE          FALSE      FALSE
##   [4,] FALSE          FALSE      FALSE
##   [5,] FALSE          FALSE      FALSE
##   [6,] FALSE          FALSE      FALSE
##   [7,] FALSE          FALSE      FALSE
##   [8,] FALSE          FALSE      FALSE
##   [9,] FALSE          FALSE      FALSE
##  [10,] FALSE          FALSE      FALSE
##  [11,] FALSE          FALSE      FALSE
##  [12,] FALSE          FALSE      FALSE
##  [13,] FALSE          FALSE      FALSE
##  [14,] FALSE          FALSE      FALSE
##  [15,] FALSE          FALSE      FALSE
##  [16,] FALSE          FALSE      FALSE
##  [17,] FALSE          FALSE      FALSE
##  [18,] FALSE          FALSE      FALSE
##  [19,] FALSE          FALSE      FALSE
##  [20,] FALSE          FALSE      FALSE
##  [21,] FALSE          FALSE      FALSE
##  [22,] FALSE          FALSE      FALSE
##  [23,] FALSE          FALSE      FALSE
##  [24,] FALSE          FALSE      FALSE
##  [25,] FALSE          FALSE      FALSE
##  [26,] FALSE          FALSE      FALSE
##  [27,] FALSE          FALSE      FALSE
##  [28,] FALSE          FALSE      FALSE
##  [29,] FALSE          FALSE      FALSE
##  [30,] FALSE          FALSE      FALSE
##  [31,] FALSE          FALSE      FALSE
##  [32,] FALSE          FALSE      FALSE
##  [33,] FALSE          FALSE      FALSE
##  [34,] FALSE          FALSE      FALSE
##  [35,] FALSE          FALSE      FALSE
##  [36,] FALSE          FALSE      FALSE
##  [37,] FALSE          FALSE      FALSE
##  [38,] FALSE          FALSE      FALSE
##  [39,] FALSE          FALSE      FALSE
##  [40,] FALSE          FALSE      FALSE
##  [41,] FALSE          FALSE      FALSE
##  [42,] FALSE          FALSE      FALSE
##  [43,] FALSE          FALSE      FALSE
##  [44,] FALSE          FALSE      FALSE
##  [45,] FALSE          FALSE      FALSE
##  [46,] FALSE          FALSE      FALSE
##  [47,] FALSE          FALSE      FALSE
##  [48,] FALSE          FALSE      FALSE
##  [49,] FALSE          FALSE      FALSE
##  [50,] FALSE          FALSE      FALSE
##  [51,] FALSE          FALSE      FALSE
##  [52,] FALSE          FALSE      FALSE
##  [53,] FALSE          FALSE      FALSE
##  [54,] FALSE          FALSE      FALSE
##  [55,] FALSE          FALSE      FALSE
##  [56,] FALSE          FALSE      FALSE
##  [57,] FALSE          FALSE      FALSE
##  [58,] FALSE          FALSE      FALSE
##  [59,] FALSE          FALSE      FALSE
##  [60,] FALSE          FALSE      FALSE
##  [61,] FALSE          FALSE      FALSE
##  [62,] FALSE          FALSE      FALSE
##  [63,] FALSE          FALSE      FALSE
##  [64,] FALSE          FALSE      FALSE
##  [65,] FALSE          FALSE      FALSE
##  [66,] FALSE          FALSE      FALSE
##  [67,] FALSE          FALSE      FALSE
##  [68,] FALSE          FALSE      FALSE
##  [69,] FALSE          FALSE      FALSE
##  [70,] FALSE          FALSE      FALSE
##  [71,] FALSE          FALSE      FALSE
##  [72,] FALSE          FALSE      FALSE
##  [73,] FALSE          FALSE      FALSE
##  [74,] FALSE          FALSE      FALSE
##  [75,] FALSE          FALSE      FALSE
##  [76,] FALSE          FALSE      FALSE
##  [77,] FALSE          FALSE      FALSE
##  [78,] FALSE          FALSE      FALSE
##  [79,] FALSE          FALSE      FALSE
##  [80,] FALSE          FALSE      FALSE
##  [81,] FALSE          FALSE      FALSE
##  [82,] FALSE          FALSE      FALSE
##  [83,] FALSE          FALSE      FALSE
##  [84,] FALSE          FALSE      FALSE
##  [85,] FALSE          FALSE      FALSE
##  [86,] FALSE          FALSE      FALSE
##  [87,] FALSE          FALSE      FALSE
##  [88,] FALSE          FALSE      FALSE
##  [89,] FALSE          FALSE      FALSE
##  [90,] FALSE          FALSE      FALSE
##  [91,] FALSE          FALSE      FALSE
##  [92,] FALSE          FALSE      FALSE
##  [93,] FALSE          FALSE      FALSE
##  [94,] FALSE          FALSE      FALSE
##  [95,] FALSE          FALSE      FALSE
##  [96,] FALSE          FALSE      FALSE
##  [97,] FALSE          FALSE      FALSE
##  [98,] FALSE          FALSE      FALSE
##  [99,] FALSE          FALSE      FALSE
## [100,] FALSE          FALSE      FALSE
## [101,] FALSE          FALSE      FALSE
## [102,] FALSE          FALSE      FALSE
## [103,] FALSE          FALSE      FALSE
## [104,] FALSE          FALSE      FALSE
## [105,] FALSE          FALSE      FALSE
## [106,] FALSE          FALSE      FALSE
## [107,] FALSE          FALSE      FALSE
## [108,] FALSE          FALSE      FALSE
## [109,] FALSE          FALSE      FALSE
## [110,] FALSE          FALSE      FALSE
## [111,] FALSE          FALSE      FALSE
## [112,] FALSE          FALSE      FALSE
## [113,] FALSE          FALSE      FALSE
## [114,] FALSE          FALSE      FALSE
## [115,] FALSE          FALSE      FALSE
## [116,] FALSE          FALSE      FALSE
## [117,] FALSE          FALSE      FALSE
## [118,] FALSE          FALSE      FALSE
## [119,] FALSE          FALSE      FALSE
## [120,] FALSE          FALSE      FALSE
## [121,] FALSE          FALSE      FALSE
## [122,] FALSE          FALSE      FALSE
## [123,] FALSE          FALSE      FALSE
## [124,] FALSE          FALSE      FALSE
## [125,] FALSE          FALSE      FALSE
## [126,] FALSE          FALSE      FALSE
## [127,] FALSE          FALSE      FALSE
## [128,] FALSE          FALSE      FALSE
## [129,] FALSE          FALSE      FALSE
## [130,] FALSE          FALSE      FALSE
## [131,] FALSE          FALSE      FALSE
## [132,] FALSE          FALSE      FALSE
## [133,] FALSE          FALSE      FALSE
## [134,] FALSE          FALSE      FALSE
## [135,] FALSE          FALSE      FALSE
## [136,] FALSE          FALSE      FALSE
## [137,] FALSE          FALSE      FALSE
## [138,] FALSE          FALSE      FALSE
## [139,] FALSE          FALSE      FALSE
## [140,] FALSE          FALSE      FALSE
## [141,] FALSE          FALSE      FALSE
## [142,] FALSE          FALSE      FALSE
## [143,] FALSE          FALSE      FALSE
## [144,] FALSE          FALSE      FALSE
## [145,] FALSE          FALSE      FALSE
## [146,] FALSE          FALSE      FALSE
## [147,] FALSE          FALSE      FALSE
## [148,] FALSE          FALSE      FALSE
## [149,] FALSE          FALSE      FALSE
## [150,] FALSE          FALSE      FALSE
## [151,] FALSE          FALSE      FALSE
## [152,] FALSE          FALSE      FALSE
## [153,] FALSE          FALSE      FALSE
## [154,] FALSE          FALSE      FALSE
## [155,] FALSE          FALSE      FALSE
## [156,] FALSE          FALSE      FALSE
## [157,] FALSE          FALSE      FALSE
## [158,] FALSE          FALSE      FALSE
## [159,] FALSE          FALSE      FALSE
## [160,] FALSE          FALSE      FALSE
## [161,] FALSE          FALSE      FALSE
## [162,] FALSE          FALSE      FALSE
## [163,] FALSE          FALSE      FALSE
## [164,] FALSE          FALSE      FALSE
## [165,] FALSE          FALSE      FALSE
## [166,] FALSE          FALSE      FALSE
## [167,] FALSE          FALSE      FALSE
## [168,] FALSE          FALSE      FALSE
## [169,] FALSE          FALSE      FALSE
## [170,] FALSE          FALSE      FALSE
## [171,] FALSE          FALSE      FALSE
## [172,] FALSE          FALSE      FALSE
## [173,] FALSE          FALSE      FALSE
## [174,] FALSE          FALSE      FALSE
## [175,] FALSE          FALSE      FALSE
## [176,] FALSE          FALSE      FALSE
## [177,] FALSE          FALSE      FALSE
## [178,] FALSE          FALSE      FALSE
## [179,] FALSE          FALSE      FALSE
## [180,] FALSE          FALSE      FALSE
## [181,] FALSE          FALSE      FALSE
## [182,] FALSE          FALSE      FALSE
## [183,] FALSE          FALSE      FALSE
## [184,] FALSE          FALSE      FALSE
## [185,] FALSE          FALSE      FALSE
## [186,] FALSE          FALSE      FALSE
## [187,] FALSE          FALSE      FALSE
## [188,] FALSE          FALSE      FALSE
## [189,] FALSE          FALSE      FALSE
## [190,] FALSE          FALSE      FALSE
## [191,] FALSE          FALSE      FALSE
## [192,] FALSE          FALSE      FALSE
## [193,] FALSE          FALSE      FALSE
## [194,] FALSE          FALSE      FALSE
## [195,] FALSE          FALSE      FALSE
## [196,] FALSE          FALSE      FALSE
## [197,] FALSE          FALSE      FALSE
## [198,] FALSE          FALSE      FALSE
## [199,] FALSE          FALSE      FALSE
## [200,] FALSE          FALSE      FALSE

Recode missing vaues into NA

csdata$Democracy[csdata$v1==' '] <- NA

Remove NA values

csdata1 <- na.omit(csdata) 

Names of variables

names(csdata1)
## [1] "Country"            "Year"               "CSO_Growth"        
## [4] "No_IGO_Memberships" "Rmtnc_Inflow_GDP"   "Democracy"         
## [7] "GDP"                "GDP_Per_Capita"     "Population"

Browse data

View(csdata1)

Summary Statistics

summary(csdata1)
##    Country               Year        CSO_Growth     No_IGO_Memberships
##  Length:180         Min.   :2005   Min.   :0.0000   Min.   :33.00     
##  Class :character   1st Qu.:2005   1st Qu.:0.0000   1st Qu.:52.00     
##  Mode  :character   Median :2015   Median :0.0000   Median :61.50     
##                     Mean   :2010   Mean   :0.4889   Mean   :62.83     
##                     3rd Qu.:2015   3rd Qu.:1.0000   3rd Qu.:73.25     
##                     Max.   :2015   Max.   :1.0000   Max.   :93.00     
##  Rmtnc_Inflow_GDP     Democracy           GDP            GDP_Per_Capita   
##  Min.   :0.000000   Min.   :0.0000   Min.   :3.655e+08   Min.   :    0.0  
##  1st Qu.:0.005864   1st Qu.:0.0000   1st Qu.:6.670e+09   1st Qu.:  793.8  
##  Median :0.023067   Median :0.0000   Median :1.744e+10   Median : 1851.5  
##  Mean   :0.050192   Mean   :0.4778   Mean   :1.740e+11   Mean   : 2895.7  
##  3rd Qu.:0.070587   3rd Qu.:1.0000   3rd Qu.:6.175e+10   3rd Qu.: 4109.0  
##  Max.   :0.392383   Max.   :1.0000   Max.   :1.050e+13   Max.   :17948.9  
##    Population       
##  Min.   :4.639e+05  
##  1st Qu.:3.854e+06  
##  Median :1.151e+07  
##  Mean   :5.705e+07  
##  3rd Qu.:3.391e+07  
##  Max.   :1.368e+09

Summary statistics presented in a table

library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
stargazer(csdata1, type="text")
## 
## =====================================================================================================
## Statistic           N         Mean              St. Dev.             Min                Max          
## -----------------------------------------------------------------------------------------------------
## Year               180      2,010.056             5.014             2,005              2,015         
## CSO_Growth         180        0.489               0.501               0                  1           
## No_IGO_Memberships 180       62.833              14.070              33                  93          
## Rmtnc_Inflow_GDP   180        0.050               0.068             0.000              0.392         
## Democracy          180        0.478               0.501               0                  1           
## GDP                180 174,009,927,388.000 843,807,886,139.000 365,451,707.000 10,499,697,714,628.000
## GDP_Per_Capita     180      2,895.682           2,870.658           0.000            17,948.920      
## Population         180   57,050,103.000      190,261,741.000     463,929.800     1,368,090,500.000   
## -----------------------------------------------------------------------------------------------------

Data Exploration

Create a new data subset that excludes non-numeric variable (country)

Make a scatterplot matrix to plot the relationships between the variables

cs <- csdata1[,c("CSO_Growth", "No_IGO_Memberships", "Rmtnc_Inflow_GDP", "Democracy", "GDP", "GDP_Per_Capita", "Population")]
pairs(cs,col=cs$CSO_Growth,cex=.5)

Quantify the relationships by computing pairwise correlations

correlation <- cor(cs)
stargazer(correlation, type="text")
## 
## ============================================================================================================
##                    CSO_Growth No_IGO_Memberships Rmtnc_Inflow_GDP Democracy  GDP   GDP_Per_Capita Population
## ------------------------------------------------------------------------------------------------------------
## CSO_Growth             1            0.059             0.158         0.021   0.130      -0.194       0.196   
## No_IGO_Memberships   0.059            1               -0.224        0.231   0.248      0.279        0.294   
## Rmtnc_Inflow_GDP     0.158          -0.224              1           0.132   -0.098     -0.185       -0.098  
## Democracy            0.021          0.231             0.132           1     -0.016     0.269        0.017   
## GDP                  0.130          0.248             -0.098       -0.016     1        0.194        0.747   
## GDP_Per_Capita       -0.194         0.279             -0.185        0.269   0.194        1          0.016   
## Population           0.196          0.294             -0.098        0.017   0.747      0.016          1     
## ------------------------------------------------------------------------------------------------------------

Calculate frequencies for CSO_Growth

# install.packages('plyr')
library('plyr')
count(csdata1, "Democracy") 
##   Democracy freq
## 1         0   94
## 2         1   86

Calculate frequencies for Democracy

# install.packages('plyr')
library('plyr')
count(csdata1, "CSO_Growth") 
##   CSO_Growth freq
## 1          0   92
## 2          1   88

Logistic regression

#  Fit a logistic regression model to predict "Increase in Number of CSOs" using Remittances, Democracy, GDP/Capita and Population
glm.fit=glm(CSO_Growth~No_IGO_Memberships+Rmtnc_Inflow_GDP+Democracy+GDP+GDP_Per_Capita+Population, data=csdata1,family=binomial)
summary(glm.fit)
## 
## Call:
## glm(formula = CSO_Growth ~ No_IGO_Memberships + Rmtnc_Inflow_GDP + 
##     Democracy + GDP + GDP_Per_Capita + Population, family = binomial, 
##     data = csdata1)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.8355  -1.0718  -0.4493   1.1344   1.8750  
## 
## Coefficients:
##                      Estimate Std. Error z value Pr(>|z|)  
## (Intercept)        -4.647e-01  8.308e-01  -0.559   0.5759  
## No_IGO_Memberships  3.661e-03  1.358e-02   0.270   0.7875  
## Rmtnc_Inflow_GDP    5.287e+00  2.626e+00   2.013   0.0441 *
## Democracy           1.723e-01  3.487e-01   0.494   0.6211  
## GDP                 5.348e-13  1.274e-12   0.420   0.6746  
## GDP_Per_Capita     -1.853e-04  8.375e-05  -2.213   0.0269 *
## Population          9.268e-09  6.403e-09   1.447   0.1478  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 249.44  on 179  degrees of freedom
## Residual deviance: 222.45  on 173  degrees of freedom
## AIC: 236.45
## 
## Number of Fisher Scoring iterations: 6

Predict function

# I use the predict function to predict the probability of an increase in the number of CSOs, given values of the predictors.
glm.probs=predict(glm.fit,type="response") 
glm.probs[1:5]
##         2         3         4         5         6 
## 0.5087720 0.5654667 0.4258202 0.4134387 0.3692769
# I coded "Increase in CSOs" as 1, so glm.probs are the probabilities of No_CSO_Increased. going up. Here I create actual labels instead of probabilities.
glm.pred=ifelse(glm.probs>0.5,"Increase","No Increase")

# Confusion matrix
attach(csdata1)
table(glm.pred,CSO_Growth) # predictions vs. truth
##              CSO_Growth
## glm.pred       0  1
##   Increase    28 51
##   No Increase 64 37

Check accuracy / Compute the fraction of CSO_Growth for which the prediction was correct

mean(glm.pred==CSO_Growth)
## [1] 0

Split the data into training and test sets

# Create a vector corresponding to the observations from 2005
train = Year<2015

# Fit the logistic regression using only the train data
glm.fit=glm(CSO_Growth ~ No_IGO_Memberships + Rmtnc_Inflow_GDP + Democracy + GDP + GDP_Per_Capita + Population, data=csdata1,family=binomial, subset=train)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
# Test the model by fitting the test data into the fitted model
glm.probs=predict(glm.fit,newdata=csdata1[!train,],type="response") 

# Compute the predictions for 2015 and compare them to the actual 
# increase in number of CSOs over that time period
glm.pred=ifelse(glm.probs >0.5,"1","0")
CSO_Growth.2015=csdata1$CSO_Growth[!train]
table(glm.pred,CSO_Growth.2015)
##         CSO_Growth.2015
## glm.pred  0  1
##        0 24  8
##        1 40 19

Test error rate

mean(glm.pred==CSO_Growth.2015)
## [1] 0.4725275

Training error rate

mean(glm.pred != CSO_Growth.2015)
## [1] 0.5274725

Check accuracy rate

19/(40+19)
## [1] 0.3220339