PMR_individual: PPMR Individual-level Analysis

View source: R/RcppExports.R

PMR_individualR Documentation

PPMR Individual-level Analysis

Description

PPMR Individual-level Analysis

Usage

PMR_individual(yin, zin, x1in, x2in, gammain, alphain, max_iterin, epsin)

Arguments

yin

Numeric vector of the outcome variable (length n1).

zin

Numeric vector of the mediator variable (length n2).

x1in

Numeric n1 \times p matrix of SNP genotypes for the outcome model.

x2in

Numeric n2 \times p matrix of SNP genotypes for the mediator model. Must have the same number of columns p as x1in.

gammain

Integer flag (0/1). If 1, constrains the gamma parameter to 0.

alphain

Integer flag (0/1). If 1, constrains the alpha parameter to 0.

max_iterin

Integer. Maximum number of EM iterations (default: 50 or more).

epsin

Numeric. Convergence tolerance for the log-likelihood.

Value

A named list with elements:

alpha

Estimated causal effect of the mediator on the outcome.

gamma

Estimated direct effect of the SNPs on the outcome.

sigmaX

Residual variance of the outcome model.

sigmaY

Residual variance of the mediator model.

sigmabeta

Variance of the genetic effects.

loglik_seq

Vector of log-likelihood values across iterations.

loglik

Final log-likelihood value.

iteration

Number of iterations before convergence.

Examples

# ---- Simulate simple example data ----
set.seed(456)
n1 <- 8
n2 <- 10
p  <- 3

# Outcome and mediator vectors
y <- c(0.5, -0.3, 0.1, 0.4, -0.2, 0.0, 0.6, -0.1)
z <- c(0.2, -0.4, 0.3, 0.1, -0.1, 0.5, 0.0, 0.4, -0.3, 0.2)

# Fixed genotype design matrices (n × p) with mild correlations
x1 <- matrix(c(
  1.0, 0.2, 0.1,
  0.2, 1.0, 0.3,
  0.1, 0.3, 1.0,
  0.4, 0.1, 0.2,
  0.2, 0.4, 0.3,
  0.3, 0.2, 0.4,
  0.5, 0.1, 0.3,
  0.1, 0.5, 0.2
), nrow = n1, byrow = TRUE)

x2 <- matrix(c(
  1.0, 0.3, 0.2,
  0.3, 1.0, 0.4,
  0.2, 0.4, 1.0,
  0.5, 0.1, 0.3,
  0.2, 0.5, 0.1,
  0.3, 0.2, 0.4,
  0.4, 0.3, 0.2,
  0.1, 0.4, 0.3,
  0.2, 0.1, 0.5,
  0.3, 0.2, 0.4
), nrow = n2, byrow = TRUE)

# Run PPMR individual-level analysis
PMR_individual(
  yin        = y,
  zin        = z,
  x1in       = x1,
  x2in       = x2,
  gammain    = 0,
  alphain    = 0,
  max_iterin = 50,
  epsin      = 1e-6
)


PPMR documentation built on Nov. 5, 2025, 5:07 p.m.