# chi_square_at_replicated_data_and_MCMC_samples_MRMC: chi square at replicated data drawn (only one time) from... In BayesianFROC: FROC Analysis by Bayesian Approaches

## Description

To pass the return value to the calculator of the posterior predictive p value.

## Usage

 1 2 3 4 5 6 chi_square_at_replicated_data_and_MCMC_samples_MRMC( StanS4class, summary = TRUE, seed = NA, serial.number = NA ) 

## 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(), ppp() and ... 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. seed This is used only in programming phase. If seed is passed, then, in procedure indicator the seed is printed. This parameter is only for package development. serial.number A positive integer or Character. This is for programming perspective. The author use this to print the serial numbre of validation. This will be used in the validation function.

## Details

For a given dataset D_0, let us denote by π(|D_0) a posterior distribution of the given data D_0.

Then, we draw poterior samples.

θ_1 \sim π(.| D_0),

θ_2 \sim π(.| D_0),

θ_3 \sim π(.| D_0),

....,

θ_n \sim π(.| D_0).

We let L(|θ) be a likelihood function or probability law of data, which is also denoted by L(y|θ) for a given data y. But, the specification of data y is somehow conversome, thus, to denote the function sending each y into L(y|θ), we use the notation L(|θ).

Now, we synthesize data-samples (y_i;i=1,2,...,n) in only one time drawing from the collection of likelihoods L(|θ_1),L(|θ_2),...,L(|θ_n).

y_1 \sim L(.| θ_1),

y_2 \sim L(.| θ_2),

y_3 \sim L(.| θ_3),

....,

y_n \sim L(.| θ_n).

Altogether, using these pair of samples (y_i, θ_i), i= 1,2,...,n, we calculate the chi squares as the return value of this function. That is,

χ(y_1|θ_1),

χ(y_2|θ_2),

χ(y_3|θ_3),

....,

χ(y_n|θ_n).

This is contained as a vector in the return value,

so the return value is a vector whose length is the number of MCMC iterations except the burn-in period.

Note that in MRMC cases,

χ(y|θ).

is defined as follows.

χ^2(y|θ) := ∑_{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 y 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.

Application of this return value to calculate the so-called Posterior Predictive P value.

As will be demonstrated in the other function, chaning seed, we can obtain

y_{1,1},y_{1,2},y_{1,3},...,y_{1,j},....,y_{1,J} \sim L ( . |θ_1),

y_{2,1},y_{2,2},y_{2,3},...,y_{2,j},....,y_{2,J} \sim L ( . |θ_2),

y_{3,1},y_{3,2},y_{3,3},...,y_{3,j},....,y_{3,J} \sim L ( . |θ_3),

...,

y_{i,1},y_{i,2},y_{i,3},...,y_{i,j},....,y_{I,J} \sim L ( . |θ_i),

...,

y_{I,1},y_{I,2},y_{I,3},...,y_{I,j},....,y_{I,J} \sim L ( . |θ_I).

where L ( . |θ_i) is a likelihood function for a model parameter θ_i. And thus, we calculate the chi square statistics.

χ(y_{1,1}|θ_1), χ(y_{1,2}|θ_1), χ(y_{1,3}|θ_1),..., χ(y_{1,j}|θ_1),...., χ(y_{1,J}|θ_1),

χ(y_{2,1}|θ_2), χ(y_{2,2}|θ_2), χ(y_{2,3}|θ_2),..., χ(y_{2,j}|θ_2),...., χ(y_{2,J}|θ_2),

χ(y_{3,1}|θ_3), χ(y_{3,2}|θ_3), χ(y_{3,3}|θ_3),..., χ(y_{3,j}|θ_3),...., χ(y_{3,J}|θ_3),

...,

χ(y_{i,1}|θ_i), χ(y_{i,2}|θ_i), χ(y_{i,3}|θ_i),..., χ(y_{i,j}|θ_i),...., χ(y_{I,J}|θ_i),

...,

χ(y_{I,1}|θ_I), χ(y_{I,2}|θ_I), χ(y_{I,3}|θ_I),..., χ(y_{I,j}|θ_I),...., χ(y_{I,J}|θ_I).

whih are used when we calculate the so-called Posterior Predictive P value to test the null hypothesis that our model is fitted a data well.

Revised 2019 Sept. 8

Revised 2019 Dec. 2

Revised 2020 March

Revised 2020 Jul

## Value

A list.

From any given posterior MCMC samples θ_1,θ_2,...,θ_i,....,θ_n (provided by stanfitExtended object), it calculates a return value as a vector of the form χ(y_i|θ_i),i=1,2,...., where each dataset y_i is drawn from the corresponding likelihood likelihood(.|θ_i),i=1,2,..., namely,

y_i \sim likelihood(.| θ_i).

The return value also retains these y_i, i=1,2,...

Revised 2019 Dec. 2

## Examples

  1 2 3 4 5 6 7 8 9 10 11 12 ## Not run: fit <- fit_Bayesian_FROC( ite = 1111, dataList = ddd ) a <- chi_square_at_replicated_data_and_MCMC_samples_MRMC(fit) b<-a\$List_of_dataList lapply(b, plot_FPF_and_TPF_from_a_dataset) ## End(Not run) 

BayesianFROC documentation built on Jan. 13, 2021, 5:22 a.m.