
Compute Joint Bivariate Binary Probabilities from Marginal Rates and Correlation
Source:R/getjointbin.R
getjointbin.RdConverts 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.
Arguments
- pi1
A single numeric value in
(0, 1)giving the marginal response probability for Endpoint 1 (\(\pi_{j1}\)) in group \(j\).- pi2
A single numeric value in
(0, 1)giving the marginal response probability for Endpoint 2 (\(\pi_{j2}\)) in group \(j\).- rho
A single numeric value giving the Pearson correlation (\(\rho_j\)) between Endpoint 1 and Endpoint 2 in group \(j\). Must lie within the feasible range \([\rho_{\min}, \rho_{\max}]\) determined by
pi1andpi2(see Details). Userho = 0for independence.- tol
A single positive numeric value specifying the tolerance used when checking whether
rholies within its feasible range and whether the resulting probabilities are non-negative. Default is1e-10.
Value
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.
Details
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).
Examples
# Example 1: Independent endpoints (rho = 0)
getjointbin(pi1 = 0.3, pi2 = 0.4, rho = 0.0)
#> p00 p01 p10 p11
#> 0.42 0.28 0.18 0.12
# Example 2: Positive correlation
getjointbin(pi1 = 0.3, pi2 = 0.4, rho = 0.3)
#> p00 p01 p10 p11
#> 0.4873498 0.2126502 0.1126502 0.1873498
# Example 3: Negative correlation
getjointbin(pi1 = 0.3, pi2 = 0.4, rho = -0.2)
#> p00 p01 p10 p11
#> 0.37510011 0.32489989 0.22489989 0.07510011
# Example 4: Verify cell probabilities sum to 1
p <- getjointbin(pi1 = 0.25, pi2 = 0.35, rho = 0.1)
sum(p) # Should be 1
#> [1] 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
#> p10
#> 0.25
p["p01"] + p["p11"] # Should equal pi2 = 0.35
#> p01
#> 0.35