Generate a simulated sparse matrix for single-cell data testing

simulate_sparse_matrix(
  nrow,
  ncol,
  density = 0.1,
  distribution_fun = function(n) stats::rpois(n, lambda = 0.5) + 1,
  seed = 1
)

Arguments

nrow

Number of rows (genes) in the matrix.

ncol

Number of columns (cells) in the matrix.

density

Density of non-zero elements (default: 0.1, representing 90 sparsity).

distribution_fun

Function to generate non-zero values.

seed

Random seed for reproducibility.

Value

A sparse matrix of class "dgCMatrix"

Examples

simulate_sparse_matrix(2000, 500) |>
  check_sparsity()
#> [1] 0.904922