getjointbin: Compute Joint Bivariate Binary Probabilities from Marginal...

View source: R/getjointbin.R

getjointbinR Documentation

Compute Joint Bivariate Binary Probabilities from Marginal Rates and Correlation

Description

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.

Usage

getjointbin(pi1, pi2, rho, tol = 1e-10)

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 pi1 and pi2 (see Details). Use rho = 0 for independence.

tol

A single positive numeric value specifying the tolerance used when checking whether rho lies within its feasible range and whether the resulting probabilities are non-negative. Default is 1e-10.

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

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.

Examples

# 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


BayesianQDM documentation built on April 22, 2026, 1:09 a.m.