### Install multidesign R Package Source: https://github.com/bbuchsbaum/multidesign/blob/master/CLAUDE.md Instructions for installing the `multidesign` R package. This includes direct installation from GitHub via R's `devtools`, or by cloning the repository and installing locally using command line tools and R's `R CMD INSTALL`. ```Bash # From R console devtools::install_github("bbuchsbaum/multidesign") # Or clone and install locally git clone https://github.com/bbuchsbaum/multidesign.git cd multidesign R CMD INSTALL . # Or using devtools devtools::install() ``` -------------------------------- ### R testthat Package Setup Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This R code demonstrates the basic setup for unit testing an R package using the `testthat` framework. It loads the `testthat` and `multidesign` libraries and then runs all tests defined within the `multidesign` package, ensuring code quality and functionality. ```R library(testthat) library(multidesign) test_check("multidesign") ``` -------------------------------- ### R: Example of multiframe.list usage Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This example demonstrates how to create a `multiframe` object using the `multiframe.list` function, providing a list of matrices and a data frame for design information. It shows how to access individual observations and print the design tibble. ```R # Create list of observations (matrices with same number of columns) x <- list( matrix(1:12, 3, 4), # 3x4 matrix matrix(13:24, 3, 4), # 3x4 matrix matrix(25:36, 3, 4) # 3x4 matrix ) # Create design information y <- data.frame( condition = c("A", "B", "C"), block = 1:3 ) # Create multiframe mf <- multiframe(x, y) # Access first observation obs1 <- mf$design$.obs[[1]]() # View design information print(mf$design) ``` -------------------------------- ### R Example: Extracting Data Matrix with xdata Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Shows how to use `xdata` to extract the underlying data matrix from a `multidesign` object. ```R # With a multidesign object X <- matrix(rnorm(20*10), 20, 10) Y <- data.frame(group = rep(letters[1:4], each=5)) mds <- multidesign(X, Y) X_data <- xdata(mds) # Returns the original matrix X ``` -------------------------------- ### Initialize Transformation for Hyperdesign Objects Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Method to initialize transformations (e.g., scaling, centering) for hyperdesign objects. Each block in the hyperdesign gets its own transformation object. ```APIDOC Initialize Transformation for Hyperdesign: @param x A hyperdesign object @param preproc A preprocessing specification (e.g., from recipes package) ``` -------------------------------- ### R Example: Summarizing Data with summarize_by Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Demonstrates how to use `summarize_by` with a matrix, a `multidesign` object, and a `multiframe` object to calculate group means. ```R X <- matrix(rnorm(100*10), 100, 10) groups <- rep(letters[1:5], each=20) group_means <- summarize_by(X, colMeans, groups) # With a multidesign object mds <- multidesign(X, data.frame(group=groups)) mds_means <- summarize_by(mds, group) # With a multiframe object mf <- multiframe(X, data.frame(group=groups)) mf_means <- summarize_by(mf, group) ``` -------------------------------- ### Subset 'multidesign' Objects in R Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Illustrates how to subset a 'multidesign' object based on conditions applied to its design tibble. Shows examples of simple and complex conditional subsetting, and handling cases with no matching results. ```R X <- matrix(1:20, 5, 4) Y <- tibble( condition = rep(c("A", "B"), c(2, 3)), subject = 1:5 ) md <- multidesign(X, Y) # Test simple subsetting sub_A <- subset(md, condition == "A") expect_equal(nrow(sub_A$x), 2) expect_equal(sub_A$design$condition, c("A", "A")) # Test multiple conditions sub_AB1 <- subset(md, condition == "A" & subject <= 2) expect_equal(nrow(sub_AB1$x), 2) # Test empty result sub_none <- subset(md, condition == "C") expect_null(sub_none) ``` -------------------------------- ### R Example: Generating Cross-validation Folds with fold_over Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Illustrates the usage of `fold_over` for creating cross-validation splits with matrix data, `multidesign` objects, and `hyperdesign` objects. ```R # Basic example with matrix data X <- matrix(rnorm(100*10), 100, 10) groups <- rep(1:2, each=50) folds <- fold_over(X, nfolds=5, stratum=groups) # With a multidesign object mds <- multidesign(X, data.frame(group=groups, subject=rep(1:10, each=10))) folds_by_group <- fold_over(mds, group) # With a hyperdesign object (multiple subjects) d1 <- multidesign(matrix(rnorm(10*20), 10, 20), data.frame(condition=rep(c("A","B"), 5), run=1:10)) d2 <- multidesign(matrix(rnorm(10*20), 10, 20), data.frame(condition=rep(c("A","B"), 5), run=1:10)) hd <- hyperdesign(list(d1, d2), block_names=c("subject1", "subject2")) folds_by_condition <- fold_over(hd, condition) ``` -------------------------------- ### Summarize 'multidesign' Objects by Group in R Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Shows how to summarize the data matrix (X) of a 'multidesign' object by grouping variables from its design tibble. Includes examples of default summarization (mean) and custom summary functions. ```R X <- matrix(1:20, 5, 4) Y <- tibble( condition = rep(c("A", "B"), c(2, 3)), subject = rep(1:3, length.out=5) ) md <- multidesign(X, Y) # Test summarization by condition sum_cond <- summarize_by(md, condition) expect_equal(nrow(sum_cond$x), 2) # One row per condition expect_equal(ncol(sum_cond$x), ncol(X)) expect_equal(sum_cond$design$condition, c("A", "B")) # Test custom summary function sum_custom <- summarize_by(md, condition, sfun=function(x) apply(x, 2, sd)) expect_equal(dim(sum_custom$x), dim(sum_cond$x)) ``` -------------------------------- ### R `hyperdesign` Object and Constructor API Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt The `hyperdesign` object in R encapsulates a collection of `multidesign` objects, useful for modeling multi-group, multi-block, or multi-view datasets. It represents related multivariate datasets that share common design variables. This entry details its constructor and provides usage examples. ```APIDOC hyperdesign <- function(x, ...) UseMethod("hyperdesign") - Description: Constructs a new `hyperdesign` object that encapsulates a collection of `multidesign` objects. - Parameters: - x: A list of multidesign objects. Each instance should represent a related block of data. - ...: Additional arguments passed to methods, such as block_names for naming each block. - Returns: A hyperdesign object with the following components: - blocks: List of multidesign objects. - block_names: Names of each block. - col_indices: Matrix of column start/end indices for each block. - row_indices: Matrix of row start/end indices for each block. - Usage Example: # Create three multidesign objects (e.g., for three subjects) d1 <- multidesign( matrix(rnorm(10*20), 10, 20), data.frame(y=1:10, subject=1, run=rep(1:5, 2)) ) d2 <- multidesign( matrix(rnorm(10*20), 10, 20), data.frame(y=1:10, subject=2, run=rep(1:5, 2)) ) d3 <- multidesign( matrix(rnorm(10*20), 10, 20), data.frame(y=1:10, subject=3, run=rep(1:5, 2)) ) # Combine into a hyperdesign hd <- hyperdesign( list(d1, d2, d3), block_names = c("subject1", "subject2", "subject3") ) ``` -------------------------------- ### R: Define and Use design for Observation Metadata Extraction Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Defines the S3 generic `design` function in R for extracting observation-level metadata from `multidesign` and `hyperdesign` objects. Includes examples demonstrating how to use `design` to retrieve all design information or design from a specific block. ```R design <- function(x, ...) UseMethod("design") ``` ```R # With a multidesign object X <- matrix(rnorm(20*10), 20, 10) Y <- data.frame( condition = rep(c("A", "B"), each=10), subject = rep(1:5, times=4) ) mds <- multidesign(X, Y) design_info <- design(mds) # Returns the original data frame Y # With a hyperdesign object d1 <- multidesign(matrix(rnorm(10*5), 10, 5), data.frame(condition=rep(c("A","B"), 5), subject=1)) d2 <- multidesign(matrix(rnorm(10*5), 10, 5), data.frame(condition=rep(c("A","B"), 5), subject=2)) hd <- hyperdesign(list(d1, d2)) all_designs <- design(hd) # Returns list of design data frames block1_design <- design(hd, block=1) # Returns just the first block's design ``` -------------------------------- ### R `multidesign` Object and Constructor API Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt The `multidesign` object in R links vector-valued observations with design variables, forming a structured representation of experimental data. It comprises a data matrix, a design data frame, and optional column metadata. This entry details its constructor and provides usage examples. ```APIDOC multidesign <- function(x, y, ...) UseMethod("multidesign") - Description: Constructs a new multivariate design object linking vector-valued observations with design variables. - Parameters: - x: The multivariate data (a matrix, a list, or other data container). - y: A design matrix or data frame with same number of rows/elements as x. - ...: Additional arguments passed to methods, such as column_design. - Returns: A multidesign object with components: - x: The input data matrix. - design: A tibble containing design variables. - column_design: A tibble containing column metadata (if provided). - Usage Example: # Create example data matrix X <- matrix(rnorm(20*100), 20, 100) # Create design information Y <- tibble(condition=rep(letters[1:5], 4)) # Create multidesign object mds <- multidesign(X, Y) # Split by condition sdes <- split(mds, condition) ``` -------------------------------- ### multiblock Function API Reference (R) Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt API reference for the `multiblock` function in R, used to construct multiblock objects from a list of matrices. It automatically determines stacking orientation (row or column) based on matrix dimensions and preserves block structure information. Includes detailed parameter descriptions, return values, and usage examples. ```APIDOC multiblock <- function(x, ...) UseMethod("multiblock") Description: Constructs a new multiblock object consisting of a set of stacked submatrices sharing a row or column dimension. This structure is useful for analyzing data with multiple related blocks of measurements while preserving block structure information. Details: A multiblock object automatically determines whether matrices should be: * Row-stacked: all matrices must have the same number of columns * Column-stacked: all matrices must have the same number of rows The resulting object maintains block structure information while allowing operations across the entire combined matrix. Parameters: x: A list of matrices sharing either row or column dimensions ...: Additional arguments passed to methods Returns: A multiblock object with the following attributes: ind: Matrix of start/end indices for each block orient: Orientation of stacking ("cstacked" or "rstacked") Examples: # Create list of matrices with varying row dimensions (column-stacked) X1 <- matrix(rnorm(20*3), 20, 3) X2 <- matrix(rnorm(20*5), 20, 5) X3 <- matrix(rnorm(20*4), 20, 4) mb_c <- multiblock(list(X1, X2, X3)) is_cstacked(mb_c) # TRUE # Create list of matrices with varying column dimensions (row-stacked) Y1 <- matrix(rnorm(10*5), 10, 5) Y2 <- matrix(rnorm(15*5), 15, 5) Y3 <- matrix(rnorm(20*5), 20, 5) mb_r <- multiblock(list(Y1, Y2, Y3)) is_rstacked(mb_r) # TRUE See Also: is_cstacked: for checking if a multiblock object is column-stacked is_rstacked: for checking if a multiblock object is row-stacked block_indices: for accessing block-specific indices ``` -------------------------------- ### Subset R hyperdesign Objects by Conditions Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This example demonstrates how to subset a `hyperdesign` object based on specific conditions using the `subset` function. It shows filtering by a single condition ('condition == "A"') and by multiple conditions ('condition == "A" & subject == 1'), verifying the resulting structure and content. ```R # Create test data X1 <- matrix(1:20, 4, 5) Y1 <- tibble::tibble( condition = rep(c("A", "B"), each=2), subject = rep(1, 4), block = c(1,1,2,2) ) d1 <- multidesign(X1, Y1) X2 <- matrix(21:40, 4, 5) Y2 <- tibble::tibble( condition = rep(c("A", "B"), each=2), subject = rep(2, 4), block = c(1,1,2,2) ) d2 <- multidesign(X2, Y2) hd <- hyperdesign(list(d1, d2)) # Test subsetting by condition subset_A <- subset(hd, condition == "A") expect_s3_class(subset_A, "hyperdesign") expect_true(all(sapply(subset_A, function(x) all(x$design$condition == "A")))) # Test subsetting by multiple conditions subset_A1 <- subset(hd, condition == "A" & subject == 1) expect_true(all(sapply(subset_A1, function(x) { all(x$design$condition == "A" & x$design$subject == 1) }))) ``` -------------------------------- ### R: Define and Use xdata for Data Matrix Extraction Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Defines the S3 generic `xdata` function in R for extracting the primary data matrix from `multidesign` and `hyperdesign` objects. Includes examples demonstrating how to use `xdata` to retrieve all data or data from a specific block within a `hyperdesign` object. ```R xdata <- function(x, ...) UseMethod("xdata") ``` ```R #' d1 <- multidesign(matrix(rnorm(10*5), 10, 5), data.frame(subject=1)) #' d2 <- multidesign(matrix(rnorm(10*5), 10, 5), data.frame(subject=2)) #' hd <- hyperdesign(list(d1, d2)) #' all_data <- xdata(hd) # Returns list of matrices #' block1_data <- xdata(hd, block=1) # Returns just the first block's matrix ``` -------------------------------- ### R `multiframe` Object and Constructor API Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt The `multiframe` object in R is an alternative to `multidesign`, offering enhanced support for data frame operations and lazy evaluation of observations. It integrates well with tidyverse functions and supports various data sources. This entry details its constructor and provides usage examples. ```APIDOC multiframe <- function(x, y, ...) UseMethod("multiframe") - Description: Constructs a new multivariate design object linking vector-valued observations with arbitrary design variables. - Parameters: - x: The multivariate data (a matrix, list, or other data container). - y: A design matrix or data frame with same number of rows/elements as x. - ...: Additional arguments passed to methods. - Returns: A multiframe object containing: - design: A tibble with design variables and observation functions. - Usage Example: # Create sample data X <- matrix(rnorm(20*100), 20, 100) Y <- tibble(condition = rep(letters[1:5], 4)) ``` -------------------------------- ### Extract Block Indices from R multiblock Objects Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This snippet illustrates the `block_indices` function for retrieving the column or row indices corresponding to specific blocks within a `multiblock` object. It provides examples for both column-stacked and row-stacked multiblocks, showing how to get the correct index ranges for each constituent block. ```R X1 <- matrix(1:12, 4, 3) X2 <- matrix(13:24, 4, 3) X3 <- matrix(25:36, 4, 3) mb_c <- multiblock(list(X1, X2, X3)) # ``` -------------------------------- ### API Documentation for R `init_transform.hyperdesign` Method Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Provides the API signature, parameters, and return value for the `init_transform` method specialized for `hyperdesign` objects, used for initializing preprocessing objects. ```APIDOC init_transform.hyperdesign(x, preproc) - x: A hyperdesign object. - preproc: A preprocessing object (e.g., from `multivarious`). Returns: A list of initialized preprocessing objects, one for each block. Family: hyperdesign functions ``` -------------------------------- ### R Implementation: Initialize Data Transformation for Hyperdesign Object Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt R code defining the `init_transform.hyperdesign` method, which applies a fresh preprocessor to each block of a hyperdesign object and re-structures the output. ```R init_transform.hyperdesign <- function(x, preproc) { ## pre-processors proclist <- lapply(seq_along(x), function(i) { multivarious:::fresh(preproc) %>% prep() }) names(proclist) <- names(x) ## subject-split and pre-processed data out <- lapply(seq_along(proclist), function(i) { p <- proclist[[i]] Xi <- x[[i]]$x Xout <- multivarious::init_transform(p, Xi) multidesign(Xout, x[[i]]$design) }) des <- hyperdesign(out) attr(des, "preproc") <- proclist des } ``` -------------------------------- ### R Markdown knitr Configuration for README Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This R Markdown chunk configures `knitr` options for generating the `README.md` file from `README.Rmd`. It sets options for collapsing code, adding comments, defining figure paths, and setting output width, ensuring consistent formatting for documentation generation. ```R knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) ``` -------------------------------- ### R hyperdesign Constructor Function Test Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This test suite verifies the correct initialization and structure of 'hyperdesign' objects in R. It demonstrates how to create 'multidesign' objects, combine them into a 'hyperdesign' object, and then asserts properties like class, length, common variables, and the extraction of design and column design attributes. ```R library(tibble) test_that("hyperdesign constructor works correctly", { # Create test multidesign objects X1 <- matrix(rnorm(50), 10, 5) Y1 <- tibble::tibble( condition = rep(c("A", "B"), each=5), subject = rep(1, 10), run = 1:10 ) col_design1 <- tibble::tibble( type = letters[1:5], group = rep(c("g1", "g2"), length.out=5) ) d1 <- multidesign(X1, Y1, col_design1) X2 <- matrix(rnorm(50), 10, 5) Y2 <- tibble::tibble( condition = rep(c("A", "B"), each=5), subject = rep(2, 10), run = 1:10 ) d2 <- multidesign(X2, Y2, col_design1) # Use the same column design # Create hyperdesign hd <- hyperdesign(list(d1, d2)) # Test basic structure expect_s3_class(hd, "hyperdesign") expect_equal(length(hd), 2) expect_equal(attr(hd, "common_vars"), c("condition", "subject", "run")) # Test design extraction all_designs <- design(hd) expect_length(all_designs, 2) expect_equal(sort(names(all_designs[[1]])), sort(c(names(Y1)))) # Test column_design extraction all_col_designs <- column_design(hd) expect_length(all_col_designs, 2) expect_equal(names(all_col_designs[[1]]), c("type", "group")) block1_col_design <- column_design(hd, block=1) expect_equal(names(block1_col_design), c("type", "group")) expect_equal(block1_col_design$type, letters[1:5]) }) ``` -------------------------------- ### multidesign R Package Directory Structure Source: https://github.com/bbuchsbaum/multidesign/blob/master/CLAUDE.md Illustrates the standard directory layout for the `multidesign` R package, including source code, documentation, tests, and metadata files. ```text multidesign/ ├── DESCRIPTION # Package metadata and dependencies ├── NAMESPACE # Exported functions and imports (auto-generated) ├── LICENSE # MIT license ├── README.md # Package overview ├── _pkgdown.yml # Documentation website config ├── .Rbuildignore # Files to ignore during R package build ├── multidesign.Rproj # RStudio project file ├── R/ # Main source code │ ├── all_generic.R # Generic function definitions │ ├── multidesign.R # multidesign class implementation │ ├── hyperdesign.R # hyperdesign class implementation │ ├── multiframe.R # multiframe class implementation │ └── multiblock.R # multiblock class implementation ├── man/ # Documentation files (auto-generated by roxygen2) ├── tests/ # Unit tests │ ├── testthat.R # Test runner │ └── testthat/ # Test files │ ├── test-multidesign.R │ ├── test-hyperdesign.R │ ├── test-multiframe.R │ └── test-multiblock.R └── vignettes/ # Package vignettes └── Introduction.Rmd ``` -------------------------------- ### is_rstacked Function API Reference (R) Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt API reference for the `is_rstacked` function in R, which checks if a `multiblock` object is row-stacked. This means all component matrices share the same number of columns. Includes parameter details, return value, and usage examples. ```APIDOC is_rstacked <- function(x) UseMethod("is_rstacked") Description: Checks if a multiblock object is row-stacked, meaning that all component matrices share the same number of columns. In row-stacked multiblock objects, blocks are arranged one above another, with each block potentially having a different number of rows. Parameters: x: The multiblock object to test Returns: Logical value: TRUE if the object is row-stacked, FALSE otherwise Examples: # Create row-stacked multiblock (matrices share column dimension) Y1 <- matrix(rnorm(10*5), 10, 5) Y2 <- matrix(rnorm(15*5), 15, 5) mb <- multiblock(list(Y1, Y2)) # Test stacking orientation is_rstacked(mb) # Returns TRUE is_cstacked(mb) # Returns FALSE See Also: is_cstacked: for testing if a multiblock object is column-stacked multiblock: for creating multiblock objects ``` -------------------------------- ### Create 'observation_set' Objects in R Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Illustrates the creation of 'observation_set' objects from both matrix and list inputs. Shows how to handle custom indices and includes tests for various error conditions during creation. ```R # Test matrix input X_mat <- matrix(1:20, 5, 4) obs_mat <- obs_group(X_mat) expect_s3_class(obs_mat, "observation_set") expect_length(obs_mat, 5) expect_equal(as.vector(obs_mat[[1]]), as.vector(X_mat[1,])) # Compare as vectors # Test list input X_list <- list(a=1:4, b=5:8, c=9:12) obs_list <- obs_group(X_list) expect_s3_class(obs_list, "observation_set") expect_length(obs_list, 3) expect_equal(obs_list[[1]], X_list[[1]]) # Test custom indices ind <- c(10, 20, 30) obs_ind <- obs_group(X_list, ind=ind) expect_length(obs_ind, 3) # Test error conditions expect_error(obs_group(list()), "must not be empty") expect_error(obs_group(X_list, ind=1:4), "must be equal to") ``` -------------------------------- ### is_cstacked Function API Reference (R) Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt API reference for the `is_cstacked` function in R, which checks if a `multiblock` object is column-stacked. This means all component matrices share the same number of rows. Includes parameter details, return value, and usage examples. ```APIDOC is_cstacked <- function(x) UseMethod("is_cstacked") Description: Checks if a multiblock object is column-stacked, meaning that all component matrices share the same number of rows. In column-stacked multiblock objects, blocks are arranged side by side, with each block potentially having a different number of columns. Parameters: x: The multiblock object to test Returns: Logical value: TRUE if the object is column-stacked, FALSE otherwise Examples: # Create column-stacked multiblock (matrices share row dimension) X1 <- matrix(rnorm(20*3), 20, 3) X2 <- matrix(rnorm(20*5), 20, 5) mb <- multiblock(list(X1, X2)) # Test stacking orientation is_cstacked(mb) # Returns TRUE is_rstacked(mb) # Returns FALSE See Also: is_rstacked: for testing if a multiblock object is row-stacked multiblock: for creating multiblock objects ``` -------------------------------- ### R Package Development Commands with devtools Source: https://github.com/bbuchsbaum/multidesign/blob/master/CLAUDE.md Essential R commands for developing, testing, documenting, and building the `multidesign` package using the `devtools` and `pkgdown` libraries. ```R # Install and load development tools library(devtools) # Load package for development load_all() # Generate documentation document() # Run tests test() # Check package check() # Install package install() # Build package build() # Generate website pkgdown::build_site() ``` -------------------------------- ### R Function: block_indices - Get Block Indices (Re-export) Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This function is a re-export of the `block_indices` function from the `multivarious` package. It retrieves the indices that define the boundaries of blocks in a multiblock or hyperdesign object. Refer to the `multivarious` package documentation for full details. ```APIDOC block_indices(x, ...) - Re-exports `block_indices` from the `multivarious` package. - Parameters: - x: The object to get block indices from - ...: Additional arguments passed to methods - Returns: A matrix with start and end indices for each block - See `multivarious::block_indices` for full documentation. ``` -------------------------------- ### Create and Validate 'multidesign' Objects in R Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Demonstrates the creation of 'multidesign' objects from a data matrix (X) and a design tibble (Y), optionally including column-wise metadata. Includes tests for basic creation, column design integration, and error handling for dimension mismatches. ```R # Create test data X <- matrix(1:20, 5, 4) Y <- tibble( condition = rep(c("A", "B"), c(2, 3)), subject = 1:5 ) col_info <- tibble( region = paste0("roi_", 1:4), type = rep(c("cortical", "subcortical"), 2) ) # Test basic creation md <- multidesign(X, Y) expect_s3_class(md, "multidesign") expect_equal(dim(md$x), c(5, 4)) expect_equal(nrow(md$design), 5) expect_true(!is.null(md$column_design)) # Test with column design md_col <- multidesign(X, Y, col_info) expect_equal(md_col$column_design, col_info) # Test error conditions expect_error( multidesign(X[1:3,], Y), "`nrow\\(x\\)` must be equal to 5L" ) expect_error( multidesign(X, Y, col_info[1:2,]), "`ncol\\(x\\)` must be equal to 2L" ) ``` -------------------------------- ### Handle Confounded Variables in R hyperdesign with fold_over Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This snippet demonstrates how the `fold_over` function in the `hyperdesign` R package identifies and handles variables that are confounded with experimental blocks. It shows an example where 'group' is confounded, leading to an error, and 'value' is not, allowing successful execution. ```R X1 <- matrix(rnorm(20), 4, 5) Y1 <- tibble( group = c("A", "A", "A", "A"), # Block 1 only has group A value = 1:4 ) X2 <- matrix(rnorm(20), 4, 5) Y2 <- tibble( group = c("B", "B", "B", "B"), # Block 2 only has group B value = 5:8 ) md1 <- multidesign(X1, Y1) md2 <- multidesign(X2, Y2) hd <- hyperdesign(list(md1, md2)) # Test error for confounded variable 'group' expect_error( fold_over(hd, group), "Variable 'group' is confounded with blocks" ) # Test that non-confounded variable 'value' works expect_no_error(fold_over(hd, value)) ``` -------------------------------- ### Create R multiblock Objects with Column or Row Stacking Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This R code demonstrates the creation of `multiblock` objects, distinguishing between column-stacked (`multiblock_c`) and row-stacked (`multiblock_r`) orientations. It verifies the class and orientation attributes of the created objects, showing how `multiblock` automatically infers the stacking method based on input matrix dimensions. ```R # Test column-stacked multiblock (same number of rows) X1 <- matrix(1:12, 4, 3) X2 <- matrix(13:24, 4, 3) X3 <- matrix(25:36, 4, 3) mb_c <- multiblock(list(X1, X2, X3)) expect_s3_class(mb_c, "multiblock") expect_s3_class(mb_c, "multiblock_c") expect_equal(attr(mb_c, "orient"), "cstacked") expect_equal(dim(attr(mb_c, "ind")), c(3, 2)) # 3 blocks, start/end indices # Test row-stacked multiblock (same number of columns) Y1 <- matrix(1:10, 2, 5) Y2 <- matrix(11:25, 3, 5) Y3 <- matrix(26:35, 2, 5) mb_r <- multiblock(list(Y1, Y2, Y3)) expect_s3_class(mb_r, "multiblock") expect_s3_class(mb_r, "multiblock_r") expect_equal(attr(mb_r, "orient"), "rstacked") expect_equal(dim(attr(mb_r, "ind")), c(3, 2)) # 3 blocks, start/end indices ``` -------------------------------- ### Extract Design Information from Hyperdesign Object (R) Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This Roxygen2 documentation describes the 'extract_design_info' function, which retrieves design information from a 'hyperdesign' object. Users can specify an optional block index to get design details for a particular block or omit it to retrieve information for all blocks. ```APIDOC Function: extract_design_info Description: Retrieves design information from a hyperdesign object, either for all blocks or for a specific block. Parameters: x: A hyperdesign object block: Optional numeric index specifying which block's design to return ``` -------------------------------- ### Basic Usage of multidesign R Package Source: https://github.com/bbuchsbaum/multidesign/blob/master/CLAUDE.md Demonstrates how to create a `multidesign` object, split data by condition, generate cross-validation folds, and perform group-wise summarization using `multidesign` functions. ```R library(multidesign) library(tibble) # Create sample data X <- matrix(rnorm(20*100), 20, 100) Y <- tibble( condition = rep(c("control", "treatment"), each=10), subject = rep(1:5, times=4) ) # Create multidesign object mds <- multidesign(X, Y) # Split by condition split_data <- split(mds, condition) # Create cross-validation folds cv_folds <- fold_over(mds, condition) # Summarize by condition condition_means <- summarize_by(mds, colMeans, condition) ``` -------------------------------- ### R Internal Function: Calculate Block Index Matrix Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt An internal helper function used within the 'multidesign' package to compute the start and end indices for blocks, either by rows or columns, from a list of matrices. This is a foundational utility for managing multiblock data structures. ```R block_index_mat2 <- function(x, byrow=FALSE) { lens <- if (byrow) { sapply(x, function(z) nrow(z)) } else { sapply(x, function(z) ncol(z)) } csum <- cumsum(lens) csum1 <- c(0, csum[-length(csum)]) m <- as.matrix(cbind(csum1+1, csum)) colnames(m) <- c("start", "end") m } ``` -------------------------------- ### APIDOC: R xdata Function Reference Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Comprehensive API documentation for the R `xdata` S3 generic function, detailing its purpose, behavior with `multidesign` and `hyperdesign` objects, parameters, return values, and related functions for extracting data matrices. ```APIDOC xdata(x, ...) Description: Retrieves the primary data matrix (X) associated with observations in various object types. This function provides a consistent interface for accessing the observed data regardless of the specific object structure. Details: * For multidesign objects: Returns the data matrix component * For hyperdesign objects: Returns a list of data matrices, one for each block (or a single matrix if a specific block is requested) Parameters: * x: The object containing data (e.g., multidesign, hyperdesign). * ...: Additional arguments passed to methods: * For hyperdesign objects: 'block' parameter to specify which block's data to return Returns: The data component of the object (typically a matrix), or a list of matrices for hyperdesign objects. See Also: design, column_design ``` -------------------------------- ### API Documentation for R `fold_over.hyperdesign` Method Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Details the API for creating cross-validation folds from a `hyperdesign` object, including parameters for splitting variables, inclusion/exclusion conditions, and important considerations for data structure. ```APIDOC fold_over.hyperdesign(x, ..., inclusion_condition = list(), exclusion_condition = list()) - x: A hyperdesign object. - ...: Unquoted names of variables to split on (e.g., condition, subject, run). - inclusion_condition: Optional list specifying values to include in assessment sets. - exclusion_condition: Optional list specifying values to exclude from assessment sets. Details: The function creates folds by splitting the data based on unique combinations of the specified variables. For each fold, one combination is held out as the assessment set, while the rest form the analysis set. Important considerations: * If a splitting variable is confounded with blocks (e.g., each subject is in a separate block), the function will fail as there would be no training data available for that block. * Numeric variables (like run numbers) are handled by converting them to factors for splitting. * The function preserves the design structure within each fold. Returns: A foldlist object containing the cross-validation folds. ``` -------------------------------- ### R: Define and Use column_design for Column Metadata Extraction Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Defines the S3 generic `column_design` function in R for extracting column-level metadata from `multidesign` and `hyperdesign` objects. Includes examples demonstrating how to use `column_design` to retrieve all column design information or column design from a specific block. ```R column_design <- function(x, ...) UseMethod("column_design") ``` ```R # With a multidesign object including column metadata X <- matrix(rnorm(20*10), 20, 10) Y <- data.frame(condition = rep(c("A", "B"), each=10)) col_info <- data.frame( feature = paste0("var", 1:10), type = rep(c("continuous", "categorical"), 5) ) mds <- multidesign(X, Y, col_info) col_metadata <- column_design(mds) # With a hyperdesign object d1 <- multidesign(matrix(rnorm(10*5), 10, 5), data.frame(condition=rep(c("A","B"), 5)), data.frame(feature=paste0("var", 1:5))) d2 <- multidesign(matrix(rnorm(10*5), 10, 5), data.frame(condition=rep(c("A","B"), 5)), data.frame(feature=paste0("var", 1:5))) hd <- hyperdesign(list(d1, d2)) all_col_designs <- column_design(hd) block1_col_design <- column_design(hd, block=1) ``` -------------------------------- ### APIDOC: R design Function Reference Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Comprehensive API documentation for the R `design` S3 generic function, detailing its purpose, behavior with `multidesign`, `hyperdesign`, and `multiframe` objects, parameters, return values, and related functions for extracting observation metadata. ```APIDOC design(x, ...) Description: Retrieves the design information (experimental metadata) associated with observations in various object types. This function provides a consistent interface for accessing design variables regardless of the specific object structure. Details: * For multidesign objects: Returns the design data frame component * For hyperdesign objects: Returns a list of design data frames, one for each block (or a single design if a specific block is requested) * For multiframe objects: Returns the design tibble with observation functions Design information typically includes experimental factors, conditions, subject IDs, or other metadata associated with each observation. Parameters: * x: The object containing design information * ...: Additional arguments passed to methods: * For hyperdesign objects: 'block' parameter to specify which block's design to return Returns: The design component of the object (typically a data frame or tibble), or a list of designs for hyperdesign objects See Also: xdata, column_design ``` -------------------------------- ### Create Multidesign Object (R APIDOC) Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt Documentation for creating a 'multidesign' object, which combines experimental data (matrix) with design information (data frame) and optional column metadata. This structure is designed for experimental designs with multiple factors and variable metadata, maintaining relationships between components for manipulation and analysis. ```APIDOC multidesign(x: numeric matrix, y: data.frame, column_design: data.frame = NULL) - Creates a multidesign object combining experimental data, design information, and optional column metadata. - Parameters: - x: A numeric matrix where rows are observations and columns are variables. - y: A data frame containing design variables for each observation (must have same number of rows as x). - column_design: Optional data frame containing metadata for columns in x (must have same number of rows as ncol(x)). - Returns: A multidesign object with components: - x: The input data matrix - design: A tibble containing design variables with an added .index column - column_design: A tibble containing column metadata (empty if not provided) - Example: X <- matrix(rnorm(20*100), 20, 100) ``` -------------------------------- ### Get Column Design Information for Hyperdesign Object in R Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This R method extracts column design information from a `hyperdesign` object. It can retrieve information for all blocks or a specific block if an index is provided. This is useful for understanding the structure of the experimental design within each block, such as variable names and types. ```R column_design.hyperdesign <- function(x, block, ...) { if (missing(block)) { lapply(x, column_design) } else { chk::vld_number(block) chk::chk_range(block, c(1, length(x))) column_design(x[[block]]) } } ``` ```APIDOC column_design.hyperdesign(x, block, ...) - x: A hyperdesign object. - block: Optional block index or name to get design for a specific block. - ...: Additional arguments passed to methods. - Returns: A list of column design information for each block. ``` -------------------------------- ### Print Method for Multidesign Objects in R Source: https://github.com/bbuchsbaum/multidesign/blob/master/repomix-output.txt This S3 method provides a detailed summary display for "multidesign" objects, including information about data dimensions, design variables, and column metadata if available. It invisibly returns the input object, allowing for chaining operations. ```APIDOC print.multidesign(x, ...) Description: Displays a detailed summary of a multidesign object, including data dimensions, design variables, and column metadata if present. Parameters: x: A multidesign object ...: Additional arguments passed to print methods Returns: Invisibly returns the input object ``` ```R print.multidesign <- function(x, ...) { # Function body not provided in the input text. } ```