# Chi_square_goodness_of_fit_in_case_of_MRMC_Posterior_Mean: Chi square statistic (goodness of fit) in the case of MRMC at... In BayesianFROC: FROC Analysis by Bayesian Approaches

## Description

Revised 2019 Oct 16. Revised 2019 Nov 1. Revised 2019 Nov 27. Revised 2019 Dec 1.

In the following, we explain what this function calculates.

Let χ^2(y|θ) be a chi square goodness of fit statistic which is defined by

( Observed data - Expectation )^2/Exectation.

In MRMC cases, it is defined as follows.

χ^2(D|θ) := ∑_{r=1}^R ∑_{m=1}^M ∑_{c=1}^C \biggr( \frac{[ H_{c,m,r}-N_L\times p_{c,m,r}(θ)]^2}{N_L\times p_{c,m,r}(θ)}+\frac{[F_{c,m,r}-(λ _{c} -λ _{c+1} )\times N_{L}]^2}{(λ_{c}(θ) -λ_{c+1}(θ) )\times N_{L} }\biggr).

where a dataset D consists of the pairs of the number of False Positives and the number of True Positives (F_{c,m,r}, H_{c,m,r}) together with the number of lesions N_L and the number of images N_I and θ denotes the model parameter.

Note that we can rewrite the chi square as follows.

χ^2(D|θ) := ∑_{r=1}^R ∑_{m=1}^M ∑_{c=1}^C \biggr( \frac{[ H_{c,m,r}- E_{θ}[H_{c,m,r}] ]^2}{E_{θ}[H_{c,m,r}]}+\frac{[F_{c,m,r}- E_{θ}[F_{c,m,r}] ]^2}{ E_{θ}[F_{c,m,r}] }\biggr).

So, the chi square has two terms.

1) The first term is the difference of hit and its expectation.

2) The second term is the differences of observed false alarms and its expectatioins.

In this function, we calculate each terms, separately. So, return values retain these two terms, separately.

In this function, we calculate the following (I) and (II):

(I) A vector ——————-

Let us denote a collection of posterior MCMC samples for a given dataset D by

θ_1 , θ_2 , \cdots , θ_i, \cdots , θ_N,

namely, each θ_i is synthesized from posterior π(θ|D), θ_i \sim π(θ|D).

Substituing these MCMC samples into the above definition of the chi square, we obtain the following vector as a return value of this function.

χ^2(D|θ_1),

χ^2(D|θ_2),

χ^2(D|θ_3),

:

:

χ^2(D|θ_N).

(II) A mean of the above vector, namely, the posterior mean of the chi square over all MCMC samples ————-

Using the set of chi squares (χ^2(D|θ_i);i=1,...,N) calculated for each posterior MCMC samples θ_i \sim π(θ|D). , the function also calculates the posterior mean of the chi square statistic, namely,

\int χ^2(D|θ)π(θ|D) dθ,

by approximating it as

\frac{1}{N} ∑ _{i=1} ^N χ^2(D|θ_i),

where π(θ|D) denotes the posterior probability density under the given data D.

Do not confuse it with the following

χ^2(D|θ^*).

where θ^* denotes the posterior estimates, i.e., θ^* := \int θ π(θ|D) dθ.

## Usage

 1 2 3 4 5 Chi_square_goodness_of_fit_in_case_of_MRMC_Posterior_Mean( StanS4class, summary = TRUE, dl_is_an_array_of_C_only_and_not_C_M_Q = TRUE ) 

## Arguments

 StanS4class An S4 object of class  stanfitExtended which is an inherited class from the S4 class stanfit. This R object is a fitted model object as a return value of the function fit_Bayesian_FROC(). To be passed to DrawCurves() ... etc summary Logical: TRUE of FALSE. Whether to print the verbose summary. If TRUE then verbose summary is printed in the R console. If FALSE, the output is minimal. I regret, this variable name should be verbose. dl_is_an_array_of_C_only_and_not_C_M_Q A Boolean, if TRUE, then false rate lambda simply denoted by l in R script ( λ ) is an vector l[C]. If false, then the false alarm rate is an array l[C,M,Q].

## Details

This function is implemented by vectorizations and further techinics. When the author review this, I find my past work is great,... I forget that I made this. But this function is great.

Revised 2019 Nov 1

## Value

A list, calculated by each modality reader and cofidence level, and MCMC samples. A one the component of list contains { χ^2(Data|θ_i) ; i= 1,2,3,...n}, where n is the number of MCMC iterations.

Each component of list isan array whose index indicats [MCMC, Confidence, Modality, Reader] .

Each component of list is an array whose index indicats [MCMC, C, M, Q].

To be passed to the calculation of Posterior predictive p value, I need the sum of return value, that is, sum of C,M,Q and resulting quantities construct a vetor whose length is a same as the number of MCMC iterations. I love you. I need you. So, to calculate such quantites, the author .... will make a new function.

Also, it retains the posterior mean of chi square statistic for an assumed occurrence of the data D:

χ^2(Data) = \int χ^2(Data|θ) π(θ|D)d θ

## Examples

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 ## Not run: #======================================================================================== # 1) Create a fitted model object for data named dd #======================================================================================== fit <- fit_Bayesian_FROC( ite = 1111, # Number of MCMC iterations cha = 1, dataList = BayesianFROC::dd # This is a MRMC dataset. ) #======================================================================================== # 2) Calculate a chi square and meta data #======================================================================================== a <- Chi_square_goodness_of_fit_in_case_of_MRMC_Posterior_Mean(fit) #======================================================================================== # 3) Extract a chi square #======================================================================================== chi.square <- a\$chi.square #======================================================================================== # A case of single reader is special in the programming perspective # 2020 Feb 24 #======================================================================================== f <- fit_Bayesian_FROC( ite = 1111, cha = 1, summary = TRUE, dataList = dddd, see = 123) Chi_square_goodness_of_fit_in_case_of_MRMC_Posterior_Mean(f) # Revised 2019 August 19 # 2019 Nov 1 ## End(Not run)# dontrun 

BayesianFROC documentation built on Jan. 23, 2022, 9:06 a.m.