| getjointbin | R Documentation |
Converts the parameterisation (\pi_{j1}, \pi_{j2}, \rho_j) into the
four-cell joint probability vector
(p_{j,00}, p_{j,01}, p_{j,10}, p_{j,11}) for a bivariate binary
outcome in group j \in \{t, c\}. The conversion uses the standard
moment-matching identity for the Pearson correlation of two Bernoulli
variables, and checks that the requested correlation is feasible for the
supplied marginal rates.
getjointbin(pi1, pi2, rho, tol = 1e-10)
pi1 |
A single numeric value in |
pi2 |
A single numeric value in |
rho |
A single numeric value giving the Pearson correlation
( |
tol |
A single positive numeric value specifying the tolerance used
when checking whether |
For a bivariate binary outcome (Y_{i1}, Y_{i2}) of patient
i (i = 1, \ldots, n_j) in group j with marginal success
probabilities \pi_{j1} = \Pr(Y_{i1} = 1) and
\pi_{j2} = \Pr(Y_{i2} = 1), the Pearson correlation is
\rho_j = \frac{p_{j,11} - \pi_{j1} \pi_{j2}}
{\sqrt{\pi_{j1}(1 - \pi_{j1})\, \pi_{j2}(1 - \pi_{j2})}}.
Solving for p_{j,11} gives
p_{j,11} = \rho_j \sqrt{\pi_{j1}(1-\pi_{j1})\,\pi_{j2}(1-\pi_{j2})}
+ \pi_{j1} \pi_{j2},
from which the remaining probabilities follow:
p_{j,10} = \pi_{j1} - p_{j,11}, \quad
p_{j,01} = \pi_{j2} - p_{j,11}, \quad
p_{j,00} = 1 - p_{j,10} - p_{j,01} - p_{j,11}.
For all four cell probabilities to lie in [0, 1], the correlation
must satisfy
\rho_{\min} =
\frac{\max(0,\; \pi_{j1} + \pi_{j2} - 1) - \pi_{j1}\pi_{j2}}
{\sqrt{\pi_{j1}(1-\pi_{j1})\,\pi_{j2}(1-\pi_{j2})}}
\;\le\; \rho_j \;\le\;
\frac{\min(\pi_{j1}, \pi_{j2}) - \pi_{j1}\pi_{j2}}
{\sqrt{\pi_{j1}(1-\pi_{j1})\,\pi_{j2}(1-\pi_{j2})}}
= \rho_{\max}.
The function raises an error if rho falls outside this range
(subject to tol).
A named numeric vector of length 4 with elements
p00, p01, p10, p11, where
p_lm = Pr(Endpoint 1 = l, Endpoint 2 = m) for
l, m \in \{0, 1\}.
All elements are non-negative and sum to 1.
# Example 1: Independent endpoints (rho = 0)
getjointbin(pi1 = 0.3, pi2 = 0.4, rho = 0.0)
# Example 2: Positive correlation
getjointbin(pi1 = 0.3, pi2 = 0.4, rho = 0.3)
# Example 3: Negative correlation
getjointbin(pi1 = 0.3, pi2 = 0.4, rho = -0.2)
# Example 4: Verify cell probabilities sum to 1
p <- getjointbin(pi1 = 0.25, pi2 = 0.35, rho = 0.1)
sum(p) # Should be 1
# Example 5: Verify marginal recovery
p <- getjointbin(pi1 = 0.25, pi2 = 0.35, rho = 0.1)
p["p10"] + p["p11"] # Should equal pi1 = 0.25
p["p01"] + p["p11"] # Should equal pi2 = 0.35
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.