modelSampling: Generate Training and Validation Sampling Matrices

View source: R/terga1.lib.R

modelSamplingR Documentation

Generate Training and Validation Sampling Matrices

Description

This function creates a sampling matrix for cross-validation, specifying which samples should be used for training and validation across multiple iterations. It supports two sampling types: "window" (systematic shifting) and "random" (random selection).

Usage

modelSampling(
  vect,
  sampling.type = c("window", "random"),
  training.pc = 90,
  iteration = 10
)

Arguments

vect

A matrix or data frame with samples as columns, used to determine the sampling order and dimensions.

sampling.type

A character string indicating the sampling method, either '"window"' or '"random"'. Default is 'c("window", "random")'. - '"window"': Sequentially shifts the training window across samples. - '"random"': Randomly selects training samples in each iteration.

training.pc

An integer representing the percentage of samples to be allocated for training in each iteration. Default is 90.

iteration

An integer specifying the number of sampling iterations. Default is 10.

Details

The function creates a binary sampling matrix with rows as sample names and columns as iterations. Cells with '1' indicate the sample is in the training set, while '0' indicates the sample is in the validation set. For '"window"' sampling, a moving window of training samples shifts across each iteration. For '"random"' sampling, training samples are selected randomly in each iteration.

**Sampling Process**: - For '"window"': A sequential window of 'size.train' is assigned for training, wrapping around if needed. - For '"random"': A random subset of size 'size.train' is selected as the training set in each iteration.

Value

A binary matrix with dimensions '(number of samples) x (iteration)', indicating training ('1') and validation ('0') samples for each iteration.

Examples

## Not run: 
vect <- matrix(rnorm(100), nrow = 10)  # Example data
sampling_matrix <- modelSampling(vect, sampling.type = "random", training.pc = 80, iteration = 5)
print(sampling_matrix)

## End(Not run)


predomics/predomicspkg documentation built on Dec. 11, 2024, 11:06 a.m.