Using CrossVA and openVA

Jason Thomas

2021-08-10

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

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" "i022d"
#>  [10] "i022e" "i022f" "i022g" "i022h" "i022i" "i022j" "i022k" "i022l" "i022m"
#>  [19] "i022n" "i059o" "i077o" "i079o" "i082o" "i083o" "i084o" "i085o" "i086o"
#>  [28] "i087o" "i089o" "i090o" "i091o" "i092o" "i093o" "i094o" "i095o" "i096o"
#>  [37] "i098o" "i099o" "i100o" "i104o" "i105o" "i106a" "i107o" "i108a" "i109o"
#>  [46] "i110o" "i111o" "i112o" "i113o" "i114o" "i115o" "i116o" "i120a" "i120b"
#>  [55] "i123o" "i125o" "i127o" "i128o" "i129o" "i130o" "i131o" "i132o" "i133o"
#>  [64] "i134o" "i135o" "i136o" "i137o" "i138o" "i139o" "i140o" "i141o" "i142o"
#>  [73] "i143o" "i144o" "i147o" "i148a" "i148b" "i148c" "i149o" "i150a" "i151a"
#>  [82] "i152o" "i153o" "i154a" "i154b" "i155o" "i156o" "i157o" "i158o" "i159o"
#>  [91] "i161a" "i165a" "i166o" "i167a" "i167b" "i168o" "i169a" "i169b" "i170o"
#> [100] "i171o" "i172o" "i173a" "i174o" "i175o" "i176a" "i178a" "i181o" "i182a"
#> [109] "i182b" "i182c" "i183a" "i184a" "i185o" "i186o" "i187o" "i188o" "i189o"
#> [118] "i190o" "i191o" "i192o" "i193o" "i194o" "i195o" "i197a" "i197b" "i199a"
#> [127] "i199b" "i200o" "i201a" "i201b" "i203a" "i204o" "i205a" "i205b" "i207o"
#> [136] "i208o" "i209a" "i209b" "i210o" "i211a" "i212o" "i213o" "i214o" "i215o"
#> [145] "i216a" "i217o" "i218o" "i219o" "i220o" "i221a" "i221b" "i222o" "i223o"
#> [154] "i224o" "i225o" "i226o" "i227o" "i228o" "i229o" "i230o" "i231o" "i232a"
#> [163] "i233o" "i234a" "i234b" "i235a" "i235b" "i235c" "i235d" "i236o" "i237o"
#> [172] "i238o" "i239o" "i240o" "i241o" "i242o" "i243o" "i244o" "i245o" "i246o"
#> [181] "i247o" "i248a" "i249o" "i250a" "i251o" "i252o" "i253o" "i254o" "i255o"
#> [190] "i256o" "i257o" "i258o" "i259o" "i260a" "i260b" "i260c" "i260d" "i260e"
#> [199] "i260f" "i260g" "i261o" "i262a" "i263a" "i263b" "i264o" "i265o" "i266a"
#> [208] "i267o" "i268o" "i269o" "i270o" "i271o" "i272o" "i273o" "i274a" "i275o"
#> [217] "i276o" "i277o" "i278o" "i279o" "i281o" "i282o" "i283o" "i284o" "i285a"
#> [226] "i286o" "i287o" "i288o" "i289o" "i290o" "i294o" "i295o" "i296o" "i297o"
#> [235] "i298o" "i299o" "i300o" "i301o" "i302o" "i303a" "i304o" "i305o" "i306o"
#> [244] "i309o" "i310o" "i312o" "i313o" "i314o" "i315o" "i316o" "i317o" "i318o"
#> [253] "i319a" "i319b" "i320o" "i321o" "i322o" "i323o" "i324o" "i325o" "i326o"
#> [262] "i327o" "i328o" "i329o" "i330o" "i331o" "i332a" "i333o" "i334o" "i335o"
#> [271] "i336o" "i337a" "i337b" "i337c" "i338o" "i340o" "i342o" "i343o" "i344o"
#> [280] "i347o" "i354o" "i355a" "i356o" "i357o" "i358a" "i360a" "i360b" "i360c"
#> [289] "i361o" "i362o" "i363o" "i364o" "i365o" "i367a" "i367b" "i367c" "i368o"
#> [298] "i369o" "i370o" "i371o" "i372o" "i373o" "i376o" "i377o" "i382a" "i383o"
#> [307] "i384o" "i385a" "i387o" "i388o" "i389o" "i391o" "i393o" "i394a" "i394b"
#> [316] "i395o" "i396o" "i397o" "i398o" "i399o" "i400o" "i401o" "i402o" "i403o"
#> [325] "i404o" "i405o" "i406o" "i408o" "i411o" "i412o" "i413o" "i414a" "i415a"
#> [334] "i418o" "i419o" "i420o" "i421o" "i422o" "i423o" "i424o" "i425o" "i426o"
#> [343] "i427o" "i428o" "i450o" "i451o" "i452o" "i453o" "i454o" "i455o" "i456o"
#> [352] "i457o" "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.

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.

We can also assign CoDs using the InSilicoVA algorithm.

run2 <- insilico(openva_input_v151, data.type = "WHO2016")
#> Using Probbase version:  probbase v19 20210720
#> 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 InterVA5
#> 
#> Top 6 CSMFs:
#>                                    Mean Std.Error  Lower Median  Upper
#> Acute resp infect incl pneumonia 0.2247    0.0553 0.1331 0.2183 0.3394
#> HIV/AIDS related death           0.1040    0.0388 0.0454 0.0986 0.1978
#> Diarrhoeal diseases              0.1000    0.0402 0.0429 0.0941 0.1951
#> Acute cardiac disease            0.0996    0.0424 0.0363 0.0919 0.1985
#> Prematurity                      0.0872    0.0358 0.0319 0.0825 0.1662
#> Pulmonary tuberculosis           0.0695    0.0334 0.0176 0.0641 0.1435

# Plot CSMF
plotVA(run2)

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())
#> Using Probbase version:  probbase v19 20210720
#> .....10% completed
#> .....19% completed
#> .....29% completed
#> .....38% completed
#> .....48% completed
#> .....58% completed
#> .....67% completed
#> .....77% completed
#> .....87% completed
#> .....96% completed
#> ..100% completed

## Summarize InterVA5 results
summary(run3)
#> InterVA5 fitted on 51 deaths
#> CSMF calculated using reported causes by InterVA5 only
#> The remaining probabilities are assigned to 'Undetermined'
#> 
#> Top 5 CSMFs:
#>  cause                            likelihood
#>  Undetermined                     0.1301    
#>  HIV/AIDS related death           0.1258    
#>  Diarrhoeal diseases              0.1236    
#>  Acute cardiac disease            0.0969    
#>  Acute resp infect incl pneumonia 0.0961    
#> 
#> Top 5 Circumstance of Mortality Category:
#>  cause          likelihood
#>  Knowledge      0.2745    
#>  Emergency      0.2549    
#>  Inevitable     0.1765    
#>  Culture        0.1176    
#>  Health systems 0.0980
plotVA(run3)


# Assign CoD with model = InSilico and codeVA
run4 <- codeVA(openva_input_v141,
               data.type = "WHO2016",
               model = "InSilicoVA")
#> Using Probbase version:  probbase v19 20210720
#> Performing data consistency check...
#> .....
#> Data check finished.
#> Warning: 52 symptom missing completely and added to missing list 
#> List of missing symptoms: 
#>  i091o, i093o, i184a, i199b, i200o, i201b, i203a, i204o, i205a, i213o, i214o, i217o, i227o, i234b, i235a, i243o, i244o, i247o, i260c, i260e, i265o, i275o, i281o, i289o, i290o, i294o, i298o, i299o, i300o, i305o, i306o, i309o, i310o, i312o, i313o, i314o, 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: 
#> 51 death processed
#> 40000 iterations performed, with first 20000 iterations discarded
#>  1000 iterations saved after thinning
#> Fitted with re-estimated conditional probability level table
#> Data consistency check performed as in InterVA5
#> 
#> Top 10 CSMFs:
#>                                     Mean Std.Error  Lower Median  Upper
#> Assault                           0.1292    0.0000 0.1292 0.1292 0.1292
#> Diarrhoeal diseases               0.1287    0.0475 0.0487 0.1258 0.2319
#> HIV/AIDS related death            0.1157    0.0475 0.0418 0.1092 0.2354
#> Acute resp infect incl pneumonia  0.1078    0.0442 0.0397 0.1015 0.2048
#> Acute cardiac disease             0.0864    0.0372 0.0283 0.0816 0.1735
#> Prematurity                       0.0747    0.0334 0.0233 0.0705 0.1488
#> Chronic obstructive pulmonary dis 0.0538    0.0308 0.0109 0.0491 0.1300
#> Malaria                           0.0393    0.0265 0.0064 0.0325 0.1079
#> Stroke                            0.0339    0.0258 0.0012 0.0283 0.0961
#> Accid expos to smoke fire & flame 0.0320    0.0000 0.0320 0.0320 0.0320
plotVA(run4)