knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of DHScalendR is to make the use of the DHS calendar easier to use in R. This package is currently being developped, but it already contains functions to:
Next additions will include ways to:
To install the current version of this package:
devtools::install_github("trottieralex/DHScalendR")
This package contains a small exemple dataset extracted from a DHS model dataset, and also a codebook to recode the calendar. The later is primarily to use with the calendar_recode function, but is available for consultation or use.
# Exemple dataset data <- dhs_extract head(data) ?dhs_extract # Calendar codebook head(dhs_calendar_codebook)
The DHS widely use CMC format date (number of month counting from January 1900). A format often convenient for analysis, but hardly interpretable. These function make the transfer CMC from/to Date and years as decimal straigthforward.
library(DHScalendR) # The Date of the Teharan declaration: cmc_to_Date(761) cmc_from_Date(as.Date("1963-05-13")) #Show warning the 1st time # or for April 19, 1989 cmc_to_Year(1072) cmc_from_Year(1989.296)
The split function divides the DHS calendar from a data frame into month columns that are added to the said data frame under the name: "CMCx" + [CMC date of the month]. Once split, the recode function coud be use to obtain more meaning full labels or classification.
dataset <- dhs_extract[95:100, c("V008", "V025", "VCAL.1")] #Dividing months into columns dataset <- calendar_split(dataset, "V008", "VCAL.1") (dataset <- dataset[ ,1:10]) #Recoding of calendar months calendar_recode(dataset$CMCx1326) calendar_recode(c("1","0","P","P","P","T","A","A","A","A","3","3","3"), recoding = "modern_DHS6")
A simple way to subset the DHS calendar for a predefined period of time.
dataset <- DHScalendR::dhs_extract[5:9, ] # Request first half of 2014 calendar_subset(calendar = dataset$VCAL.1, interview = dataset$V008, starting = 1381, ending = cmc_from_Date(as.Date("2015-06-30")))
Look for any event2 that hapenned X months or less after any event1.
example <- c("333000TPPP", "000000BPPP", "0000LLLBPPP") fp <- dhs_calendar_codebook$Recode[dhs_calendar_codebook$modern_DHS6 == "Modern"] # Check if use any modern FP in the 6 months after end pregnancy calendar_combo(calendar = example, event1 = c("B", "T"), n_months = 6, event2 = fp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.