get_pseudo_correlation: Compute Pseudo-Correlation Using Beta-Binomial Model

View source: R/general_tools.R

get_pseudo_correlationR Documentation

Compute Pseudo-Correlation Using Beta-Binomial Model

Description

This function calculates a pseudo R²-like correlation metric using a beta-binomial model implemented in C++. It takes in a data matrix ZDB_matrix and two model matrices for inclusion and exclusion, respectively. The function now supports both sparse and dense matrices for m1 and m2, and allows selection between Cox-Snell and Nagelkerke R² metrics.

Usage

get_pseudo_correlation(
  ZDB_matrix,
  m1_inclusion = NULL,
  m2_exclusion = NULL,
  metric = "CoxSnell",
  suppress_warnings = TRUE,
  verbose = FALSE
)

Arguments

ZDB_matrix

A numeric dense matrix of shape (events x samples). Should have rownames representing events.

m1_inclusion

A numeric matrix (dense or sparse) of the same number of rows as ZDB_matrix, representing inclusion features.

m2_exclusion

A numeric matrix (dense or sparse) of the same number of rows as ZDB_matrix, representing exclusion features.

metric

Character string specifying which R² metric to compute. Options are "CoxSnell" (default) or "Nagelkerke".

suppress_warnings

Logical. If TRUE (default), suppresses warnings during computation (e.g., due to ill-conditioned inputs).

verbose

Logical. If TRUE, prints progress and informational messages. Default is FALSE.

Value

A data.table with the following columns:

event

The event names from ZDB_matrix rownames.

pseudo_correlation

The computed pseudo R² correlation values using the specified metric.

null_distribution

Null correlation values from a permuted version of ZDB_matrix.

Examples


set.seed(42)
# get the m1 object
junction_abundance_object <- load_toy_SJ_object()
m1_obj <- make_m1(junction_ab_object = junction_abundance_object)

# obtaining the m1 and eventdata
m1_inclusion <- m1_obj$m1_inclusion_matrix
eventdata <- m1_obj$event_data
m2_exclusion <- make_m2(m1_inclusion, eventdata)

# creating a dummy ZDB
ZDB_matrix <- matrix(rnorm(n = (nrow(m1_inclusion) * ncol(m1_inclusion)), sd = 7),
nrow = nrow(m1_inclusion),
ncol = ncol(m1_inclusion))
rownames(ZDB_matrix) <- rownames(m1_inclusion)

# m1 and m2 can now be either sparse or dense matrices
# Example with dense matrices (backward compatible)
m1_dense <- as.matrix(m1_inclusion)
m2_dense <- as.matrix(m2_exclusion)
pseudo_r_square_cox <- get_pseudo_correlation(ZDB_matrix, m1_dense, m2_dense)
print(pseudo_r_square_cox)

# Example with sparse matrices (more memory efficient)
pseudo_r_square_sparse <- get_pseudo_correlation(ZDB_matrix, m1_inclusion, m2_exclusion)

# Example using Nagelkerke R-squared instead of Cox-Snell
pseudo_r_square_nagel <- get_pseudo_correlation(ZDB_matrix, m1_inclusion, m2_exclusion,
                                                metric = "Nagelkerke")
print(pseudo_r_square_nagel)



splikit documentation built on May 13, 2026, 9:08 a.m.