knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README_files/README-" )
This is the
R package accompanying our paper: Evaluating diagnostic tests and quantifying prevalence for Tropical Infectious Diseases: a Paradigm of Latent Class Modelling Approaches With and Without a Gold Standard for Schistosomiasis Diagnosis.
There are three models primarily used in this package: latent class model (LC), latent class with random effects model (LCRE), and a finite mixture model (FM).
Details of these models and their use for modelling diagnostic errors are found in the paper.
The package includes functions to
JAGS) and obtain estimates posterior standard deviations of sensitivities, specificities, prevalence.
The easiest way to then install from this repo is by using the devtools package. Install this first.
Then, run the following code to install and attach the
The default number of items is six (including a gold standard item), with the sensitivities and specificities as shown above.
To change this, use the
# Change sensitivities, specificities and item names diagacc_opt(sens = c(0.1, 0.2, 0.3), spec = c(0.1, 0.2, 0.3), item.names = LETTERS[1:3]) # Restore default options diagacc_opt(default = TRUE)
The functions to simulate a data set are
# Sample size (n), proportion of missing gold item (miss.prop), and prevalence # (tau), using a specific random seedmys X <- gen_lc(n = 1000, miss.prop = 0.5, tau = 0.1, seed = 123) head(X)
The functions for model fitting are
The MCMC options are pretty much the default settings in
These, of course, can be changed--see the help files for more information.
# Fitting a LC model using MCMC (mod1 <- fit_lc(X))
There is also the option for
raw = TRUE, which returns the actual
rjags or object for further inspection or manipulation.
This is especially useful for MCMC diagnostics.
# Running 8 chains in parallel mod2 <- fit_lcre(X, method = "MCMC", raw = TRUE, silent = TRUE, n.chains = 8, runjags.method = "parallel") plot(mod2, plot.type = "density", layout = c(3, 2), vars = "beta")
To perform a simulation study, use the
For instance, consider the following scenario: sample size = 500, prevalence = 0.1, missing gold standard = 20%, and data generated from a LCRE model.
We shall run this for a total of
B=8 replications (just for show).
The result is a table showing the estimates of the prevalance, sensitivities and specificities for all items except gold standard item, as fitted using the LC, LCRE and FM model.
(res <- run_sim_par(B = 8, n = 1000, tau = 0.1, miss.prop = 0.5, data.gen = "lcre", no.cores = 8))
run_sim_par() runs the replications concurrently in parallel across the specified number of cores of the machine.
There is also a non-parallel implementation of this function called
One can also plot the results, as follows:
One thing to mention is that it is possible to add more replications of a particular saved
diagaccSim1 object created by
run_sim_par() simply by running the following code:
# To run additional B = 100 simulations run_sim(object = res, B = 100) run_sim_par(object = res, B = 100)
It will automatically read in all the previous simulation scenarios.
Often, there is an interest to run multiple simulation scenarios, for example, multiple sample sizes, prevalences, and proportion of missing gold standard.
One might use the above functions in a nested for loop manually, or use the in-built
res <- run_study_par(B = 8, n = 250, tau = c(0.08, 0.4), miss.prop = 1.0)
The above code will run a total of six simulation scenarios (1 sample size x 2 prevalences x 1 missing gold proportions x 3 data generating mechanisms).
To access any one of these scenarios, use the corresponding
Currently available methods are
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.