### Install OmicsPLS Development Version Source: https://github.com/selbouhaddani/omicspls/blob/master/README.md Install the latest development version of OmicsPLS directly from GitHub using the devtools package. This may include newer bug fixes. ```r require(devtools) devtools::install_github("selbouhaddani/OmicsPLS") ``` -------------------------------- ### Install OmicsPLS Package Source: https://github.com/selbouhaddani/omicspls/blob/master/README.md Use this command to install the OmicsPLS package from CRAN. Ensure you type the quotation marks yourself if copy-pasting causes issues. Required packages are ggplot2 and parallel. ```r install.packages("OmicsPLS") ``` -------------------------------- ### Load OmicsPLS Package Source: https://github.com/selbouhaddani/omicspls/blob/master/README.md Load the OmicsPLS package into your R session after installation to access its functions. ```r library(OmicsPLS) ``` -------------------------------- ### Visualize Correlation Heatmap of X and Y Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Creates a heatmap of the correlation matrix between X and Y datasets using `gplots::heatmap.2`. This visualization helps in understanding the relationships between variables in the two datasets. The `try` block ensures that the code runs without stopping the script if `gplots` is not installed or if there are issues with the heatmap generation. ```R try( gplots::heatmap.2(cor(X,Y), Rowv=F,Colv=F, col=gplots::bluered(100), symm = TRUE, trace="none", dendrogram="none"), silent = TRUE) ``` -------------------------------- ### Get Citation for OmicsPLS Package Source: https://github.com/selbouhaddani/omicspls/blob/master/README.md Retrieve the citation information for the OmicsPLS R package to properly cite it in your research. This command displays the recommended citation format. ```r citation("OmicsPLS") ``` -------------------------------- ### Fit Sparse O2PLS (SO2PLS) Source: https://context7.com/selbouhaddani/omicspls/llms.txt Enable Sparse O2PLS by setting `sparse = TRUE`. Use `keepx` and `keepy` to specify the number of variables to retain per joint component for X and Y, respectively, facilitating variable selection. ```r # --- Sparse O2PLS: keep 10 X-variables and 8 Y-variables per joint component --- fit_sparse <- o2m(X, Y, n = 2, nx = 1, ny = 1, sparse = TRUE, keepx = 10, keepy = 8) ``` -------------------------------- ### Fit Group Sparse O2PLS (GO2PLS) Source: https://context7.com/selbouhaddani/omicspls/llms.txt Implement Group Sparse O2PLS by setting `sparse = TRUE` and providing `groupx` and `groupy` vectors to define variable groupings. Use `keepx` and `keepy` to specify the number of groups to retain per joint component. ```r # --- Group Sparse O2PLS: keep 3 X-groups and 2 Y-groups per component --- groupx <- rep(paste0("grp", 1:10), each = 5) # 10 groups of 5 X-variables groupy <- rep(paste0("grp", 1:8), each = 5) # 8 groups of 5 Y-variables fit_go2pls <- o2m(X, Y, n = 2, nx = 1, ny = 1, sparse = TRUE, groupx = groupx, groupy = groupy, keepx = 3, keepy = 2) ``` -------------------------------- ### Variance Decomposition Summary with `summary.o2m` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Provides a human-readable summary of a fitted O2PLS model, detailing proportions of variance explained by joint, orthogonal, and noise components, per-component variances, and inner-relation regression coefficients. ```r library(OmicsPLS) X <- scale(matrix(rnorm(100 * 20), 100, 20)) Y <- scale(matrix(rnorm(100 * 15), 100, 15)) fit <- o2m(X, Y, n = 2, nx = 1, ny = 0) summary(fit) # *** Summary of the O2PLS fit *** # # - Call: o2m(X = X, Y = Y, n = 2, nx = 1, ny = 0) # # - Modeled variation # -- Total variation: # in X: ... # in Y: ... # # -- Joint, Orthogonal and Noise as proportions: # # data X data Y # Joint 0.xxx 0.xxx # Orthogonal 0.xxx 0.000 # Noise 0.xxx 0.xxx # # -- Predictable variation in Y-joint part by X-joint part: # Variation in T*B_T relative to U: 0.xxx # ... ``` -------------------------------- ### Summarize O2PLS Fit Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Generate a summary of the fitted O2PLS model. This provides details on modeled variation, joint/orthogonal/noise proportions, and component variances. ```R summary(fit0) ``` -------------------------------- ### Matrix Utility Functions: `ssq`, `mse`, `vnorm` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Provides utility functions for matrix operations: `ssq` for sum of squares (Frobenius norm squared), `mse` for mean squared difference between matrices, and `vnorm` for Euclidean norm of matrix columns. These are useful for custom workflows and verifying results. ```R library(OmicsPLS) X <- matrix(1:9, 3, 3) # Sum of squares (squared Frobenius norm) ssq(X) # 285 # Mean squared difference between two matrices A <- matrix(rnorm(500), 100, 5) B <- matrix(rnorm(500), 100, 5) mse(A, B) # scalar # Column-wise Euclidean norms vnorm(X) # vector of length 3 # [1] 3.741657 8.774964 13.928388 # Verify orthonormality: norms should all be 1 M_orth <- orth(matrix(rnorm(500), 100, 5)) round(vnorm(M_orth), 6) # 1 1 1 1 1 ``` -------------------------------- ### Cross-Validation for Component Selection Source: https://context7.com/selbouhaddani/omicspls/llms.txt Use `crossval_o2m` to perform k-fold cross-validation for selecting the optimal number of components (`n`, `nx`, `ny`). It searches over a grid of candidate values and returns the combination minimizing prediction error. ```r library(OmicsPLS) set.seed(99) X <- scale(jitter(tcrossprod(rnorm(100), runif(10)))) # 100×10 Y <- scale(jitter(tcrossprod(rnorm(100), runif(10)))) # 100×10 # Search over a=(1,2,3), ax=(0,1,2), ay=(0,1,2) with 5-fold CV cv_result <- crossval_o2m(X, Y, a = 1:3, ax = 0:2, ay = 0:2, nr_folds = 5, nr_cores = 1, seed = 42) cv_result # ******************* # Elapsed time: ... # ******* # Minimal 5-CV error is at a=1 ax=0 ay=0 # ******* # Minimum MSE is ... # ******************* # Access the full 3-d array of errors cv_result$Sorted # array sorted by decreasing dimension sizes cv_result$Original # original ordering ``` -------------------------------- ### Fit Stripped O2PLS Model Source: https://context7.com/selbouhaddani/omicspls/llms.txt Use `o2m` with `stripped = TRUE` for a lighter output, which is faster and more memory-efficient, making it suitable for cross-validation loops where intermediate matrices are not needed. ```r # --- Stripped version (fewer stored matrices, faster for CV) --- fit_stripped <- o2m(X, Y, n = 2, nx = 1, ny = 1, stripped = TRUE) ``` -------------------------------- ### Fast Adjusted-R² Cross-Validation with `crossval_o2m_adjR2` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Uses a faster CV strategy to find the optimal (nx, ny) pair for a given n by maximizing R² between joint scores. Recommended for efficiency when results are comparable to full grid search. ```r library(OmicsPLS) set.seed(99) X <- scale(jitter(tcrossprod(rnorm(100), runif(10)))) Y <- scale(jitter(tcrossprod(rnorm(100), runif(10)))) cv_adj <- crossval_o2m_adjR2(X, Y, a = 1:4, ax = 0:2, ay = 0:2, nr_folds = 5, nr_cores = 1) # Minimum is at n = 1 # Elapsed time: ... sec # Returns a data.frame with columns: MSE, n, nx, ny print(cv_adj) # MSE n nx ny # 1 ... 1 0 0 # 2 ... 2 0 1 # ... best_n <- cv_adj$n[which.min(cv_adj$MSE)] best_nx <- cv_adj$nx[which.min(cv_adj$MSE)] best_ny <- cv_adj$ny[which.min(cv_adj$MSE)] fit <- o2m(X, Y, n = best_n, nx = best_nx, ny = best_ny) ``` -------------------------------- ### Cross-Validation for Sparsity Tuning with `crossval_sparsity` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Tunes sparsity for SO2PLS/GO2PLS by selecting the number of variables to retain in joint components using k-fold CV. Evaluates covariance between joint scores over a grid of `(keepx_seq, keepy_seq)` and applies the 1-standard-error rule. ```r library(OmicsPLS) set.seed(42) X <- scale(matrix(rnorm(80 * 100), 80, 100)) Y <- scale(matrix(rnorm(80 * 80), 80, 80)) # SO2PLS sparsity CV: how many variables to keep from X and Y cv_sp <- crossval_sparsity(X, Y, n = 2, nx = 1, ny = 1, nr_folds = 5, keepx_seq = c(5, 10, 20, 40), keepy_seq = c(5, 10, 20)) # Best settings (max covariance & 1-SD rule) cv_sp$Best # x1 y1 x_1sd1 y_1sd1 (for component 1) # x2 y2 x_1sd2 y_1sd2 (for component 2) # Visualize CV results plot_crossval_sparsity(cv_sp) # Fit the sparse model using recommended keepx / keepy fit_sp <- o2m(X, Y, n = 2, nx = 1, ny = 1, sparse = TRUE, keepx = cv_sp$Best["x1"], keepy = cv_sp$Best["y1"]) ``` -------------------------------- ### Plotting Loading Vectors with `plot.o2m` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Generates ggplot2 scatter plots for O2PLS loading vectors, including joint and orthogonal loadings, and group-level loadings for GO2PLS. Supports plotting individual loadings or biplots, with options for labeling by variable index or column names. ```r library(OmicsPLS) X <- scale(matrix(rnorm(100 * 30), 100, 30)) Y <- scale(matrix(rnorm(100 * 25), 100, 25)) colnames(X) <- paste0("x", 1:30) colnames(Y) <- paste0("y", 1:25) fit <- o2m(X, Y, n = 2, nx = 1, ny = 1) # Plot first joint X loading (index vs. value) plot(fit, loading_name = "Xjoint", i = 1) # Biplot of joint X loadings: component 1 vs component 2 plot(fit, loading_name = "Xjoint", i = 1, j = 2, label = "colnames", size = 3) # Plot first joint Y loading plot(fit, loading_name = "Yjoint", i = 1) # Plot X-orthogonal loading (component 1) plot(fit, loading_name = "Xorth", i = 1) ``` -------------------------------- ### Fit High-Dimensional O2PLS Model Source: https://context7.com/selbouhaddani/omicspls/llms.txt Explicitly trigger the high-dimensional mode in `o2m` by lowering `p_thresh` and `q_thresh` below the dataset dimensions. This ensures the memory-efficient NIPALS approach is used. ```r # --- High-dimensional mode triggered explicitly (threshold lowered for demo) --- fit_highd <- o2m(X, Y, n = 2, nx = 1, ny = 1, p_thresh = 10, q_thresh = 10) ``` -------------------------------- ### Matrix Orthogonalization with `orth` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Returns an orthonormalized version of a numeric matrix or vector using QR or SVD decomposition. Useful for constructing orthonormal bases or pre-processing loading matrices. ```R library(OmicsPLS) # Normalize a vector to unit length v <- c(3, 4) orth(v) # [1] 0.6 0.8 (unit vector) # Orthonormalize columns of a random matrix M <- matrix(rnorm(500), 100, 5) M_orth <- orth(M) round(crossprod(M_orth), 4) # Should be identity matrix (5×5) # Using SVD decomposition M_orth_svd <- orth(M, type = "SVD") round(crossprod(M_orth_svd), 4) ``` -------------------------------- ### crossval_o2m — Standard k-fold cross-validation for component selection Source: https://context7.com/selbouhaddani/omicspls/llms.txt Performs k-fold cross-validation to evaluate prediction error over a grid of candidate component numbers (n, nx, ny). Supports parallelization and returns a `cvo2m` object with methods for reporting the optimal component combination. ```APIDOC ## crossval_o2m — Standard k-fold cross-validation for component selection ### Description Evaluates prediction error using k-fold cross-validation over a specified grid of candidate component numbers (`n`, `nx`, `ny`). The prediction error is the sum of RMSEP for X and Y. Supports parallelization and returns a `cvo2m` object that provides methods for reporting the minimizing combination of components and accessing error arrays. ### Parameters - **X** (matrix) - The first dataset (N subjects, p variables). - **Y** (matrix) - The second dataset (N subjects, q variables). - **a** (vector) - Candidate values for the number of joint components (`n`). - **ax** (vector) - Candidate values for the number of X-specific orthogonal components (`nx`). - **ay** (vector) - Candidate values for the number of Y-specific orthogonal components (`ny`). - **nr_folds** (integer) - Number of folds for cross-validation (default 5). - **nr_cores** (integer) - Number of cores to use for parallelization (default 1). - **seed** (integer) - Seed for random number generation to ensure reproducibility. ### Return Value A `cvo2m` object containing: - **Sorted**: A 3-D array of cross-validation errors, sorted by decreasing dimension sizes. - **Original**: A 3-D array of cross-validation errors, in the original ordering of candidate values. ### Request Example ```r library(OmicsPLS) set.seed(99) X <- scale(jitter(tcrossprod(rnorm(100), runif(10)))) Y <- scale(jitter(tcrossprod(rnorm(100), runif(10)))) # Perform cross-validation searching over n=(1,2,3), nx=(0,1,2), ny=(0,1,2) cv_result <- crossval_o2m(X, Y, a = 1:3, ax = 0:2, ay = 0:2, nr_folds = 5, nr_cores = 1, seed = 42) # Print the result to see the minimal error combination cv_result # Access the error arrays cv_result$Sorted cv_result$Original ``` ``` -------------------------------- ### ssq, mse, vnorm Source: https://context7.com/selbouhaddani/omicspls/llms.txt Provides utility functions for matrix operations: `ssq` computes the sum of squared elements (Frobenius norm squared), `mse` computes the mean squared difference between two objects, and `vnorm` computes the Euclidean norm of each column of a matrix. These are useful for custom workflows. ```APIDOC ## ssq / mse / vnorm ### Description `ssq` computes the sum of squared elements (Frobenius norm squared) of a matrix or vector. `mse` computes the mean squared difference between two objects. `vnorm` computes the Euclidean norm of each column of a matrix. These are used throughout the package and are available for custom workflows. ### Usage ```r ssq(mat) mse(obj1, obj2) vnorm(mat) ``` ### Parameters * `mat`: A numeric matrix or vector. * `obj1`, `obj2`: Numeric objects (matrices or vectors) for calculating mean squared difference. ### Returns * `ssq`: A single numeric value (sum of squares). * `mse`: A single numeric value (mean squared error). * `vnorm`: A numeric vector containing the Euclidean norm of each column of the input matrix. ``` -------------------------------- ### o2m — Fit an O2PLS model Source: https://context7.com/selbouhaddani/omicspls/llms.txt The primary fitting function for O2PLS models. It decomposes datasets X and Y into joint, X-specific, and Y-specific components. Supports standard, stripped, high-dimensional, sparse, and group sparse variants. ```APIDOC ## o2m — Fit an O2PLS model ### Description Fits an O2PLS model decomposing X (N×p) and Y (N×q) into joint components (`n`), X-specific orthogonal components (`nx`), and Y-specific orthogonal components (`ny`). Automatically switches to a memory-efficient NIPALS approach for high-dimensional data. Supports stripped output for cross-validation and sparse variants (SO2PLS, GO2PLS) for variable selection. ### Parameters - **X** (matrix) - The first dataset (N subjects, p variables). - **Y** (matrix) - The second dataset (N subjects, q variables). - **n** (integer) - Number of joint components. - **nx** (integer) - Number of X-specific orthogonal components. - **ny** (integer) - Number of Y-specific orthogonal components. - **stripped** (boolean) - If TRUE, returns a lighter output suitable for cross-validation. - **sparse** (boolean) - If TRUE, enables SO2PLS or GO2PLS with variable-selection penalties. - **p_thresh** (integer) - Dimensionality threshold for triggering NIPALS in X (default 3000). - **q_thresh** (integer) - Dimensionality threshold for triggering NIPALS in Y (default 3000). - **keepx** (integer) - Number of X-variables to keep in sparse variants. - **keepy** (integer) - Number of Y-variables to keep in sparse variants. - **groupx** (vector) - Grouping variable for X-variables in GO2PLS. - **groupy** (vector) - Grouping variable for Y-variables in GO2PLS. ### Return Value An O2PLS fit object containing selected fields such as: - **Tt**: N×n joint X scores - **W.**: p×n joint X loadings - **U**: N×n joint Y scores - **C.**: q×n joint Y loadings - **T_Yosc**: N×nx X-orthogonal scores - **U_Xosc**: N×ny Y-orthogonal scores - **R2X**: Proportion of X variation modeled - **R2Y**: Proportion of Y variation modeled - **R2Xcorr**: Proportion of X variation in joint part - **R2Ycorr**: Proportion of Y variation in joint part ### Request Example ```r library(OmicsPLS) set.seed(42) X <- scale(matrix(rnorm(100 * 50), 100, 50)) Y <- scale(matrix(rnorm(100 * 40), 100, 40)) # Standard O2PLS fit fit <- o2m(X, Y, n = 2, nx = 1, ny = 1) # Sparse O2PLS fit fit_sparse <- o2m(X, Y, n = 2, nx = 1, ny = 1, sparse = TRUE, keepx = 10, keepy = 8) ``` ``` -------------------------------- ### Extracting Loading Matrices with `loadings.o2m` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Extracts one of the six loading matrices from a fitted O2PLS model. Optionally sorts rows by the absolute magnitude of the first loading column to help identify influential variables. ```r library(OmicsPLS) X <- scale(matrix(rnorm(100 * 20), 100, 20)) Y <- scale(matrix(rnorm(100 * 15), 100, 15)) fit <- o2m(X, Y, n = 2, nx = 1, ny = 1) # Joint X loadings (all components) W <- loadings(fit, loading_name = "Xjoint") dim(W) # 20 × 2 # Joint Y loadings, sorted by absolute value of component 1 C_sorted <- loadings(fit, loading_name = "Yjoint", sorted = TRUE) ``` -------------------------------- ### Full cross-validation for O2PLS model Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Performs a 10-fold cross-validation to find the minimal Mean Squared Error (MSE) for an O2PLS model. This method helps in selecting the optimal number of components (n, nx, ny) by minimizing prediction error. ```R crossval_o2m(X, Y, 1:3, 0:3, 0:3, nr_folds = 10) ``` -------------------------------- ### Plotting X-specific loadings in OmicsPLS Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Visualize the X-specific loadings of a fitted OmicsPLS model. This plot helps identify which variables in the X matrix contribute most to the latent components. Use this to understand variable importance. ```R plot(fit0, "Xo") ``` -------------------------------- ### Plot O2PLS Fit Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Visualize the results of the O2PLS fit. This typically includes plotting joint loadings to identify variables contributing to the shared variation between datasets. ```R plot(fit0) ``` -------------------------------- ### Cross-validation for O2PLS model components Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Determines the optimal number of components for an O2PLS model using adjusted R-squared. Requires the OmicsPLS package and pre-defined X and Y matrices. Set a seed for reproducibility. ```R library(OmicsPLS) set.seed(1221L) crossval_o2m_adjR2(X, Y, 1:3, 0:3, 0:3, nr_folds = 2) ``` -------------------------------- ### Impute Missing Values with `impute_matrix` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Imputes missing values (NA) in a numeric matrix using low-rank SVD imputation via the `softImpute` package. This is a preprocessing step required before using `o2m` as it does not accept matrices with NA or Inf values. ```R library(OmicsPLS) set.seed(1) X <- matrix(rnorm(50 * 100), 50, 100) # Introduce 10% missing values at random X_miss <- X X_miss[sample(length(X_miss), length(X_miss) / 10)] <- NA anyNA(X_miss) # TRUE X_imputed <- impute_matrix(X_miss) anyNA(X_imputed) # FALSE # Verify reconstruction quality cat("Imputation MSE:", mean((X_imputed - X)^2, na.rm = TRUE), "\n") # Now safe to use in o2m Y <- scale(matrix(rnorm(50 * 80), 50, 80)) fit <- o2m(scale(X_imputed), Y, n = 1, nx = 0, ny = 0) ``` -------------------------------- ### Plotting OmicsPLS Model Results Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Visualize the results of an OmicsPLS model fit. This is useful for interpreting the relationships between variables and components. ```R plot(fit0, "Yj") ``` -------------------------------- ### orth Source: https://context7.com/selbouhaddani/omicspls/llms.txt Performs matrix orthogonalization, returning an orthonormalized version of a numeric matrix or vector using QR or SVD decomposition. This is useful for constructing orthonormal bases or pre-processing loading matrices. ```APIDOC ## orth ### Description Returns an orthonormalized version of a numeric matrix or vector using either QR or SVD decomposition. Useful for constructing orthonormal bases or pre-processing loading matrices. ### Usage ```r orth(mat, type = c("QR", "SVD")) ``` ### Parameters * `mat`: A numeric matrix or vector to be orthogonalized. * `type`: A character string specifying the decomposition method, either "QR" or "SVD". Defaults to "QR". ### Returns An orthonormalized matrix or vector. ``` -------------------------------- ### Fit Standard O2PLS Model Source: https://context7.com/selbouhaddani/omicspls/llms.txt Use `o2m` to fit an O2PLS model. Specify the number of joint components (`n`), X-specific orthogonal components (`nx`), and Y-specific orthogonal components (`ny`). The function automatically switches to a memory-efficient NIPALS approach for high-dimensional data. ```r library(OmicsPLS) # --- Simulate data --- set.seed(42) X <- scale(matrix(rnorm(100 * 50), 100, 50)) # 100 subjects, 50 X-variables Y <- scale(matrix(rnorm(100 * 40), 100, 40)) # 100 subjects, 40 Y-variables # --- Standard O2PLS fit: 2 joint, 1 X-specific, 1 Y-specific component --- fit <- o2m(X, Y, n = 2, nx = 1, ny = 1) fit # O2PLS fit # with 2 joint components # and 1 orthogonal components in X # and 1 orthogonal components in Y # Elapsed time: 0.03 sec # Return value (selected fields): # fit$Tt — N×n joint X scores # fit$W. — p×n joint X loadings # fit$U — N×n joint Y scores # fit$C. — q×n joint Y loadings # fit$T_Yosc — N×nx X-orthogonal scores # fit$U_Xosc — N×ny Y-orthogonal scores # fit$R2X — proportion of X variation modeled (joint + orthogonal) # fit$R2Y — proportion of Y variation modeled # fit$R2Xcorr — proportion of X variation in joint part # fit$R2Ycorr — proportion of Y variation in joint part ``` -------------------------------- ### Predict Y from X with `predict.o2m` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Predicts the Y matrix from new X observations using a trained O2PLS model. Ensure new data has the same number of variables as the training data. Orthogonal correction is applied before prediction. ```R library(OmicsPLS) set.seed(7) X_train <- scale(matrix(rnorm(80 * 20), 80, 20)) Y_train <- scale(matrix(rnorm(80 * 15), 80, 15)) fit <- o2m(X_train, Y_train, n = 2, nx = 1, ny = 1) # New test samples X_test <- scale(matrix(rnorm(20 * 20), 20, 20)) Y_test <- scale(matrix(rnorm(20 * 15), 20, 15)) # Predict Y from X_test Y_hat <- predict(fit, newdata = X_test, XorY = "X") dim(Y_hat) # 20 × 15 # Prediction RMSEP on test set cat("RMSEP:", sqrt(mean((Y_hat - Y_test)^2)), "\n") # Predict X from Y_test X_hat <- predict(fit, newdata = Y_test, XorY = "Y") ``` -------------------------------- ### Fit O2PLS Model Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Fit an O2PLS model with specified numbers of joint and orthogonal components. This is a foundational step for analyzing the covariance structure between two omics datasets. ```R fit0 = o2m(X, Y, 1, 1, 0) fit0 ``` -------------------------------- ### Generate Synthetic Data for OmicsPLS Source: https://github.com/selbouhaddani/omicspls/blob/master/vignettes/OmicsPLS_vignette.html Generates synthetic X and Y matrices with latent components and added noise, suitable for testing OmicsPLS functionalities. Ensures reproducibility by setting a seed. ```R set.seed(564785412L) X = rnorm(100) %*% t(c(rep(1,5), rep(0,45))/sqrt(5)) + # Component 1 = joint rnorm(100) %*% t(c(rep(0,45), rep(1,5))/sqrt(5)) # Component 2 = specific Y = X[,c(6:25, 1:5, 26:45)] # Reorder columns of X and leave out last 5 X = X + matrix(rnorm(100*50), nrow=100) # add noise Y = Y + matrix(rnorm(100*45), nrow=100) # add noise X = scale(X, scale=F) Y = scale(Y, scale=F) ``` -------------------------------- ### impute_matrix Source: https://context7.com/selbouhaddani/omicspls/llms.txt Imputes missing values in a numeric matrix using softImpute (low-rank SVD imputation). This function is useful for preprocessing omics data before using functions like `o2m` that do not accept matrices with NA or Inf values. ```APIDOC ## impute_matrix ### Description Imputes missing values in a numeric matrix using the `softImpute` package (low-rank SVD imputation). Useful for preprocessing omics data before passing to `o2m`, since `o2m` does not accept matrices with `NA` or `Inf` values. ### Usage ```r impute_matrix(mat) ``` ### Parameters * `mat`: A numeric matrix potentially containing missing values (NA). ### Returns A numeric matrix with missing values imputed. ``` -------------------------------- ### Extract Score Matrices with `scores.o2m` Source: https://context7.com/selbouhaddani/omicspls/llms.txt Retrieves subject-level score matrices from a fitted O2PLS model. Use to obtain joint scores (shared signal) or orthogonal scores (dataset-specific variation). ```R library(OmicsPLS) X <- scale(matrix(rnorm(100 * 20), 100, 20)) Y <- scale(matrix(rnorm(100 * 15), 100, 15)) fit <- o2m(X, Y, n = 2, nx = 1, ny = 1) # Joint X scores (N × n matrix) Tt <- scores(fit, which_part = "Xjoint") # Joint Y scores U <- scores(fit, which_part = "Yjoint") # Plot joint scores — check alignment between X and Y plot(Tt[, 1], U[, 1], xlab = "T (X joint comp 1)", ylab = "U (Y joint comp 1)") abline(lm(U[, 1] ~ Tt[, 1]), col = "red") # Orthogonal scores T_orth <- scores(fit, which_part = "Xorth") U_orth <- scores(fit, which_part = "Yorth") ``` -------------------------------- ### predict.o2m Source: https://context7.com/selbouhaddani/omicspls/llms.txt Predicts the Y matrix from new X observations (or vice versa) using a trained O2PLS model. It applies orthogonal correction before prediction and requires the new data to have the same number of variables as the training data. ```APIDOC ## predict.o2m ### Description Given a trained O2PLS model, predicts the Y matrix from new X observations (or vice versa). Orthogonal correction is applied before prediction. The new data must have the same number of variables as the training data. ### Usage ```r predict(object, newdata, XorY) ``` ### Parameters * `object`: A fitted O2PLS model object. * `newdata`: A numeric matrix containing the new observations for prediction. * `XorY`: A character string, either "X" or "Y", indicating whether to predict Y from X or X from Y. ### Returns A numeric matrix containing the predicted values. ``` -------------------------------- ### scores.o2m Source: https://context7.com/selbouhaddani/omicspls/llms.txt Retrieves subject-level score matrices (projections onto latent components) from the fitted O2PLS model. It can extract joint scores for X and Y, as well as orthogonal scores capturing dataset-specific variation. ```APIDOC ## scores.o2m ### Description Retrieves subject-level score matrices (projections onto latent components) from the fitted model. The joint scores `Tt` (X) and `U` (Y) capture the shared signal; the orthogonal scores `T_Yosc` and `U_Xosc` capture dataset-specific variation. ### Usage ```r scores(fit, which_part = c("Xjoint", "Yjoint", "Xorth", "Yorth")) ``` ### Parameters * `fit`: A fitted O2PLS model object. * `which_part`: A character string specifying which score matrix to retrieve. Options are "Xjoint", "Yjoint", "Xorth", or "Yorth". ### Returns A matrix of scores. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.