Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

BayesianFROC (version 0.3.0)

ppp_srsc: Calculates PPP for Models of a single reader and a single modality (Calculation is correct! :'-D)

Description

Calculates Posterior Predictive P value for chi square (goodness of fit)

Usage

ppp_srsc(
  StanS4class,
  Colour = TRUE,
  dark_theme = TRUE,
  plot = TRUE,
  summary = TRUE,
  replicate.number.from.model.for.each.MCMC.sample = 100
)

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().

It can be passed to DrawCurves(), ppp() and ... etc

Colour

Logical: TRUE of FALSE. whether Colour of curves is dark theme or not.

dark_theme

TRUE or FALSE

plot

Logical, whether replicated data are drawn, in the following notation, replicated data are denoted by y1,y2,...,yN.

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.

replicate.number.from.model.for.each.MCMC.sample

A positive integer, representing J in the following notation. Now, I think all I needed is love! ttu ttu tututu Love is all I need.

Suppose that θ1,θ2,θ3,...,θn is drawn from posterior π(θ|D) of given data D.

Let y1,y2,...,yn be samples drawn from

y1likelihood(.|θ1), y2likelihood(.|θ2), y3likelihood(.|θ3), ..., ynlikelihood(.|θN),

Then the list of return values retains the following:

chisq_at_observed_data

χ(D|θ1),χ(D|θ2),χ(D|θ3),...,χ(D|θn),

chisq_not_at_observed_data

χ(y1|θ1),χ(y2|θ2),χ(y3|θ3),...,χ(yn|θn),

Logical

The i-th component is a logical vector indicating whether χ(y2|θ2)>χ(D|θ2) is satisfied or not. Oppai ga Ippai. If TRUE, then the inequality holds.

p.value

From the component Logical, we calculate the so-called Posterior Predictive P value. Note that the author hate this notion!! I hate it!! Akkan Beeeee!!!

Value

A list, including p value and materials to calculate it.

Details

In addition, this function plots replicated datasets from model at each MCMC sample generated by HMC. Using the Hamiltonian Monte Carlo Sampling: HMC. we can draw the MCMC samples of size n, say θ1,θ2,θ3,...,θn, namely, θ1π(.|D), θ2π(.|D), θ3π(.|D), ..., θnπ(.|D). where π(θ|D) is the posterior for given data D.

Then, the function plots the following datasets y11,y21,...,yIJ.

χ(y1,1|θ1),χ(y1,2|θ1),χ(y1,3|θ1),...,χ(y1,j|θ1),....,χ(y1,J|θ1), χ(y2,1|θ2),χ(y2,2|θ2),χ(y2,3|θ2),...,χ(y2,j|θ2),....,χ(y2,J|θ2), χ(y3,1|θ3),χ(y3,2|θ3),χ(y3,3|θ3),...,χ(y3,j|θ3),....,χ(y3,J|θ3), ..., χ(yi,1|θi),χ(yi,2|θi),χ(yi,3|θi),...,χ(yi,j|θi),....,χ(yI,J|θi), ..., χ(yI,1|θI),χ(yI,2|θI),χ(yI,3|θI),...,χ(yI,j|θI),....,χ(yI,J|θI).

where L(.|θi) is a likelihood at parameter θi.

Let χ(y|θ) be a chi square goodness of fit statistics of our hierarchical Bayesian Model

χ(y|θ):=r=1Rm=1Mc=1C((Hc,m,rNL×pc,m,r)2NL×pc,m,r+(Fc,m,r(λcλc+1)×NL)2(λcλc+1)×NL).

and a chi square goodness of fit statistics of our non-hierarchical Bayesian Model

χ(y|θ):=c=1C((HcNL×pc)2NL×pc+(Fc(λcλc+1))×NL]2(λcλc+1)×NL).

where a dataset y denotes (Fc,m,r,Hc,m,r) in MRMC case and (Fc,Hc) in a single reader and a single modality case, and model parameter θ.

Then we can calculate the posterior predictive p value for a given dataset y0.

I(χ(y|θ)>χ(y0|θ))f(y|θ)π(θ|y0)dθdy iI(χ(y|θi)>χ(y0|θi))f(y|θi)dy j=1Ji=1II(χ(yi,j|θi)>χ(y0|θi))

When we plot these synthesized data-sets yi,j, we use the jitter() which adds a small amount of noise to avoid overlapping points. For example, jitter(c(1,1,1,1)) returns values: 1.0161940 1.0175678 0.9862400 0.9986126, which is changed from 1,1,1,1 to be not exactly 1 by adding tiny errors to avoid overlapping. I love you. 2019 August 19 Nowadays, I cannot remove my self from some notion, such as honesty, or pain, or,.. maybe these thing is no longer with myself. This programm is made to fix previous release calculation. Now, this programm calculates correct p value.

So... I calculate the ppp for MCMC and Graphical User Interface based on Shiny for MRMC, which should be variable such as number of readers, modalities, to generate such ID vectors automatically. Ha,... tired! Boaring, I want to die...t, diet!! Tinko, tinko unko unko. Manko manko. ha.

Leberiya, he will be die, ha... he cannot overcome, very old, old guy. I will get back to meet him. Or I cannot meet him? Liberiya,...very wisdom guy, Ary you already die? I will get back with presents for you. Ball, I have to throgh ball, and he will catch it.

The reason why the author made the plot of data drawn from Posterior Predictive likelihoods with each MCMC parameters is to understand our programm is correct, that is, each drawing is very mixed. Ha,.... when wright this,... I always think who read it. I love you, Ruikobach. Ruikobach is tiny and tiny, but,... cute. Ruikosan...Ruiko... But he has time only several years. He will die, he lives sufficiently so long, ha.

Using this function, user would get reliable posterior predictive p values, Cheers! Pretty Crowd!

We note that the calculation of posterior perdictive p value (PPP) relies on the law of large number. Thus, in order to obtain the relicable PPP, we need to enough large MCMC samples to approximate the double integral of PPP. For example, the MCMC samples is small, then R hat is far from 1 but, the low MCMC samples leads us to incorrect p value which sometimes said that the model is correct even if the R hat criteria reject the MCMC results.

Examples

Run this code
# NOT RUN {

# }
# NOT RUN {
#========================================================================================
#            1) Create a fitted model object with data named  "d"
#========================================================================================



fit <- fit_Bayesian_FROC( dataList = d,
                              ite  = 222 # to restrict running time, but it is too small
                           )



#========================================================================================
#            2) Calculate p value and meta data
#========================================================================================



                              ppp <- ppp_srsc(fit)



#========================================================================================
#            3) Extract a p value
#========================================================================================




                              ppp$p.value


# Revised 2019 August 19
# Revised 2019 Nov 27

# }
# NOT RUN {


# }

Run the code above in your browser using DataLab