Skip to content

Commit

Permalink
45_h_getbetaMixpost_simplify (#47)
Browse files Browse the repository at this point in the history
* new formula

* h_getBetaMixPost reasoning

* clean

* clean

* added my name+email

* clean

* notations cleaned

* removed unused term in wordlist

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* clean

* clean

* clean

* clean

* checking formulars first

* clean

* clean

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* clean

* Update vignettes/introduction.Rmd

Co-authored-by: Daniel Sabanes Bove <[email protected]>

* Auto stash before merge of "45_h_getbetaMixPost_simplify" and "origin/45_h_getbetaMixPost_simplify"

* clean

* clean

---------

Co-authored-by: Daniel Sabanes Bove <[email protected]>
  • Loading branch information
audreyyeoCH and danielinteractive authored Jan 11, 2024
1 parent 5995c82 commit 8cd8a0d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 12 deletions.
5 changes: 1 addition & 4 deletions R/dbetabinom.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ h_getBetamixPost <- function(x, n, par, weights) {
postPar <- par
postPar[, 1] <- postPar[, 1] + x
postPar[, 2] <- postPar[, 2] + n - x
postParProb <- postPar[, 1] / (postPar[, 1] + postPar[, 2])
# We compute updated mixture probabilities.
tmp <- exp(
stats::dbinom(x, size = n, prob = postParProb, log = TRUE) +
stats::dbeta(postParProb, par[, 1], par[, 2], log = TRUE) -
stats::dbeta(postParProb, postPar[, 1], postPar[, 2], log = TRUE)
lbeta(a = postPar[, 1], b = postPar[, 2]) - lbeta(a = par[, 1], b = par[, 2])
)
# We compute the updated weights of the posterior
postWeights <- weights * tmp / sum(weights * tmp)
Expand Down
19 changes: 19 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ analysed
apriori
bA
ba
BayesBetaBinom
BayesRobust
bB
bbeta
Expand All @@ -12,13 +13,15 @@ bD
bE
beps
betadiff
BetaPrior
bF
bG
bgttheta
bH
bh
bI
Binom
binom
Biometrics
bL
bLambda
Expand Down Expand Up @@ -50,6 +53,8 @@ bX
bY
bZ
bz
calc
calcweights
calulation
cdf
comparator
Expand Down Expand Up @@ -89,8 +94,10 @@ hyoithesis
hyperprior
increasement
inefficacious
infty
Integrand
integrations
kernal
LciU
ldots
leq
Expand All @@ -108,6 +115,8 @@ nnE
nnF
nnr
normalised
normalising
normalizingconstant
nS
oc
ocPostProb
Expand Down Expand Up @@ -147,6 +156,7 @@ pU
py
pyz
RCT
rearrangingWeightedBayes
refering
renewcommand
responder
Expand All @@ -156,6 +166,9 @@ SampleSizeActive
SampleSizeControl
seperate
ShinyPhase
simplifiedWeightedBayes
simplifiedWeightedBayesone
simplifiedWeightedBayestwo
specialised
sumbetadiff
summerize
Expand All @@ -173,10 +186,16 @@ tT
TtR
tU
UciL
unweightedBetaPrior
updatedalpha
updatedbeta
updatedsalpha
USUBJID
VAD
vanillaBayes
vanillaPP
WeightedBayes
weightedBetaPrior
xL
xS
xU
Expand Down
77 changes: 69 additions & 8 deletions vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: "`phase1b`: Tools for Decision Making in Phase 1b Studies"
package: phase1b
bibliography: '`r system.file("REFERENCES.bib", package = "phase1b")`'
author:
- name: Audrey Yeo
email: [email protected]
- name: Tony Pourmohamad
email: [email protected]
- name: Jiawen Zhu
Expand Down Expand Up @@ -242,7 +244,7 @@ Under the Bayesian approach, the parameter $P_E$ is treated as a random unknown
quantity in the model. The prior distribution for $P_E$ can be elicited from
external knowledge or expert opinion, however, the use of a conjugate prior is
employed here. The prior used in `postprob()` is of the following form:
$P_E\sim \sum_{i=1}^kw_i\text{Beta}(a_i,b_i)$, so a mixture of Beta
$P_E\sim \sum_i=1}^kw_i\text{Beta}(a_i,b_i)$, so a mixture of Beta
distributions, but for simplicity, the default prior in `postprob()` is
set to be the single conjugate Beta distribution, $\text{Beta}(\alpha,\beta)$.
Here we make the assumption that a (mixture) Beta prior is a reasonable choice
Expand All @@ -266,17 +268,76 @@ following Beta distribution
P_E\given x\sim\text{Beta}(a+x,b+n-x)
\end{equation}

Of course we could have carried out this calculation using the more general prior,
$P_E\sim \sum_{i=1}^kw_i\text{Beta}(a_i,b_i)$, however, for sake of illustration
(and to avoid tedious bookkeeping) we chose to use the simpler non-mixture of
Beta distributions for ease of calculation.
Here we illustrate a posterior of a simple prior as an illustration
$P_E\sim \sum_{j=1}^kw_i\text{Beta}(a_j,b_j)$. In section \@ref(updateposterior), we illustrate a mixture Beta distribution and how weights and parameters are updated with data.

All further probabilistic calculations follow naturally under the Bayesian approach
once the posterior distribution has been identified. For example, as seen in
the function `postprob()`, one could calculate the posterior probability that the
rate $P_E$ is greater than (or less than) some threshold $p$, i.e., $\Pr(P_E>p\given x)$,
by simply calculating the area under the corresponding Beta distribution.

## Updating Posterior Distribution parameters and weights {#updateposterior}

In order to incorporate prior information and evaluate posterior probabilities, updated weights and parameters are required especially where mixed Beta-Binomial distribution is involved. To demonstrate the calculation of how parameters and weights are updated, we
illustrate the reasoning as follows.

We present the Binomial likelihood and the mixture of Beta distributions prior to begin:

\begin{align}
f(x|\pi) &= \binom{n}{k} \pi^x (1-\pi)^{n-x} \\
f(\pi) &= \sum_{j = 1}^{k} w_j \frac {1} {B(\alpha_j, \beta_j)} \pi^{\alpha_j-1} (1-\pi)^{\beta_j-1}
(\#eq:binomial)
\end{align}
<!-- (\#eq:weightedBetaPrior) -->

Where the sum $w_j$ has to equal 1: $\sum_{j = 1}^{k} w_j = 1$.

Each component $j$ has the Beta density:
\begin{align}
f(\pi | \alpha_j, \beta_j) = \frac {1} {B(\alpha_j, \beta_j)} \pi^{\alpha_j-1} (1-\pi)^{\beta_j-1}
(\#eq:unweightedBetaPrior)
\end{align}

Here $B(\alpha, \beta)$ is the beta function evaluated with parameters $\alpha$ and $\beta$.
Then, the product of likelihood and prior $f(\pi | x) \propto f(\pi) f(x | \pi)$ gives the kernel for the posterior where we exclude the normalising constants $\frac{1}{f(x)}$ as well as any other multiplicative constants not depending on $\pi$:

\begin{align}
f(\pi | x) &\propto \pi^x (1-\pi)^{n-x}\sum_{j = 1}^{k} \ w_j \frac {1}{B(\alpha_j, \beta_j)} \pi^{\alpha_j-1}(1-\pi)^{\beta_j-1}
\\
&\propto \sum_{j = 1}^{k} \frac {w_j}{B(\alpha_j, \beta_j)} \pi^{\alpha_j + x -1} (1-\pi)^{\beta_j + n - x -1} \frac{B(\alpha_j + x, \beta_j + n - x)}{B(\alpha_j + x, \beta_j + n - x)}
(\#eq:rearrangingWeightedBayes)
\end{align}

From \@ref(eq:rearrangingWeightedBayes), we know that the updated Beta prior $f(\pi | \alpha + x_j, \beta_j + n -x) = \frac {1} {Beta(\alpha_j + x, \beta_j + n - x)}\pi^{\alpha_j + x -1} (1-\pi)^{\beta_j + n - x -1}$ is embedded and can be simplified to the following:

\begin{align}
f(\pi | x) \propto \sum_{j = 1}^{k} {w_j} \frac {B(\alpha_j + x, \beta_j +n -x )}{B(\alpha_j, \beta_j)} f(\pi | \alpha_j + x, \beta_j + n - x)
(\#eq:simplifiedWeightedBayesone)
\end{align}
\
We can identify the shape of the density as that of a mixture distribution with weights being proportional to $w_j$ :
\frac {B(\alpha_j + x, \beta_j +n -x )}{B(\alpha_j, \beta_j)}

\begin{align}
f(\pi | x) \propto \sum_{j = 1}^{k} w_j \frac {B(\alpha_j + x, \beta_j + n -x )}{B(\alpha_j, \beta_j)}
(\#eq:simplifiedWeightedBayestwo)
\end{align}
\
The normalizing constant is thus:

\begin{align}
\frac {1}{\sum_{j=1}^{k}w_j\frac{B(\alpha_j + x, \beta_j + n - x)}{B(\alpha_j, \beta_j)}}
(\#eq:normalizingconstant)
\end{align}

such that the updated weights are given as :
\
\begin{align}
\tilde{w}_j = w_j \frac {\frac {B(\alpha_j + x, \beta_j +n -x )}{B(\alpha_j, \beta_j)}} {\sum_{j} w_j \frac {Beta(\alpha_j + x, \beta_j +n -x )}{B(\alpha_j, \beta_j)}}
(\#eq:calcweights)
\end{align}

## Difference in beta random variables {#betadiff}

One may wish to know the distribution of the difference in response rates between groups.
Expand Down Expand Up @@ -1050,7 +1111,7 @@ while the advanced predictive probability design should be used.

An advantage of such a design is that it allows an option of further evaluation
on additional clinical endpoints or PD markers when the decision falls into the
"gray zone". Moreover, a seperate delta can be specified for the futility decision
"gray zone". Moreover, a separate delta can be specified for the futility decision
to represent a "pool clinical improvement", which makes it a more flexible
decision rule.

Expand Down Expand Up @@ -1091,7 +1152,7 @@ calculate the *PPs*, if there are 18 PET-CR at the first interim analysis:

```{r ex3:predictive, echo=TRUE}
# PP(event A)
predprobDist(
result1 <- predprobDist(
x = 18, n = 25, Nmax = 80,
delta = 0.15,
thetaT = 0.6,
Expand All @@ -1101,7 +1162,7 @@ predprobDist(
## PP(event B)
1 - predprobDist(
result2 <- 1 - predprobDist(
x = 18, n = 25, Nmax = 80,
delta = 0.05,
thetaT = 1 - 0.6,
Expand Down

0 comments on commit 8cd8a0d

Please sign in to comment.