Downloading packages

install.packages("tidyverse", repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## āœ” dplyr     1.1.1     āœ” readr     2.1.4
## āœ” forcats   1.0.0     āœ” stringr   1.5.0
## āœ” ggplot2   3.4.1     āœ” tibble    3.2.1
## āœ” lubridate 1.9.2     āœ” tidyr     1.3.0
## āœ” purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## āœ– dplyr::filter() masks stats::filter()
## āœ– dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
install.packages("psych", repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
library(psych)
## 
## Attaching package: 'psych'
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
install.packages("ggplto2", repos = "https://cloud.r-project.org")
## Warning: package 'ggplto2' is not available for this version of R
## 
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
library(ggplot2)
install.packages("ggthemes",repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
library(ggthemes)
install.packages("gt",repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
library("gt")
install.packages("stargazer",repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
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
install.packages("knitr",repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
library("knitr")
install.packages("kableExtra",repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
library("kableExtra")
## 
## Attaching package: 'kableExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     group_rows

Download data

df <- read_csv("Child.csv", show_col_types = FALSE)

Filtering data for only one year 2012

df2 <- df[df$Year == "2012",]

Filtering data for descriptive statistic for only the numeric variables.

df3 <- select_if(df2, is.numeric)
df4 <- df3[,-1]

Using the describe command on our data and creating a table using the gt package

des4 <- describe(df4)
?gt
table1 <- des4 %>% gt()
table1 %>%
  tab_header(
    title = "Descriptive Statistics", 
    subtitle = "For the 2012 year") %>%
  opt_align_table_header(align = "left") %>%
  fmt_number(columns = everything()) %>%
  tab_source_note("**Sources**: www.childmortality.org ,  http://www.wssinfo.org, International Labour Organization, ILOSTAT database. Data retrieved in November 2017, World Bank staff estimates based on sources and methods in World Bank's The Changing Wealth of Nations: Measuring Sustainable Development in the New Millennium (2011), http://www.fao.org/publications/en/), World Bank staff estimates based on the United Nations Population Division's World Urbanization Prospects: 2014 Revision., washdata.org, United Nations Educational, Scientific, and Cultural Organization (UNESCO) Institute for Statistics.,UNICEF, State of the World's Children, Childinfo, and Demographic and Health Surveys.")
Descriptive Statistics
For the 2012 year
vars n mean sd median trimmed mad min max range skew kurtosis se
1.00 239.00 36.48 34.34 21.60 31.66 24.61 2.40 149.80 147.40 1.12 0.38 2.22
2.00 258.00 9.36 15.13 1.45 5.92 2.15 0.00 76.75 76.75 2.08 4.25 0.94
3.00 233.00 9.87 11.05 5.44 7.90 7.36 0.03 46.50 46.46 1.34 1.07 0.72
4.00 217.00 10,438.08 14,411.30 4,508.33 7,321.53 5,356.99 190.13 78,278.82 78,088.69 2.05 3.96 978.30
5.00 218.00 11.32 9.94 8.22 9.69 8.48 2.50 49.60 47.10 1.37 1.55 0.67
6.00 260.00 42.29 23.29 43.08 42.31 28.61 0.00 91.20 91.20 āˆ’0.02 āˆ’1.00 1.44
7.00 108.00 80.09 24.23 91.74 84.33 10.53 5.88 100.00 94.12 āˆ’1.37 0.82 2.33
8.00 153.00 4.48 1.47 4.43 4.44 1.41 1.50 8.35 6.85 0.23 āˆ’0.32 0.12
9.00 234.00 6.36 2.73 5.86 6.16 2.64 1.19 18.71 17.52 0.95 1.77 0.18
10.00 238.00 87.89 11.95 92.91 89.86 7.54 35.00 99.00 64.00 āˆ’1.62 2.73 0.77
11.00 14.00 42.09 17.82 39.95 42.10 20.61 12.00 72.00 60.00 0.13 āˆ’1.13 4.76
12.00 24.00 53.17 10.56 54.65 53.78 9.27 28.80 69.30 40.50 āˆ’0.64 āˆ’0.48 2.16
13.00 97.00 91.76 16.61 99.00 96.24 1.19 29.30 100.00 70.70 āˆ’2.45 5.01 1.69
**Sources**: www.childmortality.org , http://www.wssinfo.org, International Labour Organization, ILOSTAT database. Data retrieved in November 2017, World Bank staff estimates based on sources and methods in World Bank's The Changing Wealth of Nations: Measuring Sustainable Development in the New Millennium (2011), http://www.fao.org/publications/en/), World Bank staff estimates based on the United Nations Population Division's World Urbanization Prospects: 2014 Revision., washdata.org, United Nations Educational, Scientific, and Cultural Organization (UNESCO) Institute for Statistics.,UNICEF, State of the World's Children, Childinfo, and Demographic and Health Surveys.

Usiing Knitr package and KableExtra to create descriptive table.

table2 <- knitr::kable(des4, 
             "html",
             caption = "World Countries Data",
             digits = 2) %>%
footnote(general = "Sources www.childmortality.org ,  www.wssinfo.org, International Labour Organization, ILOSTAT database. Data retrieved in November 2017, World Bank staff estimates based on sources and methods in World Bank's The Changing Wealth of Nations: Measuring Sustainable Development in the New Millennium (2011), http://www.fao.org/publications/en/), World Bank staff estimates based on the United Nations Population Division's World Urbanization Prospects: 2014 Revision., washdata.org, United Nations Educational, Scientific, and Cultural Organization (UNESCO) Institute for Statistics.,UNICEF, State of the World's Children, Childinfo, and Demographic and Health Surveys.") %>% 
  kable_styling(font_size = 8)
table2
World Countries Data
vars n mean sd median trimmed mad min max range skew kurtosis se
Mortality rate, under-5 (per 1,000 live births) 1 239 36.48 34.34 21.60 31.66 24.61 2.40 149.80 147.40 1.12 0.38 2.22
People practicing open defecation (% of population) 2 258 9.36 15.13 1.45 5.92 2.15 0.00 76.75 76.75 2.08 4.25 0.94
Contributing family workers, total (% of total employment) (modeled ILO estimate) 3 233 9.87 11.05 5.44 7.90 7.36 0.03 46.50 46.46 1.34 1.07 0.72
Adjusted net national income per capita (current US$) 4 217 10438.08 14411.30 4508.33 7321.53 5356.99 190.13 78278.82 78088.69 2.05 3.96 978.30
Prevalence of undernourishment (% of population) 5 218 11.32 9.94 8.22 9.69 8.48 2.50 49.60 47.10 1.37 1.55 0.67
Rural population (% of total population) 6 260 42.29 23.29 43.08 42.31 28.61 0.00 91.20 91.20 -0.02 -1.00 1.44
People using safely managed drinking water services (% of population) 7 108 80.09 24.23 91.74 84.33 10.53 5.88 100.00 94.12 -1.37 0.82 2.33
Government expenditure on education, total (% of GDP) 8 153 4.48 1.47 4.43 4.44 1.41 1.50 8.35 6.85 0.23 -0.32 0.12
Current health expenditure (% of GDP) 9 234 6.36 2.73 5.86 6.16 2.64 1.19 18.71 17.52 0.95 1.77 0.18
Immunization, measles (% of children ages 12-23 months) 10 238 87.89 11.95 92.91 89.86 7.54 35.00 99.00 64.00 -1.62 2.73 0.77
Use of insecticide-treated bed nets (% of under-5 population) 11 14 42.09 17.82 39.95 42.10 20.61 12.00 72.00 60.00 0.13 -1.13 4.76
Diarrhea treatment (% of children under 5 receiving oral rehydration and continued feeding) 12 24 53.17 10.56 54.65 53.78 9.27 28.80 69.30 40.50 -0.64 -0.48 2.16
Births attended by skilled health staff (% of total) 13 97 91.76 16.61 99.00 96.24 1.19 29.30 100.00 70.70 -2.45 5.01 1.69
Note:
Sources www.childmortality.org , www.wssinfo.org, International Labour Organization, ILOSTAT database. Data retrieved in November 2017, World Bank staff estimates based on sources and methods in World Bank’s The Changing Wealth of Nations: Measuring Sustainable Development in the New Millennium (2011), http://www.fao.org/publications/en/), World Bank staff estimates based on the United Nations Population Division’s World Urbanization Prospects: 2014 Revision., washdata.org, United Nations Educational, Scientific, and Cultural Organization (UNESCO) Institute for Statistics.,UNICEF, State of the World’s Children, Childinfo, and Demographic and Health Surveys.

Creating the Histogram for 1 variable

h1 <- hist(df2$`Mortality rate, under-5 (per 1,000 live births)`, 
     breaks = 80, 
     ylim = c(0,25),
     xlim = c(0,175),
     main = "Mortality rate under-5 (n =264)",
     sub = "Source: www.childmortality.org.",
     xlab = "Mortality rate, under-5 (per 1,000 live births)",
     ylab = "frenquency",
     col = "pink")

Creating second Histogram for 1 variable

h2 <- hist(df2$`Prevalence of undernourishment (% of population)`, 
     breaks = 80, 
     ylim = c(0,60),
     xlim = c(0,50),
     main = "Prevalence of undernourishment (n = 264 ",
     sub = " Source:(http://www.fao.org/publications/en/).",
     xlab = "Prevalence of undernourishment (%of population)",
     ylab = "frenquency",
     col = "pink")

Creating a scatterplot between 2 of our variable

plot(x = df2$`Rural population (% of total population)`, y = df2$`People using safely managed drinking water services (% of population)`,
     main = "Rural popolutaion vs  \nSafely driking water services (n = 264",
     sub = " Sources: World Bank staff estimates based on the United Nations Population Division's World Urbanization Prospects: 2014 Revision. n/washdata.org",
     xlab = "Rural polulation (%)",
     ylab = "Poeple safely \ndrinking water services (%)",
     font.main = 1,
     cex.sub = 0.5,
     cex.main = 1,
     cex.lab = 0.6,
     xlim = c(0,100),
     ylim = c(0,100)
     )

F) Creating the OLS regression

install.packages("robustbase",repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/5_/389qrkvs1sd7nkp792bslx5r0000gn/T//Rtmp9bshll/downloaded_packages
library(robustbase)

Creating the regression

set.seed(77)
lmro <- lmrob( df2$`Immunization, measles (% of children ages 12-23 months)` ~ df2$`Current health expenditure (% of GDP)`)

result1 <- summary(lmro)
result1
## 
## Call:
## lmrob(formula = df2$`Immunization, measles (% of children ages 12-23 months)` ~ 
##     df2$`Current health expenditure (% of GDP)`)
##  \--> method = "MM"
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -53.03374  -7.20673  -0.09119   4.81568  10.71892 
## 
## Coefficients:
##                                             Estimate Std. Error t value
## (Intercept)                                  87.1545     3.4444  25.304
## df2$`Current health expenditure (% of GDP)`   0.6086     0.3754   1.621
##                                             Pr(>|t|)    
## (Intercept)                                   <2e-16 ***
## df2$`Current health expenditure (% of GDP)`    0.106    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Robust residual standard error: 6.532 
##   (35 observations deleted due to missingness)
## Multiple R-squared:  0.04171,    Adjusted R-squared:  0.03758 
## Convergence in 19 IRWLS iterations
## 
## Robustness weights: 
##  6 observations c(1,33,53,124,153,183)
##   are outliers with |weight| = 0 ( < 0.00043); 
##  9 weights are ~= 1. The remaining 219 ones are summarized as
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.01122 0.83680 0.93120 0.83460 0.97510 0.99880 
## Algorithmic parameters: 
##        tuning.chi                bb        tuning.psi        refine.tol 
##         1.548e+00         5.000e-01         4.685e+00         1.000e-07 
##           rel.tol         scale.tol         solve.tol       eps.outlier 
##         1.000e-07         1.000e-10         1.000e-07         4.274e-04 
##             eps.x warn.limit.reject warn.limit.meanrw 
##         3.403e-11         5.000e-01         5.000e-01 
##      nResample         max.it       best.r.s       k.fast.s          k.max 
##            500             50              2              1            200 
##    maxit.scale      trace.lev            mts     compute.rd fast.s.large.n 
##            200              0           1000              0           2000 
##                   psi           subsampling                   cov 
##            "bisquare"         "nonsingular"         ".vcov.avar1" 
## compute.outlier.stats 
##                  "SM" 
## seed : int(0)

Using the Stargazer package to create a table for the regression

stargazer(lmro,
          title = "Measles Immunization based on Goverment healt spending",
          dep.var.caption = "DV: Measles Immunization (% of children ages 12-23 months)",
          covariate.labels = c("Goverment health speding"),
          notes.label = "Source:  (http://www.who.int/immunization/monitoring_surveillance/en/). ; (UNESCO) Institute for Statistics || Significance level:",
          add.lines = TRUE,
          keep.stat = c("n","rsq"),
          digits = 2,
          type = "html",
          out = "Economretics.htm")
## 
## <table style="text-align:center"><caption><strong>Measles Immunization based on Goverment healt spending</strong></caption>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td>DV: Measles Immunization (% of children ages 12-23 months)</td></tr>
## <tr><td></td><td colspan="1" style="border-bottom: 1px solid black"></td></tr>
## <tr><td style="text-align:left"></td><td>`Immunization, measles (% of children ages 12-23 months)`</td></tr>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Goverment health speding</td><td>0.61</td></tr>
## <tr><td style="text-align:left"></td><td>(0.38)</td></tr>
## <tr><td style="text-align:left"></td><td></td></tr>
## <tr><td style="text-align:left">Constant</td><td>87.15<sup>***</sup></td></tr>
## <tr><td style="text-align:left"></td><td>(3.44)</td></tr>
## <tr><td style="text-align:left"></td><td></td></tr>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">TRUE</td><td></td></tr>
## <tr><td style="text-align:left">Observations</td><td>234</td></tr>
## <tr><td style="text-align:left">R<sup>2</sup></td><td>0.04</td></tr>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Source: (http://www.who.int/immunization/monitoring; (UNESCO) Institute for Statistics || Significance level:</td><td style="text-align:right"><sup>*</sup>p<0.1; <sup>**</sup>p<0.05; <sup>***</sup>p<0.01</td></tr>
## </table>

Testing the… at significance level of

significant <- result1$coefficients < 0.07
significant2 <- result1$coefficients > 0.07