verbal-autopsy-software / InSilicoVA

R package for InSilicoVA framework
3 stars 6 forks source link

Customized cause grouping with corresponding uncertainty #5

Closed sophiayc closed 5 years ago

sophiayc commented 5 years ago

Hi team, Awesome work! Is it possible to have user-defined further grouping of cause of death categories based upon the original 61/62 Insilico output categories, and have corresponding uncertainty ranges associated with each CSMF please?

Thanks much!

richardli commented 5 years ago

For sure. It's possible, see below codes for a toy example where I grouped the first 30 causes as one group and the second 30 as another.

library(openVA)
data(RandomVA1)
fit <- codeVA(RandomVA1, data.type = "WHO2012", model = "InSilicoVA",
                    Nsim=100, auto.length = TRUE)
my.grouping <- data.frame(causes = as.character(colnames(fit$csmf)))
my.grouping$group <- c(rep("first thirty", 30), rep("second thirty", 30))
my.grouping # check out what the grouping matrix looks like
stackplotVA(fit, type = "dodge", grouping = my.grouping)

You can customize what the my.grouping matrix contains. For example, you can create a similar matrix with meaningful grouping and save as a csv file and read it in every time you need to do this step.

richardli commented 5 years ago

[Repost from another related question] Just to make it more useful, we can also get the CSMF estimates for the grouped causes using the codes above. Following the steps above, we can then do

csmf.new <- g$data

# sanity check: these two should have similar mean value but different CI
# since the direct sum of the lower and upper bound is incorrect
# In this case, the CI from direct sum is clearly wrong (exceeds 1)
# But the values in csmf.new is consistent with the posterior draws
apply(getCSMF(fit)[1:30, ], 2, sum)[c("Mean", "Lower", "Upper")]
apply(getCSMF(fit)[31:60, ], 2, sum)[c("Mean", "Lower", "Upper")]
csmf.new