sim_mat: Simulate a Matrix with Metadata

View source: R/sim_mat.R

sim_matR Documentation

Simulate a Matrix with Metadata

Description

sim_mat() generates random normal data with optional compound-symmetric column correlation. Values can optionally be scaled to the interval ⁠[0, 1]⁠ column-wise. The function also creates feature metadata for columns and sample metadata for rows, and can inject NA values into a specified proportion of matrix cells across a specified proportion of columns.

Usage

sim_mat(
  n = 100,
  p = 100,
  rho = 0.5,
  n_col_groups = 2,
  n_row_groups = 1,
  perc_total_na = 0.1,
  perc_col_na = 0.5,
  beta = TRUE
)

Arguments

n

Integer. Number of rows, interpreted as samples. Defaults to 100.

p

Integer. Number of columns, interpreted as features. Defaults to 100.

rho

Numeric. Compound-symmetric column correlation before optional scaling. Defaults to 0.5.

n_col_groups

Integer. Number of groups to assign to features. Defaults to 2.

n_row_groups

Integer. Number of groups to assign to samples. Defaults to 1.

perc_total_na

Numeric scalar between 0 and 1. Proportion of all matrix cells to set to NA. Defaults to 0.1.

perc_col_na

Numeric scalar between 0 and 1. Proportion of columns across which injected NA values are spread. Defaults to 0.5.

beta

Logical. If TRUE, scale values to the interval ⁠[0, 1]⁠ column-wise.

Details

Generate a numeric matrix with optional row and column metadata and added missing values.

Value

An object of class slideimp_sim. This is a list containing:

  • input: a numeric matrix of dimension n \times p containing the simulated values and injected missing values.

  • col_group: a data frame with p rows mapping each feature to a group.

  • row_group: a data frame with n rows mapping each sample to a group.

Examples

set.seed(123)
sim_data <- sim_mat(n = 50, p = 10, rho = 0.5)
sim_data

slideimp documentation built on June 17, 2026, 1:08 a.m.