Package {SIMPLICA}


Title: Simplivariate Component Analysis
Version: 2.0.0
Description: Identifies coherent biclusters in numeric data matrices using simplivariate component analysis. Components are extracted sequentially using a binary genetic algorithm to select subsets of rows and columns, followed by residual deflation. Six built-in component patterns are supported: constant, row, column, additive, multiplicative, and additive-multiplicative. Components may overlap, and missing values are handled without imputation. Cross-validation can be used for pattern selection after component extraction. User-defined component patterns and corresponding model complexity specifications can also be supplied. The method builds on simplivariate models as introduced in Hageman et al. (2008) <doi:10.1371/journal.pone.0003259> and is related to biclustering frameworks as reviewed by Madeira and Oliveira (2004) <doi:10.1109/TCBB.2004.2>.
License: GPL-3
Encoding: UTF-8
Depends: R (≥ 4.1)
Imports: compiler, GA, ggplot2, ggsci, stats, utils
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
LazyData: true
LazyDataCompression: xz
URL: https://github.com/joshageman/SIMPLICA
BugReports: https://github.com/joshageman/SIMPLICA/issues
Config/roxygen2/markdown: TRUE
Config/roxygen2/version: 8.1.1
NeedsCompilation: no
Packaged: 2026-11-26 12:07:15 UTC; hagem011
Author: Jos Hageman [aut, cre]
Maintainer: Jos Hageman <jos.hageman@wur.nl>
Repository: CRAN
Date/Publication: 2026-11-26 14:10:15 UTC

Cross-Validation of Simplivariate Component Patterns

Description

Compares patterns on a block with fixed rows and columns. Each pattern is tested on the same held-out cells. Patterns must produce valid predictions on every split. The simplest pattern within parsimonyMargin of the lowest pooled RMSE is selected. Custom functions receive a matrix whose held-out cells are NA and must return a numeric matrix of the same size.

Usage

componentCVPatterns(
  df,
  rows,
  cols,
  patterns = defaultPatterns(),
  customPatterns = list(),
  customPatternComplexity = list(),
  preferenceOrder = c(patterns, names(customPatterns)),
  nRepeats = 5,
  testFraction = 0.2,
  parsimonyMargin = 0.02,
  cvSeed = 1,
  verbose = FALSE,
  splitScores = NULL
)

Arguments

df

A numeric matrix or data frame. Missing values are allowed.

rows, cols

Fixed row and column indices of the component.

patterns

Built-in pattern names.

customPatterns

Named custom approximation functions.

customPatternComplexity

Named complexities for custom patterns.

preferenceOrder

Tie-break order between equal-complexity patterns.

nRepeats

Number of repeated held-out splits.

testFraction

Requested fraction of usable cells to hold out.

parsimonyMargin

Relative RMSE margin within which the simplest model is selected.

cvSeed

Seed used to generate splits without changing the caller's RNG.

verbose

Print progress messages.

splitScores

Optional deterministic split priorities with dimensions nrow(df) by ncol(df) by nRepeats.

Value

A list containing the selected pattern (decision), an explanation (reason), pooled RMSE by pattern (cv), RMSE by split (repeats), and the settings used (meta). See simplicaCV() for evaluating fitted SIMPLICA components on their search matrices.

Examples

set.seed(1)
x <- outer(1:8, 1:8, "+") + matrix(rnorm(64, sd = 0.1), 8, 8)
cv <- componentCVPatterns(x, rows = 1:8, cols = 1:8,
                          patterns = c("constant", "additive"))
cv$decision
cv$cv


Default conditional pattern complexities for fitness

Description

Gives the parameter count for each built-in pattern at a given block size. SIMPLICA uses these counts in the fitness penalty.

Usage

defaultPatternComplexity()

Details

Each custom pattern supplied to simplica() must have a corresponding complexity entry. Entries may also be fixed non-negative numeric values.

Value

A named list. Each element is a function accepting nRows, nCols, and nObserved, and returning one non-negative number.

Examples

complexity <- defaultPatternComplexity()
vapply(complexity, function(count) count(6, 10, 60), numeric(1))


Names of the default SIMPLICA patterns

Description

Names of the default SIMPLICA patterns

Usage

defaultPatterns()

Value

A character vector containing the six default pattern names.

Examples

defaultPatterns()

Plot fitted components

Description

Draws the original matrix as a heatmap and outlines fitted components by pattern.

Usage

plotComponentResult(
  df,
  string,
  componentPatterns,
  componentScores,
  scoreCutoff = 0,
  showAxisLabels = TRUE,
  showComponentLabels = TRUE,
  title = "Detected Components",
  rearrange = FALSE,
  grayscale = TRUE
)

Arguments

df

Original data matrix. Missing values are permitted and are rendered using the missing-value colour of the selected ggplot2 fill scale.

string

Membership string from the fit (vector of length nrow(df) + ncol(df); rows first, then columns). Values are bit masks, allowing rows and columns to belong to multiple components.

componentPatterns

Vector of component pattern names, typically obtained from a fitted SIMPLICA object.

componentScores

Vector of fitness scores per component

scoreCutoff

Minimum score a component must have to be shown. At the default of 0, only strictly positive components are shown; use a lower value to show inactive or negative component slots.

showAxisLabels

Logical: show axis tick labels (default: TRUE)

showComponentLabels

Logical: show component labels inside clusters (default: TRUE)

title

Title for the plot (default: "Detected Components")

rearrange

Logical: reorder rows and columns to group components (default: FALSE)

grayscale

Logical: use grayscale for heatmap background (default: TRUE)

Value

ggplot object

Examples

data("simplicaVignette")

fit <- simplicaVignette$fit

plotComponentResult(
  df = simplicaVignette$data,
  string = fit$string,
  componentPatterns = fit$componentPatterns,
  componentScores = fit$componentScores,
  showAxisLabels = FALSE,
  rearrange = TRUE
)


Print method for summaryComponents

Description

Print method for summaryComponents

Usage

## S3 method for class 'summaryComponents'
print(x, showDetails = FALSE, maxLinesDetails = 200, ...)

Arguments

x

An object produced by summaryComponents().

showDetails

Logical. If TRUE, also print row/column indices per component.

maxLinesDetails

Integer. Max number of indices to print per dimension (rows/cols) before truncation (default 200).

...

Further arguments passed to or from other methods (not used here).

Value

The input object x, invisibly. Called for its side effect of printing a formatted component summary to the console.


Fit SIMPLICA components

Description

Finds one component at a time. For each component, the genetic algorithm searches for rows, columns and a pattern, using each seed in mySeeds. SIMPLICA keeps the highest-scoring candidate. It refits the pattern and subtracts the fitted values minus the background location within that block before searching again. The background stays fixed throughout the fit. The search stops at numSimComp or when the best score is zero or negative. Optional cross-validation suggests patterns for interpretation after the search.

Usage

simplica(
  df,
  numSimComp,
  maxIter = 5000,
  run = 500,
  popSize = 200,
  pCrossover = 0.9,
  pMutation = 0.2,
  maxMutatedGenes = 5,
  maxCrossoverPoints = 20,
  elitism = 80,
  verbose = FALSE,
  mySeeds = 1:5,
  interval = 100,
  patterns = defaultPatterns(),
  customPatterns = list(),
  customPatternComplexity = list(),
  minimumRows = 3,
  minimumColumns = 3,
  doSimplicaCV = TRUE,
  cvControl = NULL,
  backgroundSignal = NULL,
  backgroundScale = NULL,
  selectionPressure = 1.01,
  zeroFraction = 0.75
)

Arguments

df

Numeric matrix or data frame. Missing values are allowed.

numSimComp

Maximum number of components (1 to 31).

maxIter, run, popSize, pCrossover, elitism, selectionPressure, verbose, interval

GA controls. maxIter caps generations and run stops a start after that many generations without improvement. popSize is the population size, pCrossover is the crossover probability, and elitism caps the number of distinct elite candidates carried forward. selectionPressure controls rank-based selection (1 gives equal weights). With verbose = TRUE, progress is printed every interval generations.

pMutation

Probability of mutating each string.

maxMutatedGenes

Maximum distinct bit flips; sample uniformly from 1 to this maximum (default 5).

maxCrossoverPoints

Maximum cuts, sampled uniformly per crossover (default 20); capped at string length minus one.

mySeeds

Seeds used anew for each component (default 1:5).

patterns

Built-in patterns to compare.

customPatterns

Named custom approximation functions.

customPatternComplexity

Named complexities for custom patterns.

minimumRows, minimumColumns

Minimum selected dimensions (default 3).

doSimplicaCV

Whether to report cross-validated pattern suggestions after the search.

cvControl

Optional tuning arguments for simplicaCV. SIMPLICA defaults to ten splits and requires seven shared valid splits. When nRepeats is supplied, all splits are required unless minValidRepeats is supplied too.

backgroundSignal, backgroundScale

Background location and positive scale. Supply both to override estimation.

zeroFraction

Probability of initializing a gene to zero (default 0.75).

Value

A list with best (a fitted SIMPLICA object) and raw (GA results grouped by search step and seed). Use summaryComponents(best) to view the retained components. The fit contains componentFits, the final residuals, bestSeeds, per-step seedFitness and a stopReason. Unused slots have zero scores. The total fitness is the sum of the retained component scores.

Typical analysis

The following code reproduces the SIMPLICA analysis presented in the package vignette. The analysis takes several minutes to complete.

data("simplicaVignette")
x <- simplicaVignette$data
analysis <- do.call(simplica, c(list(df = x), simplicaVignette$info$gaSettings))
fit <- analysis$best
summaryComponents(fit)

Cross-validate fitted component patterns

Description

Uses held-out cells to select the simplest pattern within parsimonyMargin of the reference pattern's pooled RMSE. With compareToBest = TRUE, all testable patterns can qualify. Patterns are included in order of valid split count while at least minValidRepeats common splits remain. The lowest pooled RMSE on those common splits sets the reference. Otherwise the GA pattern sets the reference and each simpler alternative is compared on its shared splits. Row and column membership, GA fitness, component scores, and the original GA-selected patterns are never changed. When the object is updated, fits returned by simplica() retain the fits used for deflation. Standalone component objects refresh parameter fits for the CV-selected pattern.

Usage

simplicaCV(
  foundObject,
  df,
  patterns = defaultPatterns(),
  customPatterns = list(),
  customPatternComplexity = list(),
  preferenceOrder = c(patterns, names(customPatterns)),
  nRepeats = 5,
  testFraction = 0.2,
  parsimonyMargin = 0.02,
  cvSeed = 1,
  updateObject = TRUE,
  verbose = FALSE,
  minValidRepeats = nRepeats,
  compareToBest = !is.null(foundObject[["components"]])
)

Arguments

foundObject

A simplica object with fixed component membership.

df

Original numeric data matrix or data frame.

patterns

Built-in patterns to compare.

customPatterns

Named custom approximation functions.

customPatternComplexity

Named complexities for custom patterns.

preferenceOrder

Tie-break order between equal-complexity patterns.

nRepeats

Number of repeated held-out splits.

testFraction

Requested fraction of usable cells to hold out.

parsimonyMargin

Relative RMSE margin for selecting a simpler model.

cvSeed

Seed for reproducible splits; the caller's RNG is preserved.

updateObject

Return the input object with CV-specific fields added.

verbose

Print component and repeat progress.

minValidRepeats

Minimum number of shared valid splits for comparison with the reference pattern.

compareToBest

Use the lowest CV RMSE among patterns with enough valid splits as the reference. Defaults to true for a fit returned by simplica().

Details

Fits returned by simplica() are evaluated component by component on their original residual trajectory. Standalone component objects use the supplied data. Multi-component CV requires the original residual trajectory. Components whose GA score is not positive are not cross-validated.

Value

With updateObject = TRUE, the unchanged input object plus componentPatternsUpdated and componentAudit. Standalone component objects also receive refreshed componentFits. Otherwise a list containing only the two CV-specific results. componentPatternsUpdated retains the original GA-selected pattern for a component when CV cannot make a decision.


Simulated matrix and fitted components

Description

A simulated matrix and its SIMPLICA fit for the introductory vignette. The fit is stored so examples can run without repeating the GA.

Usage

simplicaVignette

Format

A named list with three elements:

data

The simulated matrix with 60 rows, 120 columns and 5 percent missing values. It contains one planted block for each of the six built-in patterns.

fit

The result of fitting up to six components, including post-fit CV, residuals, component fits and scores by seed.

info

Arguments used for the fit, dataset ID, simulation seeds, and SIMPLICA and R versions.

Details

Use do.call(simplica, c(list(df = simplicaVignette$data), simplicaVignette$info$gaSettings)) to rerun the fit. The source checkout contains the simulation and fitting scripts in ⁠data-raw/⁠.

Examples

data("simplicaVignette")

x <- simplicaVignette$data
fit <- simplicaVignette$fit

dim(x)
mean(is.na(x))
summaryComponents(fit)

Summarize fitted components

Description

Summarizes the fitted pattern, score and membership of each component. Returns a data.frame with class "summaryComponents" and an attribute holding row/column index lists for printing details.

Usage

summaryComponents(results, scoreCutoff = 0)

Arguments

results

A list or 'simplica' object with fields: nRows, nCols, string, componentScores, and either componentPatternsUpdated or componentPatterns. The membership string uses bit masks and can assign a row or column to multiple components.

scoreCutoff

Numeric. Minimum score to include a component. At the default of 0, only strictly positive components are included; use a lower value to inspect inactive or negative component slots.

Value

A data.frame with columns: componentId, pattern, gaPattern, cvPattern, cvChanged, score, rows, cols, and size. The pattern column is the fitted pattern used for deflation in a fit returned by simplica(), or the effective pattern after CV for a standalone component. gaPattern is the original GA selection and cvPattern is the CV decision. When CV cannot decide, the fitted pattern is still reported while cvPattern and cvChanged are NA. They are also NA when CV was not run. class is c("summaryComponents","data.frame"). The attribute "indices" stores a list with per-component rowIdx and colIdx. The logical attribute "cv_run" records whether CV was run. The size column is the full row-by-column rectangle and does not subtract original missing values or cells shared by multiple components.

Examples

data("simplicaVignette")

componentSummary <- summaryComponents(simplicaVignette$fit)
componentSummary

componentId <- 1
membership <- attr(componentSummary, "indices")[[
  match(componentId, componentSummary$componentId)
]]
membership$rowIdx
membership$colIdx