View source: R/general_tools.R
| get_pseudo_correlation | R Documentation |
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.
get_pseudo_correlation(
ZDB_matrix,
m1_inclusion = NULL,
m2_exclusion = NULL,
metric = "CoxSnell",
suppress_warnings = TRUE,
verbose = FALSE
)
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 |
m2_exclusion |
A numeric matrix (dense or sparse) of the same number of rows as |
metric |
Character string specifying which R² metric to compute. Options are "CoxSnell" (default) or "Nagelkerke". |
suppress_warnings |
Logical. If |
verbose |
Logical. If |
A data.table with the following columns:
The event names from ZDB_matrix rownames.
The computed pseudo R² correlation values using the specified metric.
Null correlation values from a permuted version of ZDB_matrix.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.