simu_n: Simulate multivariate normal data for multiple classes

View source: R/generate_simulation.R

simu_nR Documentation

Simulate multivariate normal data for multiple classes

Description

Generates synthetic classification data by drawing independent multivariate normal samples for each class. Useful when you want explicit control over each class's mean and covariance structure.

Usage

simu_n(
  means,
  covs,
  ns,
  class_names = NULL,
  seed = NULL,
  noise_ratio = 0,
  test_ratio = 0
)

Arguments

means

A list of numeric vectors, one per class, specifying the class means. Each vector must have length equal to the number of features.

covs

A list of covariance matrices, one per class.

ns

A numeric vector of sample sizes, one per class.

class_names

Optional character vector of class labels (length equal to length(ns)). Defaults to "Class 1", "Class 2", etc.

seed

Optional integer for reproducibility. The global random seed is restored after the call.

noise_ratio

Numeric in [0, 1). Proportion of sum(ns) to add as uniform background noise (randomly labeled).

test_ratio

Numeric in [0, 1). If greater than 0, generates an additional independent test dataset. This is not a split of the training data.

Details

Test data

When test_ratio > 0, an additional independent test dataset is generated by drawing fresh samples of size round(ns * test_ratio) for each class using the same means and covs. This is not a split of the training data. The training set has sum(ns) observations; the test set has sum(round(ns * test_ratio)) independently generated observations.

Value

If test_ratio == 0 (default): a data frame with a Sim class column and feature columns (X1, X2, ...). If test_ratio > 0: a list with ⁠$train⁠ and ⁠$test⁠ data frames.

See Also

simulate_mixsim()

Examples


means <- list(c(0, 0), c(3, 3), c(0, 5))
covs <- list(diag(2), diag(2), diag(2))
ns <- c(60, 60, 60)

train_df <- simu_n(means, covs, ns, seed = 1)
head(train_df)

# With independent test data
sim <- simu_n(means, covs, ns, seed = 1, test_ratio = 0.3)
nrow(sim$train) # 180
nrow(sim$test) # 54 (independently generated, not split from train)


classbound documentation built on Sept. 30, 2026, 5:13 p.m.