The following description is redundant, so I should omit it.
To avoid that readers are bothered to read the following, the author puts Buffer zone.
Available from CRAN .
install.packages("BayesianFROC")
# Please execute it from the R console (or the R studio console), which installs the released version of `BayesianFROC`
A single reader and a single modality (SRSM) case
To fit a model to the SRSM data, fit_a_model_to()
would be adequate for the purpose.
Multiple Readers and Multiple Modalities Case
See vignette (Because package size restriction (< 5Mb), it is omitted.)
A pre-print: Bayesian Models for Free-response Receiver Operating Characteristic Analysis
BayesianFROC
Comparison of imaging modality. In some context, modality is imaging methods: MRI, CT, PET,…etc, and the another context, if images are taken for treatment (case) group and untreatment (or another treatment) (control) group, then modality means efficacy of treatment.
Confidence Level | Number of Hits | Number of False alarms |
---|---|---|
3 = definitely present | 97 | 1 |
2 = equivocal | 32 | 14 |
1 = questionable | 31 | 74 |
where hit means the number of True Positive, briefly TP, and false alarm the number False Positive, FP, respectively.
#0) To avoid the following error in Readme file,
#I have to attach the Rcpp.
#I do not know why such error occur withou Rcpp.
#This error occurs only when I run the following R scripts from readme.
#Error
#in do.call(rbind,sampler_params) :second argument must be a list Calles:<Anonymous>...get_divergent_iterations ->sampler_param_vector =. do.call Execution halted
library(Rcpp) # This code can remove the above unknown error, if someone know why the error occur, please tell me.
library(BayesianFROC)
#1) Build data for single reader and single modality case.
dataList <- list(c=c(3,2,1), # c is ignored, can omit.
h=c(97,32,31),
f=c(1,14,74),
NL=259,
NI=57,
C=3)
# where,
# c denotes confidence level, each components indicates that
# 3 = Definitely lesion,
# 2 = subtle,
# 1 = very subtle
# h denotes number of hits
# (True Positives: TP) for each confidence level,
# f denotes number of false alarms
# (False Positives: FP) for each confidence level,
# NL denotes number of lesions (signal),
# NI denotes number of images,
#2) Fit the FROC model.
fit <- BayesianFROC::fit_Bayesian_FROC(
# data to which we fit a model
dataList = dataList,
# The number of MCMC chains
cha = 1,
# The number of MCMC samples for each chains
ite = 555,
# The number of warming up of MCMC simulation for each chains
war = 111,
# Show verbose summary and MCMC process
summary = TRUE )
# validation of fit via calculation of p -value of the chi square goodness of fit, which is
# calculated by integrating with predictive posterior measure.
plot_dataset_of_ppp( fit )
# The author thinks it is probably coded correctly, so it needs validation of program
In order to apply the functions in this package to an xlsx file representing a dataset formulated for Jafroc, use the following code;
where it requires to specify the number of modalities, readers, confidence levels.
Using the above code, an object is created from an xlsx file.
Using the fitted model object fit
of class stanfitExtended
, we can draw the FROC curve (or AFROC curve) as follows;
# new.imaging.device = FALSE is used to include the output image
# in this README file, so I recommand new.imaging.device = TRUE
BayesianFROC::DrawCurves(fit,
new.imaging.device = FALSE)
# new.imaging.device = FALSE is used to include the output image
# in this README file, so I recommand new.imaging.device = TRUE.
BayesianFROC::DrawCurves(fit,
Colour = FALSE,
new.imaging.device = FALSE)
Executing the above code, an imaging device will appears in which there are circles indicating the so-called False Positive Fractions (FPFs) and True Positive Fractions (TPFs). In addition, an FROC curve is plotted. FROC curve thorough exactly the expected points of FPFs and TPFs. Thus we can intuitively confirm the goodness of fit by comparing the circles and the curve. Ha,… someone reads this boring vignettes? My right arm ache bothering me for 20 months. Ha,… I want to die. I developed theory and package, but this research cannot make me happy, cannot change anything about my poor life… ha.
Hit rates are determined the areas of signal Gaussian between thresholds,
and false alarm rate are defined by the areas of differential logarithmic cumulative Gaussian between thresholds.
# new.imaging.device = FALSE is used to include the output image
# in this README file, so I recommend new.imaging.device = TRUE
BayesianFROC::draw_bi_normal_version_UP(
fit,
new.imaging.device = F,
dark_theme = T,
hit.rate = F,
false.alarm.rate = T,
both.hit.and.false.rate = F)
# new.imaging.device = FALSE is used to include the output image
# in this README file, so I recommend new.imaging.device = TRUE
BayesianFROC::draw_bi_normal_version_UP(
fit,
new.imaging.device = F,
dark_theme = T,
hit.rate = T,
false.alarm.rate = F,
both.hit.and.false.rate = F)
One will see that the bi normal assumption is wrong in the FROC context, and instead of bi normal assumption, we use two latent distributions, one is Gaussian for signal and another is the differential logarithmic Gaussian introduced first by the author of this package. For details, see vignettes of this package.
By fitting hierarchical Bayesian model, we can get the characteristics such as AUCs for each imaging modality (MRI,PET,CT,etc) to compare modalities.
Using the data object named BayesianFROC::dataList.Chakra.Web
representing multiple modality data, we will fit the model to data by the following R script. For letting the running time be short, we take small MCMC iteration, that is, ite =222
which is too small to obtain reliable estimates. I think it should be ite =33333
for actual data analysis or compatible result with Jafroc.
The author try to remove eval=FALSE
, but it cause stopping of knitr, so I can not include the following code. The following code sometimes crash R session, so,… it is heavy for README file??
#0) To avoid the following error I have to attach the Rcpp. I do not know why such error occur withou Rcpp.
#Error in do.call(rbind,sampler_params) :second argument must be a list Calles:<Anonymous>...get_divergent_iterations ->sampler_param_vector =. do.call Execution halted
library(Rcpp) # This code can remove the above unknown error, if someone know why the error occur, please tell me.
library(BayesianFROC)
dataList <- dataList.Chakra.Web
fitt <- BayesianFROC::fit_Bayesian_FROC(
# data of multiple reader and multiple case (modalities)
dataList = dataList,
# iteration of MCMC
ite = 1111 # Should be ite = 33333
)
Now, we obtain the fitted model object named fit
which is an S4 object of class stanfitExtended
inherited from stanfit
of the rstan package..
To apply the functions of other package such as rstan or ggmcmc, …, etc in which there are functions for object of class stanfit
, e.g., rstan::stan_trace()
, rstan::stan_dens()
,rstan::check_hmc_diagnostics()
,…etc, we have to change the class of the fitted model object by the following manner:
Then the above object fit.stan
is an object of the class stanfit
and thus we can apply the function of rstan package, e.g. in the following manner; rstan::stan_dens(fit.stan)
.
stanfit
stanfit
# Change the class from stanfitExtended to stanfit
#fit.stan <- methods::as(fit,"stanfit")
# Plot about MCMC samples of paremeter name "A", reperesenting AUC
# ggmcmc::ggs(fit.stan) %>% ggmcmc::ggs_traceplot(family = "A")
A
stored in an object of class stanfit
The following plot indicates that maximal posterior estimator (MAP) is very unstable in each chain in this iteration. By drawing more samples, it become stable?
# Change the class from stanfitExtended to stanfit
#fit.stan <- methods::as(fit,"stanfit"
# ggmcmc::ggs(fit.stan) %>% ggmcmc::ggs_density(family = "A")
stanfit
# Change the class from stanfitExtended to stanfit
# fit.stan <- methods::as(fit,"stanfit")
# ggmcmc::ggs(fit.stan) %>% ggmcmc::ggs_autocorrelation(family = "A")
For fitted model object fit.stan
of class stanfit
, there is a GUI viewer
# Change the class from stanfitExtended to stanfit
fit.stan <- methods::as(fit,"stanfit")
# shinystan::launch_shinystan(fit.stan)
Evaluates a p value of chi square goodness of fit. In addition, the scatter plot are drawn which shows the replicated datasets from the posterior predictive p value of the data which is used to create a fitted model object fit
.
# Makes a fitted model object, i.e., a stanfit object, in which one can figure out there is a pretty cute p values for each MCMC samples calculated in generatid quatinties block of Stan file/
f <- fit_Bayesian_FROC( ite = 1111, summary = TRUE, cha = 1, dataList = dataList.Chakra.1 );
# Plot datasets for calculations of the posterior prediciteve p value of the chi square goodness of fit
plot_dataset_of_ppp(f)
In previous release, my program for ppp was wrong, so in the current version I fixed.
Talts, S., Betancourt, M., Simpson, D., Vehtari, A., and Gelman, A. (2018). Validating Bayesian Inference Algorithms with Simulation-Based Calibration. arXiv preprint arXiv:1804.06788
The author investigate the relation between the sample size and the error of estimates. Accuracy of estimates are depend on the sample size. Large sample size leads us to small error. However, in practical perspective, the number of images or lesions has limitation. The author thinks it is better to obtain 100 images or lesions. And 100 images or lesions gives us the error 0.01 in AUC.
library(BayesianFROC)
a <-BayesianFROC::error_srsc(NLvector = c(
33L,
50L,
111L,
11111L,
1111111L,
111111111L,
999999999L),
# NIvector,
ratio=2,
replicate.datset =3,# This should be more large, e.g. 100 or 200. Larger is better.
ModifiedPoisson = FALSE,
mean.truth=0.6,
sd.truth=5.3,
z.truth =c(-0.8,0.7,2.38),
ite =222
)
The author is a homeless, so, please employ me,,, send me a mail whose address is in the page :’-D.
The author also diseased from multiple chemical sensitivity caused the NO/ONOO- cycle and the initiating toxicant is the synthetic detergent (i.e., syndet) which makes very many prurigo nodularises in all of my body for more than two years and a half.
My nervous system and the immune system have seriously damaged by the synthetic detergent (i.e., syndet). However the company making the synthetic detergent (i.e., syndet) never