| Title: | Bayesian Mendelian Randomization for Causal Cell-Cell Communication |
|---|---|
| Description: | Implements MR-CCC, a Bayesian Mendelian randomization framework for inferring causal ligand-receptor signalling between cell types from population-scale single-cell expression and genotype data. For each ligand-receptor-pathway triplet, cis-eQTL genotypes instrument ligand expression in the sender cell type and receptor expression in the receiver cell type, and a working model with a ligand-by-receptor interaction is fitted to downstream pathway activity by a blocked Gibbs sampler. A spike-and-slab prior on the causal block yields a posterior inclusion probability that serves as the communication score, and the retained draws support credible intervals, sign probabilities, the receptor level at which the ligand effect reverses sign, and Bayesian false discovery rate control across many triplets. |
| Authors: | Bitan Sarkar [aut, cre] (ORCID: <https://orcid.org/0009-0000-5178-5934>), Yang Ni [aut] (ORCID: <https://orcid.org/0000-0003-0636-2363>) |
| Maintainer: | Bitan Sarkar <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.4 |
| Built: | 2026-10-08 20:34:07 UTC |
| Source: | https://github.com/BiocStaging/MRCCC |
For a vector of posterior inclusion probabilities from many
ligand-receptor-pathway triplets, computes the Bayesian false discovery
rate (bFDR) of every nested set obtained by declaring the top-
triplets by PIP, for .
bayes_fdr(pip)bayes_fdr(pip)
pip |
Numeric vector of posterior inclusion probabilities in
|
For a declared set , the posterior expected number of false
discoveries is , so the Bayesian
false discovery rate is
Ranking the triplets by decreasing PIP and accumulating gives, for each
possible cut-off, the bFDR incurred by declaring everything at or above
it. Because the PIPs are posterior probabilities, this controls the
expected proportion of false discoveries without a separate multiplicity
correction. The value returned for triplet is the bFDR of the
smallest nested set that contains ; it is non-decreasing in the
rank of . Ties in PIP are broken by input order.
A numeric vector of the same length as pip, in the order of the
input, giving the bFDR of the nested set that ends at each triplet.
Newton MA, Noueiry A, Sarkar D, Ahlquist P (2004). Detecting differential gene expression with a semiparametric hierarchical mixture method. Biostatistics 5(2):155-176.
bfdr_threshold_set(), mr_ccc()
pip <- c(0.9, 0.8, 0.5) bayes_fdr(pip) # Unsorted input is handled; results are returned in input order. bayes_fdr(c(0.5, 0.9, 0.8))pip <- c(0.9, 0.8, 0.5) bayes_fdr(pip) # Unsorted input is handled; results are returned in input order. bayes_fdr(c(0.5, 0.9, 0.8))
Selects the largest nested set of triplets, ranked by decreasing posterior
inclusion probability, whose Bayesian false discovery rate does not exceed
alpha. The rule is monotone: if the top- set qualifies, so does
every smaller top- set. If no set qualifies, nothing is selected.
bfdr_threshold_set(pip, alpha)bfdr_threshold_set(pip, alpha)
pip |
Numeric vector of posterior inclusion probabilities in
|
alpha |
Target Bayesian false discovery rate in |
A logical vector of the same length as pip, in input order,
that is TRUE for the selected triplets.
pip <- c(0.9, 0.8, 0.5, 0.2) bayes_fdr(pip) bfdr_threshold_set(pip, alpha = 0.2) bfdr_threshold_set(pip, alpha = 0.05)pip <- c(0.9, 0.8, 0.5, 0.2) bayes_fdr(pip) bfdr_threshold_set(pip, alpha = 0.2) bfdr_threshold_set(pip, alpha = 0.05)
Computes equal-tailed posterior credible intervals for ,
and from the pooled retained draws of an
MR-CCC fit.
credible_intervals(fit, level = 0.95, standardized = TRUE)credible_intervals(fit, level = 0.95, standardized = TRUE)
fit |
An object of class |
level |
Credible level in |
standardized |
Logical; if |
The intervals are marginal posterior quantiles of each coefficient. Because
the prior on is a spike-and-slab mixture, the
marginal posterior of each of these two coefficients is itself a mixture of
a component concentrated near zero (draws with ) and a
slab component (draws with ). An interval that covers zero
therefore reflects the posterior weight of the spike as much as the
uncertainty within the slab; see sign_probabilities() for a
decomposition.
A data frame with columns parameter (beta_X, beta_XZ,
beta_Z), lower, median and upper.
mr_ccc(), sign_probabilities()
sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) credible_intervals(fit) credible_intervals(fit, level = 0.9, standardized = FALSE)sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) credible_intervals(fit) credible_intervals(fit, level = 0.9, standardized = FALSE)
Fits the Bayesian Mendelian randomization model for causal cell-cell
communication to a single triplet consisting of ligand expression in a
sender cell type, receptor expression in a receiver cell type, and
pathway activity in the receiver cell type, using cis-eQTL genotypes as
instruments. The function validates and centres the inputs, runs one or
more Gibbs chains through mr_ccc_gibbs(), pools the retained draws, and
computes the posterior inclusion probability (PIP) together with its Monte
Carlo standard error and convergence diagnostics.
mr_ccc( X, Z, Y, G, H, V, n_iter = 20000, burn_in = 2000, thin = 1, n_chains = 4, init_scale = 1, pip_threshold = 0.5, hyper = mrccc_hyperparameters(), seed = NULL, verbose = FALSE )mr_ccc( X, Z, Y, G, H, V, n_iter = 20000, burn_in = 2000, thin = 1, n_chains = 4, init_scale = 1, pip_threshold = 0.5, hyper = mrccc_hyperparameters(), seed = NULL, verbose = FALSE )
X |
Ligand expression in the sender cell type: a numeric vector of
length |
Z |
Receptor expression in the receiver cell type, same format as
|
Y |
Pathway activity in the receiver cell type, same format as |
G |
Numeric matrix with |
H |
Numeric matrix with |
V |
Numeric matrix with |
n_iter |
Total number of Gibbs iterations per chain. |
burn_in |
Number of initial iterations discarded per chain. Must be
smaller than |
thin |
Thinning interval: every |
n_chains |
Number of independent chains, pooled for all posterior
summaries. With two or more chains the Gelman-Rubin statistic is reported
and the chains start from dispersed values. Pooling |
init_scale |
Standard deviation of the normal distribution from which
|
pip_threshold |
Threshold in |
hyper |
Prior hyperparameters, as returned by
|
seed |
Optional integer; if supplied, the chains are run under this
seed, which makes the whole multi-chain fit reproducible as a unit, and
the caller's random number state is restored afterwards. The default
|
verbose |
Logical; if |
Model. With and
the genetically predicted ligand and receptor levels, the outcome model is
where is a spike-and-slab inclusion indicator
for the causal block . The indicator is
implemented through the prior variance of that block (a continuous
spike-and-slab: under the prior variance is multiplied by
nu1, by default), so that under the spike the two
coefficients are concentrated tightly at zero rather than fixed at zero;
at this value of nu1 the two formulations are numerically
indistinguishable. The posterior inclusion probability
is the
communication score. The receptor-modulated ligand effect is
, which changes sign at
; see sign_reversal().
Centring. The model requires X, Z and Y, and every column of
G, H and V, to have mean zero: neither first stage carries an
intercept, so uncentred instruments or covariates would force each
first-stage fit through the origin. All six inputs are centred internally.
The standard deviations of the original X, Z and Y are stored in the
scale element so that effects can be reported
on a standardised scale (per standard deviation of and , in
standard deviations of ).
Priors. The first-stage blocks
and the covariate block carry Zellner g-priors on their
observed designs , and . The second-stage blocks are
scaled by the size of their regressors, but with that scale fixed:
where
and are computed once from the least-squares
first stage and held fixed, and is 1 in the slab and nu1
in the spike. Equivalently, the causal coefficients carry independent
normal priors on the scale of the standardised regressors. The scale is
fixed rather than recomputed from the current draws because and
are functions of the first-stage parameters; a prior whose
covariance moved with them would enter their full conditionals, and the
sampler would no longer be a Gibbs sampler for the stated model. The
values used are returned in settings$prior_scale. Unless overridden in
hyper, every scale is set to .
Instrument strength. The first-stage partial F statistic of each
instrument block, after the covariates, is computed by ordinary least
squares and returned in instruments. When either F is below 10 a message
is issued. The threshold is the conventional two-stage least-squares
heuristic and is reported for orientation: the one-sample Bayesian model
fitted here does not require it, but posterior inclusion probabilities are
less decisive under weak instruments and longer chains may be needed.
Chains and pooling. Chain starts with when
is odd and when is even, and, when
n_chains > 1, with drawn from a normal
distribution with mean zero and standard deviation init_scale.
Retained draws are pooled across
chains for all posterior summaries.
Monte Carlo error of the PIP. The PIP is the mean of an autocorrelated
binary chain, so its Monte Carlo standard error (MCSE) is estimated by
non-overlapping batch means within each chain and combined across chains
in quadrature: .
Effective sample sizes add across chains. Batch means are never applied to
the concatenated chains, because a batch straddling the join between two
chains started at different values would inflate the variance estimate.
If , where is
pip_threshold, the
discovery status of the triplet is not resolved at the current chain
length and a warning is issued.
Convergence diagnostics. The Gelman-Rubin statistic is
reported for , , and the joint
log-likelihood. It compares the variance between chains with the variance
within them, so it requires n_chains >= 2 and is NA for a single chain;
it is also only informative when the chains start from dispersed values,
which init_scale > 0 and the alternating start provide.
Values below 1.01 are conventionally taken as consistent with convergence;
a warning is issued when any exceeds 1.01, and a message when
only one chain is run. Because a useful is the reason to run
several chains at all, the default n_chains is 4.
Units. The g-priors are invariant to the scale of the inputs, but the
inverse-gamma priors on the residual variances are not: their defaults
assume that X, Z and Y are on a scale of roughly unit variance.
Inputs on very different scales should be standardised first.
An object of class mrccc_fit: a list with elements
pipPosterior inclusion probability, pooled over chains.
pip_mcseMonte Carlo standard error of pip.
pip_essEffective sample size of the pooled
chain.
estimatesData frame with columns parameter (beta_X,
beta_XZ, beta_Z), raw_mean (posterior mean on the centred input
scale) and std_mean (posterior mean on the standardised scale).
drawsList of pooled numeric vectors beta_X, beta_XZ,
beta_Z, gamma, mu and loglik, the first five on the raw
(centred) scale, each of length n_keep * n_chains. loglik is the
joint log-likelihood of the three equations at each retained draw and
is useful for trace plots.
scaleList with sd_X, sd_Z, sd_Y (standard deviations of
the original inputs), mean_X, mean_Z, mean_Y (the subtracted
means) and Z_range_std (range of the centred receptor expression in
standard-deviation units).
diagnosticsData frame with columns parameter (beta_X,
beta_XZ, gamma, loglik) and rhat.
instrumentsData frame with one row per exposure and columns
exposure (X or Z), n_instruments, F_statistic (first-stage
partial F of the instrument block after the covariates) and weak
(TRUE when F_statistic < 10).
settingsList with n_iter, burn_in, thin, n_chains,
n_keep (retained draws per chain), pip_threshold, hyper, g
(the g-prior scale used) and prior_scale (the fixed second-stage
prior scale d_X, d_XZ, d_Z).
callThe matched call.
Sarkar B, Ni Y (2026). MR-CCC: Bayesian Mendelian Randomization for Causal Cell-Cell Communication. arXiv:2604.23917.
summary.mrccc_fit(), credible_intervals(),
sign_probabilities(), sign_reversal(), plot_effect_curve(),
bayes_fdr(), simulate_mrccc(), mrccc_hyperparameters().
sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) fit fit$pip fit$estimatessim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) fit fit$pip fit$estimates
Runs the blocked Gibbs sampler for a single ligand-receptor-pathway
triplet and returns posterior means together with the retained draws of
the scalar parameters of inferential interest. This is the low-level
engine called by mr_ccc(); most users should call mr_ccc(), which
validates and centres the inputs, runs several chains, and computes
convergence diagnostics.
mr_ccc_gibbs( X, Z, Y, G, H, V, n_iter = 20000L, burn_in = 2000L, thin = 1L, a_sigma = 3, b_sigma = 2, a_rho = 3, b_rho = 1, nu1 = 1e-04, gG = 100, gV = 100, gH = 100, gZ = 100, gBeta = 100, ridge = 1e-08, init_gamma = 1L, init_scale = 0, verbose = FALSE )mr_ccc_gibbs( X, Z, Y, G, H, V, n_iter = 20000L, burn_in = 2000L, thin = 1L, a_sigma = 3, b_sigma = 2, a_rho = 3, b_rho = 1, nu1 = 1e-04, gG = 100, gV = 100, gH = 100, gZ = 100, gBeta = 100, ridge = 1e-08, init_gamma = 1L, init_scale = 0, verbose = FALSE )
X |
Numeric matrix of dimension n x 1: centred ligand expression in the sender cell type. |
Z |
Numeric matrix of dimension n x 1: centred receptor expression in the receiver cell type. |
Y |
Numeric matrix of dimension n x 1: centred pathway activity in the receiver cell type. |
G |
Numeric matrix of dimension n x pG: column-centred sender cis-eQTL genotypes (instruments for X). |
H |
Numeric matrix of dimension n x pH: column-centred receiver cis-eQTL genotypes (instruments for Z). |
V |
Numeric matrix of dimension n x pV, pV >= 1: column-centred
shared covariates. The first stages have no intercept, so all three
design matrices must be centred, as |
n_iter |
Total number of Gibbs iterations. |
burn_in |
Number of initial iterations discarded. |
thin |
Thinning interval; every |
a_sigma, b_sigma
|
Inverse-gamma shape and scale for the three residual variances. |
a_rho, b_rho
|
Beta shape parameters for the prior inclusion probability rho. |
nu1 |
Spike variance multiplier; small values enforce a near-zero spike. |
gG, gV, gH, gZ, gBeta
|
Prior scale factors for the first-stage sender effects, the covariate effects, the first-stage receiver effects, the receptor main effect, and the causal block (Beta_X, Beta_XZ). The first three are Zellner g-priors on the observed designs G, V and H; the last two scale a fixed diagonal computed once from the least-squares first stage (see Details). |
ridge |
Diagonal ridge added before every matrix inversion. |
init_gamma |
Starting value (0 or 1) of the inclusion indicator. |
init_scale |
If greater than zero, Beta_X and Beta_XZ start from
independent normal draws with standard deviation |
verbose |
Logical; if |
The priors on the second-stage coefficients are
with
and computed once from least squares of X on
[G V] and of Z on [H V] and held fixed, and in the
slab and nu1 in the spike. Because the projected regressors
and are functions of the first-stage parameters, a prior whose
covariance was recomputed from the current draws would enter the full
conditionals of those parameters; fixing the scale keeps every update an
exact conjugate step. The values used are returned in prior_scale.
A named list with posterior means (Pi_X_mean, Alpha_X_mean,
Pi_Z_mean, Alpha_Z_mean, Beta_X_mean, Beta_XZ_mean,
Beta_Z_mean, Alpha_Y_mean, mu_mean, sigma_X_sq_mean,
sigma_Z_sq_mean, sigma_Y_sq_mean, gamma_mean, rho_mean), the
number of retained draws n_keep, the retained draws Beta_X_draws,
Beta_XZ_draws, Beta_Z_draws, gamma_draws, mu_draws and
loglik_draws (each a numeric vector of length n_keep), and
prior_scale, a named numeric vector giving d_X, d_XZ and d_Z.
loglik_draws is the joint
log-likelihood of the three equations evaluated at each retained draw,
excluding prior terms.
mr_ccc() for the user-facing interface.
sim <- simulate_mrccc(n = 120, seed = 1) ctr <- function(v) matrix(v - mean(v), ncol = 1) ctr_cols <- function(M) scale(M, center = TRUE, scale = FALSE) out <- mr_ccc_gibbs(ctr(sim$X), ctr(sim$Z), ctr(sim$Y), ctr_cols(sim$G), ctr_cols(sim$H), ctr_cols(sim$V), n_iter = 400, burn_in = 100, thin = 1) out$gamma_mean out$prior_scale length(out$Beta_XZ_draws) == out$n_keepsim <- simulate_mrccc(n = 120, seed = 1) ctr <- function(v) matrix(v - mean(v), ncol = 1) ctr_cols <- function(M) scale(M, center = TRUE, scale = FALSE) out <- mr_ccc_gibbs(ctr(sim$X), ctr(sim$Z), ctr(sim$Y), ctr_cols(sim$G), ctr_cols(sim$H), ctr_cols(sim$V), n_iter = 400, burn_in = 100, thin = 1) out$gamma_mean out$prior_scale length(out$Beta_XZ_draws) == out$n_keep
Constructs and validates the list of prior hyperparameters used by
mr_ccc(). The defaults are those used throughout the MR-CCC analyses and
are weakly informative for inputs on a scale of roughly unit variance:
with several hundred donors the likelihood then dominates the
inverse-gamma and beta priors. The inverse-gamma priors are not invariant
to the units of X, Z and Y, so inputs on very different scales
should be standardised before fitting.
mrccc_hyperparameters( a_sigma = 3, b_sigma = 2, a_rho = 3, b_rho = 1, nu1 = 1e-04, g = NULL, ridge = 1e-08 )mrccc_hyperparameters( a_sigma = 3, b_sigma = 2, a_rho = 3, b_rho = 1, nu1 = 1e-04, g = NULL, ridge = 1e-08 )
a_sigma, b_sigma
|
Shape and scale of the inverse-gamma prior on the
three residual variances |
a_rho, b_rho
|
Shape parameters of the beta prior on the prior
inclusion probability |
nu1 |
Spike variance multiplier in |
g |
Common g-prior scale applied to every coefficient block
(first-stage sender effects, first-stage receiver effects, covariate
effects, receptor main effect, and the causal block). If |
ridge |
Non-negative diagonal ridge added before every matrix inversion for numerical stability. |
Each first-stage block with observed design (the
genotype matrices , or the covariates ) has the
Zellner g-prior . The
second-stage blocks and use the
same scale but against a fixed diagonal computed once from the
least-squares first stage, because their regressors and
are themselves parameters of the model; see the Priors section
of mr_ccc(). The default follows the
unit-information convention for small samples and caps the prior
dispersion for large ones. The spike-and-slab prior on the causal block
uses scale in the slab and in the spike.
A named list of class mrccc_hyper with elements a_sigma,
b_sigma, a_rho, b_rho, nu1, g and ridge.
hyper <- mrccc_hyperparameters() str(hyper) # A more diffuse slab and a fixed g-prior scale mrccc_hyperparameters(nu1 = 1e-3, g = 50)hyper <- mrccc_hyperparameters() str(hyper) # A more diffuse slab and a fixed g-prior scale mrccc_hyperparameters(nu1 = 1e-3, g = 50)
Draws the posterior mean of the receptor-modulated ligand effect
over the observed range
of receptor expression, together with a pointwise credible band computed
from paired posterior draws.
plot_effect_curve( fit, Z_observed = NULL, level = 0.95, n_draws = 2000, standardized = TRUE )plot_effect_curve( fit, Z_observed = NULL, level = 0.95, n_draws = 2000, standardized = TRUE )
fit |
An object of class |
Z_observed |
Optional numeric vector of observed receptor expression
on the original (uncentred) scale, typically the |
level |
Credible level in |
n_draws |
Maximum number of paired draws used for the band. A systematic subsample of the pooled draws of this size is taken; the default of 2000 is ample for the quantiles of the band. |
standardized |
Logical; if |
The band is built from paired draws of , for
the same reason as the sign-reversal threshold in sign_reversal(): the
curve depends on two correlated parameters at once, so combining their
marginal intervals would misstate the uncertainty. At each grid point
, the band is the equal-tailed interval of
across the subsampled draws. A
horizontal reference line marks an effect of zero; where the band crosses
it, the direction of the ligand effect is uncertain.
The draws include both spike () and slab
() iterations, so the band reflects the full spike-and-
slab posterior.
A ggplot object that can be further modified.
mr_ccc(), sign_reversal(), plot.mrccc_fit()
sim <- simulate_mrccc(n = 150, beta_X = 0.3, beta_XZ = -0.3, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) p <- plot_effect_curve(fit, Z_observed = sim$Z) psim <- simulate_mrccc(n = 150, beta_X = 0.3, beta_XZ = -0.3, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) p <- plot_effect_curve(fit, Z_observed = sim$Z) p
Method for plot() that dispatches to plot_effect_curve().
## S3 method for class 'mrccc_fit' plot(x, Z_observed = NULL, ...)## S3 method for class 'mrccc_fit' plot(x, Z_observed = NULL, ...)
x |
An object of class |
Z_observed |
Optional numeric vector of observed receptor expression
(on the original scale) used to set the plotting range. If |
... |
Further arguments passed to |
A ggplot object.
sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) plot(fit)sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) plot(fit)
Prints a compact description of an mrccc_fit object: the chain
configuration, the posterior inclusion probability with its Monte Carlo
standard error, and the standardised posterior means of the three effect
sizes.
## S3 method for class 'mrccc_fit' print(x, digits = 3L, ...)## S3 method for class 'mrccc_fit' print(x, digits = 3L, ...)
x |
An object of class |
digits |
Number of significant digits used for printing. |
... |
Further arguments; ignored. |
x, invisibly.
sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) print(fit)sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) print(fit)
Extracts a single gene (row) from a SummarizedExperiment and returns it
as a plain named numeric vector suitable for the X, Z or Y argument
of mr_ccc(). The expected layout is donor-level (pseudo-bulk)
expression with genes as rows and donors (samples) as columns, so the
returned vector holds one value per donor, named by the column names of
the object.
se_row(se, gene, assay = 1L)se_row(se, gene, assay = 1L)
se |
A |
gene |
A single character string: the name of the gene to extract.
Must match one of |
assay |
The assay to read from: either a single positive integer
index or the name of an assay of |
A named numeric vector of length ncol(se) with names
colnames(se), holding the expression of gene in the selected assay.
sim <- simulate_mrccc(n = 60, seed = 1) m <- rbind(LIG1 = as.numeric(sim$X), REC1 = as.numeric(sim$Z)) colnames(m) <- paste0("donor", seq_len(ncol(m))) se <- SummarizedExperiment::SummarizedExperiment( assays = list(logcounts = m) ) x <- se_row(se, "LIG1") head(x)sim <- simulate_mrccc(n = 60, seed = 1) m <- rbind(LIG1 = as.numeric(sim$X), REC1 = as.numeric(sim$Z)) colnames(m) <- paste0("donor", seq_len(ncol(m))) se <- SummarizedExperiment::SummarizedExperiment( assays = list(logcounts = m) ) x <- se_row(se, "LIG1") head(x)
Computes the posterior probability that the ligand-by-receptor
interaction coefficient is positive and that it is
negative, both marginally and conditionally on the causal block being
included ().
sign_probabilities(fit)sign_probabilities(fit)
fit |
An object of class |
The prior on is a spike-and-slab mixture, so
the marginal posterior of is a mixture of two
components: draws taken while , which are concentrated
near zero and carry no directional information, and draws taken while
, which come from the slab. The two summaries therefore
answer different questions and both are informative.
The marginal probabilities p_pos_marginal and p_neg_marginal
use every retained draw. They combine the evidence that there is an
effect at all with the evidence about its direction. By the law of
total probability,
, and the
last factor is close to one half because the spike is symmetric about
zero.
The conditional probabilities p_pos_conditional and
p_neg_conditional use only the draws with . They
describe the direction of the interaction given that the ligand acts on
the pathway, and sum to one (up to draws exactly at zero).
A triplet with a high PIP and a conditional probability near one has a
well-determined direction; a triplet with a modest PIP can still have a
decisive conditional direction, in which case the marginal probability is
limited mainly by the inclusion uncertainty. When no retained draw has
, the conditional columns are NA.
A one-row data frame with columns pip, p_pos_marginal,
p_neg_marginal, p_pos_conditional, p_neg_conditional and
n_conditional (the number of pooled draws with ).
mr_ccc(), credible_intervals(), sign_reversal()
sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) sign_probabilities(fit)sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) sign_probabilities(fit)
Computes the posterior distribution of the sign-reversal threshold
, the receptor expression level at which
the receptor-modulated ligand effect changes
sign, from paired posterior draws of an MR-CCC fit.
sign_reversal(fit, Z_observed = NULL, level = 0.95)sign_reversal(fit, Z_observed = NULL, level = 0.95)
fit |
An object of class |
Z_observed |
Optional numeric vector of observed receptor expression
on the original (uncentred) scale, typically the |
level |
Credible level in |
is a ratio of two parameters, so its posterior can only be
obtained from paired draws of ; combining the
two marginal summaries would misstate the uncertainty because the two
coefficients are strongly correlated a posteriori. Draws in which the
standardised interaction is negligible,
, are dropped, since diverges there.
Applying the cutoff on the standardised scale makes it independent of the
units of , and .
All remaining draws are used, including those from the spike
(); for a fit with a PIP well below one, the threshold is
therefore best interpreted together with the PIP. Note that the model's
interaction acts on the genetically predicted receptor level ,
whereas p_in_range refers to the range of the observed receptor
expression.
Scale. mr_ccc() centres before fitting, so on the raw scale
is expressed in the
original units of relative to the mean receptor expression.
The function reports ,
in standard-deviation units of relative to its mean, which is the
scale on which the standardised coefficients are defined:
. A value of therefore corresponds to a
donor with average receptor expression, and to a donor one
standard deviation above the average. The observed range is expressed on
the same scale, .
Whether the reversal is realised in the population is determined by
p_in_range, the posterior probability that lies inside the
observed standardised receptor range, rather than by itself:
a threshold far outside the observed range describes a direction change
that no donor exhibits. The posterior of a ratio is heavy-tailed, so the
median and quantiles are reported rather than a mean.
A list with elements
tau_medianPosterior median of in standard-deviation
units of .
tau_lower, tau_upper
Equal-tailed credible bounds at level.
levelThe credible level.
n_drawsNumber of paired draws used.
Z_range_stdThe observed receptor range in standard-deviation units.
p_in_rangePosterior probability that lies inside
Z_range_std.
tau_drawsThe paired draws of (standardised scale).
All numeric summaries are NA when no usable paired draw is available.
mr_ccc(), plot_effect_curve(), sign_probabilities()
sim <- simulate_mrccc(n = 150, beta_X = 0.3, beta_XZ = -0.3, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) sr <- sign_reversal(fit, Z_observed = sim$Z) c(sr$tau_median, sr$tau_lower, sr$tau_upper, sr$p_in_range)sim <- simulate_mrccc(n = 150, beta_X = 0.3, beta_XZ = -0.3, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) sr <- sign_reversal(fit, Z_observed = sim$Z) c(sr$tau_median, sr$tau_lower, sr$tau_upper, sr$p_in_range)
Generates donor-level data for a single triplet under the MR-CCC data
generating process, including cis-eQTL instruments for the ligand and the
receptor, observed covariates, and an unmeasured confounder that loads on
the ligand, the receptor and the pathway. The output can be passed
directly to mr_ccc().
simulate_mrccc( n = 300, pG = 5, pH = 5, pV = 3, beta_X = 0.3, beta_XZ = 0.3, beta_Z = 0.5, pi_val = 0.5, conf_strength = 0.7, seed = NULL )simulate_mrccc( n = 300, pG = 5, pH = 5, pV = 3, beta_X = 0.3, beta_XZ = 0.3, beta_Z = 0.5, pi_val = 0.5, conf_strength = 0.7, seed = NULL )
n |
Number of donors. |
pG |
Number of sender instruments (columns of |
pH |
Number of receiver instruments (columns of |
pV |
Number of observed covariates (columns of |
beta_X |
True ligand main effect on the pathway. |
beta_XZ |
True ligand-by-receptor interaction effect. |
beta_Z |
True receptor main effect on the pathway. |
pi_val |
Common first-stage effect of every instrument on its target gene (instrument strength). |
conf_strength |
Loading of the unmeasured confounder |
seed |
Optional integer; if supplied, the data are simulated under
this seed and the caller's random number state is restored afterwards.
The default |
With independently, the
model is
where is conf_strength, every element of and
equals pi_val, every element of ,
and equals 0.3, and the residuals are
standard normal. The confounder induces a spurious association
between the exposures and the outcome that a naive regression absorbs
into the causal coefficients; the instruments allow MR-CCC to separate
the causal signal from it. Setting beta_X = beta_XZ = 0 gives a null
triplet.
A list with elements X, Z, Y (numeric matrices of dimension
), G, H, V (numeric matrices with rows),
U (the unmeasured confounder, for reference only) and truth, a list
of the generating parameters beta_X, beta_XZ, beta_Z, pi_val,
conf_strength and tau (the true sign-reversal threshold
in raw units of , or NA when
beta_XZ is zero).
sim <- simulate_mrccc(n = 200, seed = 42) str(sim$truth) dim(sim$G) # A null triplet null_sim <- simulate_mrccc(n = 200, beta_X = 0, beta_XZ = 0, seed = 42)sim <- simulate_mrccc(n = 200, seed = 42) str(sim$truth) dim(sim$G) # A null triplet null_sim <- simulate_mrccc(n = 200, beta_X = 0, beta_XZ = 0, seed = 42)
Prints the posterior inclusion probability with its Monte Carlo standard error and effective sample size, the standardised posterior means and credible intervals of the three effect sizes, the convergence diagnostics, and a note when the discovery status is not resolved at the current chain length. The assembled table is returned invisibly.
## S3 method for class 'mrccc_fit' summary(object, level = 0.95, digits = 3L, ...)## S3 method for class 'mrccc_fit' summary(object, level = 0.95, digits = 3L, ...)
object |
An object of class |
level |
Credible level for the reported intervals. |
digits |
Number of significant digits used for printing. |
... |
Further arguments; ignored. |
The discovery status is considered unresolved when
, where is the
discovery threshold stored in the fit; in that case a note recommends a
longer run or additional chains. The Gelman-Rubin column is NA unless the
fit used at least two chains.
Invisibly, a data frame with one row per quantity (beta_X,
beta_XZ, beta_Z, pip) and columns raw_mean, std_mean,
std_lower, std_upper and rhat. For the pip row the
raw and standardised means both equal the PIP, the interval columns are
NA, and rhat refers to the chain.
mr_ccc(), credible_intervals()
sim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) tab <- summary(fit) tabsim <- simulate_mrccc(n = 150, seed = 1) fit <- mr_ccc(sim$X, sim$Z, sim$Y, sim$G, sim$H, sim$V, n_iter = 600, burn_in = 100, seed = 1) tab <- summary(fit) tab