## ------------------------------------------------------------------------ x <- "Hello" y <- c(1, 2, 3) ## ------------------------------------------------------------------------ x <- 1:100 ## ------------------------------------------------------------------------ x <- matrix(1:24, nrow = 3) y <- array(1:24, dim = c(2, 3, 4)) ## ------------------------------------------------------------------------ x <- x^2 + 1 y <- log(y) ## ------------------------------------------------------------------------ x <- data.frame(ID = 1:4, name = c("A", "B", "C", "D"), color = factor(c("red", "blue", "blue", "green"))) ## ------------------------------------------------------------------------ y <- list(apple = 1:20, orange = x) ## ------------------------------------------------------------------------ x[1:2, ] x[1:2, 2:3] x[, c("ID", "name")] ## ------------------------------------------------------------------------ y[[1]] y[["orange"]] y$orange ## ------------------------------------------------------------ install.packages("ggplot2", dep = TRUE) install.packages("rgdal", dep = TRUE) install.packages("survey", dep = TRUE) install.packages("SUMMER", dep = TRUE) install.packages("readstata13", dep = TRUE) install.packages("gridExtra", dep = TRUE) ## ------------------------------------------------------------ install.packages("INLA", repos=c(getOption("repos"), INLA="https://inla.r-inla-download.org/R/stable")) ## ------------------------------------------------------------------------ library(SUMMER) library(ggplot2) ## ------------------------------------------------------------ sessionInfo() ## ------------------------------------------------------------------------ library(rgdal) geo <- readOGR("../data/shapefiles/sdr_subnational_boundaries.shp", verbose = FALSE) ## ------------------------------------------------------------------------ plot(geo) ## ------------------------------------------------------------------------ library(readstata13) data <- read.dta13("../data/ZZBR62DT/ZZBR62FL.DTA") data <- subset(data, v139 %in% c("region 1", "region 2", "region 3", "region 4")) head(data[, 1:10]) ## ------------------------------------------------------------------------ births <- getBirths(data = data, surveyyear = 2015, strata = c("v023"), dob = "b3", alive = "b5", age = "b7", date.interview= "v008", variables = c("v001", "v002", "v004", "v005", "v021", "v022", "v023", "v024", "v025", "v139"), month.cut = c(1, 12, 24, 36, 48, 60), year.cut = seq(1980, 2020, by = 5)) head(births) ## ------------------------------------------------------------------------ years <- levels(births$time) direct <- getDirect(births = births, years = years,regionVar = "v139", timeVar = "time", clusterVar = "~v001 + v002", ageVar = "age", weightsVar = "v005") ## ------------------------------------------------------------------------ head(direct) ## ------------------------------------------------------------------------ tail(direct) ## ------------------------------------------------------------------------ direct$years <- factor(direct$years, levels = years) g <- ggplot(data = direct, aes(x = years, y = mean, color = region, group = region)) + geom_line() g ## ------------------------------------------------------------------------ g + geom_point() + geom_errorbar(aes(ymin = lower, ymax = upper), width = 0.2) ## ------------------------------------------------------------------------ pos <- position_dodge(width=0.2) g <- ggplot(data = direct, aes(x = years, y = mean, color = region, group = region)) + geom_line(position = pos) + geom_point(position = pos) + geom_errorbar(aes(ymin = lower, ymax = upper), width = 0.2, position = pos) g ## ------------------------------------------------------------------------ g <- ggplot(data = direct, aes(x = years, y = mean, group = region)) + geom_line() + geom_ribbon(aes(ymin = lower, ymax = upper), color = NA, alpha=0.2) + facet_wrap(~region, ncol=5) + geom_point(color = "red") + theme_bw() + theme(axis.text.x=element_text(angle=45, hjust = 1)) + xlab("5-Year Period") + ylab("U5MR") + ggtitle("Direct Estimates of Subnational U5MR") g ## ------------------------------------------------------------------------ data(DemoMap) geo <- DemoMap$geo geo$REGNAME <- paste("region", 1:4) ## ------------------------------------------------------------------------ mapPlot(data = direct, geo = geo, by.data = "region", by.geo = "REGNAME", variables = "years", values = "mean", is.long = TRUE, ncol = 4) ## ------------------------------------------------------------------------ mapPlot(data = direct, geo = geo, by.data = "region", by.geo = "REGNAME", variables = "years", values = "mean", is.long = TRUE, ncol = 4, per1000 = TRUE, size = 0.5, legend.label = "U5MR") + ggtitle("Direct Estimates of Subnational U5MR") ## ------------------------------------------------------------------------ hatchPlot(data = subset(direct, years!="15-19"), geo = geo, by.data = "region", by.geo = "REGNAME", variables = "years", values = "mean", lower = "lower", upper = "upper", is.long = TRUE, ncol = 4, per1000 = TRUE, size = 0.5, legend.label = "U5MR", hatch = "red")