This vignette provides several examples of preparing verbal autopsy (VA) data using the CrossVA function odk2openVA and then assigning a cause of death (CoD) using openVA. CrossVA is designed to work with VA data collected using a questionnare with the same format as the 2016 VA instruments developed by the World Health Organization (WHO) – versions 1.4.1 and 1.5.1 of the 2016 WHO VA instrument and the final version of the 2014 WHO VA instrument are currently supported.

Example R Sessions

CrossVA has a wrapper function with an option to specify the WHO instrument used to collect the data:

This function accepts an export from an Open Data Kit (ODK) Aggregate server as its input. The exported records need to be a comma-separated-values (CSV) file.

Before we load our data and assign CoD, we need to know the path of the folder that contains the data. Sometimes it is useful to change R's current working directory to the folder where the data files is located:

# Print the current working directory
getwd()
#> [1] "C:/Users/LeoMessi/"

# Change your current working directory as follows
setwd("C:/Users/LeoMessi/Verbal-Autopsy")
getwd()
#> [1] "C:/Users/LeoMessi/Verbal-Autopsy"

# Print the files in your current working directory with the dir() function
# (the CSV file you created with ODK Briefcase should be listed)
dir()
#> [1] "vaData_2016.csv"    "vaData_2012.csv" "rCode_for_cleaning_vaData.R"
#> [2] "vaData_report.pdf"  "cat_Videos"

# Load data into R
odkexport <- read.csv("vaData_2016.csv", stringsAsFactors = FALSE)

If you prefer to keep your data in one folder and your R code in another directory, it is possible to use the path to the CSV data file exported by ODK Briefcase – this is used below with the example data file who151_odk_export.csv.

Analysis of 2016 WHO Verbal Autopsy Instrument

Again, CrossVA currently supports version 1.5.1 and 1.4.1 of the 2016 WHO VA questionnaire. If the input data frame (from odk) includes a column containing the string: “age_neonate_hours”, then the function assumes the questionnaire version is 1.4.1 (and assumes version 1.5.1 if the string is not located).

Questionnaire version 1.5.1

# Start by loading the CrossVA and openVA packages from your library
library(CrossVA)
library(openVA)

# Load the CSV from ODK Briefcase (here we use the example data file from the CrossVA package)
## fileNames_v151 contains the path to the example data file
fileName_v151 <- system.file("sample", "who151_odk_export.csv", package = "CrossVA")
fileName_v151
#> [1] "C:/Users/LeoMessi/R/win-library/3.5/CrossVA/sample/who151_va_output.csv"

dir("C:/Users/LeoMessi/R/win-library/3.5/CrossVA/sample/")
#> [1] "who151_odk_export.csv"    "who141_odk_export.csv"    "who2014_odk_export.csv"

# Use the read.csv() function to load the data
odkexport_v151 <- read.csv(fileName_v151, stringsAsFactors = FALSE)

Now that the CSV file is loaded into R, we can use CrossVA's function odk2openVA to convert the CSV file into the proper format (i.e., a data frame with 354 columns).

# Convert VAs using the odk2openVA() function
## we will be able to use either InterVA5 or insilico(data.type = "WHO2016") to assign CoD
openva_input_v151 <- odk2openVA(odkexport_v151)
#> Assuming 2016 WHO questionnaire version is 1.5.1

# For 2016 WHO VA instrument, the output needs to have 354 columns (1 ID + 353 symptoms)
dim(openva_input_v151)
#> [1]  54 354

# ID must be the first column
names(openva_input_v151)
#>   [1] "ID"    "i004a" "i004b" "i019a" "i019b" "i022a" "i022b" "i022c"
#>   [9] "i022d" "i022e" "i022f" "i022g" "i022h" "i022i" "i022j" "i022k"
#>  [17] "i022l" "i022m" "i022n" "i059o" "i077o" "i079o" "i082o" "i083o"
#>  [25] "i084o" "i085o" "i086o" "i087o" "i089o" "i090o" "i091o" "i092o"
#>  [33] "i093o" "i094o" "i095o" "i096o" "i098o" "i099o" "i100o" "i104o"
#>  [41] "i105o" "i106a" "i107o" "i108a" "i109o" "i110o" "i111o" "i112o"
#>  [49] "i113o" "i114o" "i115o" "i116o" "i120a" "i120b" "i123o" "i125o"
#>  [57] "i127o" "i128o" "i129o" "i130o" "i131o" "i132o" "i133o" "i134o"
#>  [65] "i135o" "i136o" "i137o" "i138o" "i139o" "i140o" "i141o" "i142o"
#>  [73] "i143o" "i144o" "i147o" "i148a" "i148b" "i148c" "i149o" "i150a"
#>  [81] "i151a" "i152o" "i153o" "i154a" "i154b" "i155o" "i156o" "i157o"
#>  [89] "i158o" "i159o" "i161a" "i165a" "i166o" "i167a" "i167b" "i168o"
#>  [97] "i169a" "i169b" "i170o" "i171o" "i172o" "i173a" "i174o" "i175o"
#> [105] "i176a" "i178a" "i181o" "i182a" "i182b" "i182c" "i183a" "i184a"
#> [113] "i185o" "i186o" "i187o" "i188o" "i189o" "i190o" "i191o" "i192o"
#> [121] "i193o" "i194o" "i195o" "i197a" "i197b" "i199a" "i199b" "i200o"
#> [129] "i201a" "i201b" "i203a" "i204o" "i205a" "i205b" "i207o" "i208o"
#> [137] "i209a" "i209b" "i210o" "i211a" "i212o" "i213o" "i214o" "i215o"
#> [145] "i216a" "i217o" "i218o" "i219o" "i220o" "i221a" "i221b" "i222o"
#> [153] "i223o" "i224o" "i225o" "i226o" "i227o" "i228o" "i229o" "i230o"
#> [161] "i231o" "i232a" "i233o" "i234a" "i234b" "i235a" "i235b" "i235c"
#> [169] "i235d" "i236o" "i237o" "i238o" "i239o" "i240o" "i241o" "i242o"
#> [177] "i243o" "i244o" "i245o" "i246o" "i247o" "i248a" "i249o" "i250a"
#> [185] "i251o" "i252o" "i253o" "i254o" "i255o" "i256o" "i257o" "i258o"
#> [193] "i259o" "i260a" "i260b" "i260c" "i260d" "i260e" "i260f" "i260g"
#> [201] "i261o" "i262a" "i263a" "i263b" "i264o" "i265o" "i266a" "i267o"
#> [209] "i268o" "i269o" "i270o" "i271o" "i272o" "i273o" "i274a" "i275o"
#> [217] "i276o" "i277o" "i278o" "i279o" "i281o" "i282o" "i283o" "i284o"
#> [225] "i285a" "i286o" "i287o" "i288o" "i289o" "i290o" "i294o" "i295o"
#> [233] "i296o" "i297o" "i298o" "i299o" "i300o" "i301o" "i302o" "i303a"
#> [241] "i304o" "i305o" "i306o" "i309o" "i310o" "i312o" "i313o" "i314o"
#> [249] "i315o" "i316o" "i317o" "i318o" "i319a" "i319b" "i320o" "i321o"
#> [257] "i322o" "i323o" "i324o" "i325o" "i326o" "i327o" "i328o" "i329o"
#> [265] "i330o" "i331o" "i332a" "i333o" "i334o" "i335o" "i336o" "i337a"
#> [273] "i337b" "i337c" "i338o" "i340o" "i342o" "i343o" "i344o" "i347o"
#> [281] "i354o" "i355a" "i356o" "i357o" "i358a" "i360a" "i360b" "i360c"
#> [289] "i361o" "i362o" "i363o" "i364o" "i365o" "i367a" "i367b" "i367c"
#> [297] "i368o" "i369o" "i370o" "i371o" "i372o" "i373o" "i376o" "i377o"
#> [305] "i382a" "i383o" "i384o" "i385a" "i387o" "i388o" "i389o" "i391o"
#> [313] "i393o" "i394a" "i394b" "i395o" "i396o" "i397o" "i398o" "i399o"
#> [321] "i400o" "i401o" "i402o" "i403o" "i404o" "i405o" "i406o" "i408o"
#> [329] "i411o" "i412o" "i413o" "i414a" "i415a" "i418o" "i419o" "i420o"
#> [337] "i421o" "i422o" "i423o" "i424o" "i425o" "i426o" "i427o" "i428o"
#> [345] "i450o" "i451o" "i452o" "i453o" "i454o" "i455o" "i456o" "i457o"
#> [353] "i458o" "i459o"

Now that the VA records have been converted into the expected format, we can use the tools in the openVA package to analyze the data. There are separate functions for each algorithm: InterVA, InterVA5, and insilico. For your convenience, openVA also includes a wrapper function, codeVA, which call any of these algorithms to assign CoD.

# InterVA5
run1 <- InterVA5(openva_input_v151,
                 HIV = "l",
                 Malaria = "l",
                 write = TRUE,
                 directory = getwd())
#> .....9% completed
#> .....19% completed
#> .....28% completed
#> .....37% completed
#> .....46% completed
#> .....56% completed
#> .....65% completed
#> .....74% completed
#> .....83% completed
#> .....93% completed
#> ....

# We could also use codeVA() to get the same results:
## run1 <- codeVA(openva_input_v151,
##                data.type = "WHO2016",
##                model = "InterVA",
##                version = "5.0",
##                HIV = "l",
##                Malaria = "l",
##                write = TRUE,
##                directory = getwd())

By default the parameter write = TRUE, which requires that we pass an argument to directory – the folder where the log file is created. The log file includes information about the VA records that are excluded from the analysis (usually because they have a missing value for age and/or sex) as well as any changes made to ensure the indicators are consistent with each other. We can use the following commands to summarize the results.

# List the top 5 causes in the Cause-Specific Mortality Fraction (CSMF)
summary(run1)
#> InterVA5 fitted on 54 deaths
#> CSMF calculated using reported causes by InterVA5 only
#> The remaining probabilities are assigned to 'Undetermined'
#> 
#> Top 5 CSMFs:
#>  cause                            likelihood
#>  Acute resp infect incl pneumonia 0.2245    
#>  HIV/AIDS related death           0.1115    
#>  Acute cardiac disease            0.1087    
#>  Diarrhoeal diseases              0.0943    
#>  Stroke                           0.0755    
#> 
#> Top 5 Circumstance of Mortality Category:
#>  cause          likelihood
#>  Knowledge      0.3704    
#>  Emergency      0.1852    
#>  Inevitable     0.1852    
#>  Health systems 0.1296    
#>  Culture        0.0741

# We can list more causes with the top parameter.
summary(run1, top = 10)
#> InterVA5 fitted on 54 deaths
#> CSMF calculated using reported causes by InterVA5 only
#> The remaining probabilities are assigned to 'Undetermined'
#> 
#> Top 10 CSMFs:
#>  cause                             likelihood
#>  Acute resp infect incl pneumonia  0.2245    
#>  HIV/AIDS related death            0.1115    
#>  Acute cardiac disease             0.1087    
#>  Diarrhoeal diseases               0.0943    
#>  Stroke                            0.0755    
#>  Pulmonary tuberculosis            0.0754    
#>  Malaria                           0.0471    
#>  Congenital malformation           0.0377    
#>  Birth asphyxia                    0.0377    
#>  Chronic obstructive pulmonary dis 0.0377    
#> 
#> Top 6 Circumstance of Mortality Category:
#>  cause          likelihood
#>  Knowledge      0.3704    
#>  Emergency      0.1852    
#>  Inevitable     0.1852    
#>  Health systems 0.1296    
#>  Culture        0.0741    
#>  Multiple       0.0556

# Create a bar plot of the CSMF.
plotVA(run1)

plot of chunk InterVA5-summary


# InterVA5 will also write an CSV file, called VA5_result.csv, with the CoDs for each record.
# Also note that InterVA5 created the log file, errorlogV5.txt
dir()
#> [1] "VA5_result.csv"               "errorlogV5.txt"              
#> [3] "using-crossva-and-openva.R"   "using-crossva-and-openva.Rmd"

We can also assign CoDs using the InSilicoVA algorithm.

run2 <- insilico(openva_input_v151, data.type = "WHO2016")
#> Performing data consistency check...
#> .....
#> Data check finished.
#> Warning: 66 symptom missing completely and added to missing list 
#> List of missing symptoms: 
#>  i059o, i091o, i093o, i201b, i203a, i204o, i205a, i214o, i216a, i217o, i218o, i219o, i220o, i221a, i221b, i227o, i243o, i244o, i247o, i265o, i275o, i281o, i285a, i287o, i288o, i289o, i290o, i294o, i295o, i296o, i297o, i298o, i299o, i300o, i301o, i302o, i303a, i304o, i305o, i306o, i309o, i310o, i312o, i313o, i314o, i315o, i316o, i317o, i318o, i319a, i319b, i320o, i321o, i322o, i323o, i324o, i325o, i326o, i328o, i334o, i337c, i354o, i355a, i356o, i367a, i402o
#> Not all causes with CSMF > 0.02 are convergent.
#> Increase chain length with another 4000 iterations
#> Not all causes with CSMF > 0.02 are convergent.
#> Increase chain length with another 8000 iterations
#> Not all causes with CSMF > 0.02 are convergent.
#>  Please check using csmf.diag() for more information.

## run2 <- codeVA(openva_input_v151,
##                data.type = "WHO2016",
##                model = "InSilico",
##                version = "WHO2016")

# Print CSMF for top 6 causes
summary(run2, top = 6)
#> InSilicoVA Call: 
#> 54 death processed
#> 16000 iterations performed, with first 8000 iterations discarded
#>  800 iterations saved after thinning
#> Fitted with re-estimated conditional probability level table
#> Data consistency check performed as in InterVA4 
#> 
#> Top 6 CSMFs:
#>                                    Mean Std.Error  Lower Median  Upper
#> Acute resp infect incl pneumonia 0.2331    0.0552 0.1371 0.2283 0.3562
#> HIV/AIDS related death           0.1034    0.0383 0.0440 0.0994 0.1874
#> Diarrhoeal diseases              0.1019    0.0404 0.0448 0.0938 0.1948
#> Acute cardiac disease            0.0983    0.0410 0.0350 0.0925 0.1906
#> Pulmonary tuberculosis           0.0703    0.0380 0.0149 0.0623 0.1607
#> Stroke                           0.0701    0.0333 0.0238 0.0632 0.1497

# Plot CSMF
plotVA(run2)

plot of chunk InSilico

Questionnaire version 1.4.1

# If you have not run the previous code, make sure you have loaded the packages
# library(CrossVA)
# library(openVA)
fileName_v141 <- system.file("sample", "who141_odk_export.csv", package = "CrossVA")
odkexport_v141 <- read.csv(fileName_v141, stringsAsFactors = FALSE)

## Since odkexport has a column name that includes "age_neonate_hours"
## odk2openVA will assume the questionnaire version is 1.4.1
col_age_neonate_hours <- grep("age_neonate_hours",
                              tolower(names(odkexport_v141)))
col_age_neonate_hours
#> [1] 33
names(odkexport_v141)[col_age_neonate_hours]
#> [1] "consented.deceased_CRVS.info_on_deceased.age_neonate_hours"

# Convert VAs using the odk2openVA() function for version 1.4.1
## we will be able to use either InterVA5 or insilico(data.type = "WHO2016") to assign CoD
openva_input_v141 <- odk2openVA(odkexport_v141)
#> Assuming 2016 WHO questionnaire version is 1.4.1
dim(openva_input_v141)
#> [1]  52 354

# Assign CoD with model = InterVA5 and codeVA
run3 <- codeVA(openva_input_v141,
               data.type = "WHO2016",
               model = "InterVA",
               version = "5.0",
               HIV = "l",
               Malaria = "l",
               write = TRUE,
               directory = getwd())
#> .....10% completed
#> .....19% completed
#> .....29% completed
#> .....38% completed
#> .....48% completed
#> .....58% completed
#> .....67% completed
#> .....77% completed
#> .....87% completed
#> .....96% completed
#> ..

## Summarize InterVA5 results
summary(run3)
#> InterVA5 fitted on 52 deaths
#> CSMF calculated using reported causes by InterVA5 only
#> The remaining probabilities are assigned to 'Undetermined'
#> 
#> Top 5 CSMFs:
#>  cause                            likelihood
#>  Diarrhoeal diseases              0.1711    
#>  HIV/AIDS related death           0.1275    
#>  Acute cardiac disease            0.1074    
#>  Acute resp infect incl pneumonia 0.1065    
#>  Road traffic accident            0.0652    
#> 
#> Top 5 Circumstance of Mortality Category:
#>  cause          likelihood
#>  Knowledge      0.2885    
#>  Emergency      0.2500    
#>  Inevitable     0.1538    
#>  Culture        0.1154    
#>  Health systems 0.1154
plotVA(run3)

plot of chunk example141


# Assign CoD with model = InSilico and codeVA
run4 <- codeVA(openva_input_v141,
               data.type = "WHO2016",
               model = "InSilicoVA")
#> Performing data consistency check...
#> .....
#> Data check finished.
#> Warning: 51 symptom missing completely and added to missing list 
#> List of missing symptoms: 
#>  i059o, i091o, i093o, i184a, i199b, i200o, i201b, i203a, i204o, i205a, i213o, i214o, i217o, i218o, i219o, i221a, i227o, i234b, i235a, i243o, i244o, i247o, i260c, i260e, i265o, i275o, i281o, i298o, i299o, i300o, i305o, i306o, i312o, i313o, i315o, i316o, i317o, i318o, i322o, i325o, i328o, i331o, i333o, i334o, i354o, i355a, i356o, i363o, i367a, i387o, i402o
#> Not all causes with CSMF > 0.02 are convergent.
#> Increase chain length with another 10000 iterations
#> Not all causes with CSMF > 0.02 are convergent.
#> Increase chain length with another 20000 iterations
#> Not all causes with CSMF > 0.02 are convergent.
#>  Please check using csmf.diag() for more information.

## Summarize InSilicoVA results
summary(run4)
#> InSilicoVA Call: 
#> 52 death processed
#> 40000 iterations performed, with first 20000 iterations discarded
#>  2000 iterations saved after thinning
#> Fitted with re-estimated conditional probability level table
#> Data consistency check performed as in InterVA4 
#> 
#> Top 10 CSMFs:
#>                                     Mean Std.Error  Lower Median  Upper
#> Diarrhoeal diseases               0.1606    0.0484 0.0802 0.1568 0.2627
#> Assault                           0.1268    0.0000 0.1268 0.1268 0.1268
#> Acute resp infect incl pneumonia  0.1072    0.0439 0.0396 0.1009 0.2093
#> HIV/AIDS related death            0.1029    0.0442 0.0388 0.0966 0.2138
#> Acute cardiac disease             0.0862    0.0357 0.0299 0.0819 0.1680
#> Chronic obstructive pulmonary dis 0.0583    0.0316 0.0119 0.0537 0.1336
#> Prematurity                       0.0546    0.0286 0.0117 0.0507 0.1198
#> Malaria                           0.0381    0.0264 0.0025 0.0323 0.1068
#> Other and unspecified cardiac dis 0.0370    0.0292 0.0017 0.0301 0.1113
#> Accid expos to smoke fire & flame 0.0314    0.0000 0.0314 0.0314 0.0314
plotVA(run4)

plot of chunk example141