This case example seeks to create the case table outlined in the “Data processing across domains” guidance. It is implemented as an R Markdown notebook.
This case example illustrates the world as it is now - what is required to build the table using existing data sources and tools, using Steve’s best efforts (Twitter: @stevenmce).
The second case, to be developed, will illustrate the world as we would like it to be, demonstrating how the set of Best Practices (Group 5) could be implemented, using the relevant Terminology Guidance (Group 4), to be applied to the case studies from the Sustainable Development Goals and Sendai Framework (Group 1) and HIV prevalence and Alpha Network (Group 3).
Our case study is exploring the correlates of the national infant mortality rate across countries. The table we want to create is as follows.
Country | Infant Mortality Rate | Employment Rate | HIV Prevention | GDP | Land Use | … |
---|---|---|---|---|---|---|
A | ||||||
B | ||||||
C | ||||||
D |
So let’s try to build this.
Get the data
#Import DHS Indicator data for Infant Mortality for each survey
json_file <- fromJSON("http://api.dhsprogram.com/rest/dhs/data/CM_ECMT_C_IMR")
# Unlist the JSON file entries
json_data <- lapply(json_file$Data, function(x) { unlist(x) })
# Convert JSON input to a data frame
APIdata <- as.data.frame(do.call("rbind", json_data),stringsAsFactors=FALSE)
# Tabulate the IMR values by the survey IDs
#xtabs(as.numeric(Value) ~ SurveyId, data=APIdata)
plot(APIdata$SurveyYear,APIdata$Value,type = "b",main = "Infant Mortality Rate by Year - Probability of dying before the first birthday per 1,000 live births", ylab = "Infant mortality rate (5 year periods)", xlab = "Year")
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#summary(cars)
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.