| Title: | Spectral Network Quantitative Trait Loci (snQTL) Analysis |
|---|---|
| Description: | A spectral framework to map quantitative trait loci (QTLs) affecting joint differential networks of gene co-Expression. Test the equivalence among multiple biological networks via spectral statistics. See reference Hu, J., Weber, J. N., Fuess, L. E., Steinel, N. C., Bolnick, D. I., & Wang, M. (2025) <doi:10.1371/journal.pcbi.1012953>. |
| Authors: | Jiaxin Hu [aut, cre, cph], Miaoyan Wang [aut, cph] |
| Maintainer: | Jiaxin Hu <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.2 |
| Built: | 2026-05-24 09:57:27 UTC |
| Source: | https://github.com/cran/snQTL |
Create a Tensor-class object from an array, matrix, or vector.
as.tensor(x, drop = FALSE)as.tensor(x, drop = FALSE)
x |
an instance of |
drop |
whether or not modes of 1 should be dropped |
a Tensor-class object
#From vector vec <- runif(100); vecT <- as.tensor(vec); vecT #From matrix mat <- matrix(runif(1000),nrow=100,ncol=10) matT <- as.tensor(mat); matT #From array indices <- c(10,20,30,40) arr <- array(runif(prod(indices)), dim = indices) arrT <- as.tensor(arr); arrT#From vector vec <- runif(100); vecT <- as.tensor(vec); vecT #From matrix mat <- matrix(runif(1000),nrow=100,ncol=10) matT <- as.tensor(mat); matT #From array indices <- c(10,20,30,40) arr <- array(runif(prod(indices)), dim = indices) arrT <- as.tensor(arr); arrT
A binary search to find proper soft threshold lamv such that
BinarySearch(argv, sumabsv, maxiter = 150)BinarySearch(argv, sumabsv, maxiter = 150)
argv |
the vector to be soft thresholded |
sumabsv |
upperbound of the L_1 norm of sv |
maxiter |
max iteration to perform binary search |
the proper threshold level lamv.
symmPMD().
Tensor Column Space Unfolding
cs_unfold(tnsr, m) ## S4 method for signature 'Tensor' cs_unfold(tnsr, m = NULL)cs_unfold(tnsr, m) ## S4 method for signature 'Tensor' cs_unfold(tnsr, m = NULL)
tnsr |
Tensor instance |
m |
mode to be unfolded on |
cs_unfold(tnsr,m=NULL)
Generate snQTL test statistics from a given list of differential networks. This function takes a list of differential networks, the choice of test statistics, and other computational tuning parameters as inputs. Outputs include the calculated statistics, recall of the choice, and the decomposition components associated with the statistics.
diffnet_to_snQTL_stats( diffnet_list, method = c("sum", "sum_square", "max", "tensor"), rho = 1000, sumabs = 0.2, niter = 20, trace = FALSE, tensor_iter = 20, tensor_tol = 10^(-3), tensor_seed = NULL )diffnet_to_snQTL_stats( diffnet_list, method = c("sum", "sum_square", "max", "tensor"), rho = 1000, sumabs = 0.2, niter = 20, trace = FALSE, tensor_iter = 20, tensor_tol = 10^(-3), tensor_seed = NULL )
diffnet_list |
list, a list of p-by-p differential networks |
method |
character, the choice of test statistics; see "details" |
rho |
number, a large positive constant adding to the diagonal elements to ensure positive definiteness in symmetric matrix spectral decomposition |
sumabs |
number, the number specify the sparsity level in the matrix/tensor eigenvector; |
niter |
integer, the number of iterations to use in the PMD algorithm (see |
trace |
logic variable, whether to trace the progress of PMD algorithm (see |
tensor_iter |
integer, the maximal number of iteration in SSTD algorithm (see |
tensor_tol |
number, a small positive constant for error difference to indicate the SSTD convergence (see |
tensor_seed |
number, the seed to generate random initialization for SSTD algorithm |
The list diffnet_list records the pairwise differential networks . This package provides four options for test statistics:
sum, the sum of sparse leading matrix eigenvalues (sLMEs) of all pairwise differential networks:
where refers to the sLME operation with given sparsity level set up by sumabs.
sum_square, the sum of squared sLMEs:
max, the maximal of sLMEs:
tensor, the sparse leading tensor eigenvalue (sLTE) of the differential tensor:
where refers to the sLTE operation with given sparsity level set up by sumabs,
and is the differential tensor composed by stacking three pairwise differential networks.
The sparse symmetric matrix decomposition is implemented by symmPMD() with parameters rho, sumabs, niter, trace.
The sparse symmetric tensor decomposition is implemented by SSTD().
Since symmPMD() is used in SSTD(), parameters for symmPMD() are used for SSTD().
While parameters tensor_iter, tensor_tol, tensor_seed should be uniquely defined for tensor method.
a list containing the following:
method |
character, recall of the choice of test statistics |
stats |
number, the calculated test statistics with given network list and choices |
decomp_result |
list, if |
Hu, J., Weber, J. N., Fuess, L. E., Steinel, N. C., Bolnick, D. I., & Wang, M. (2025). A spectral framework to map QTLs affecting joint differential networks of gene co-expression. PLOS Computational Biology, 21(4), e1012953.
Return the vector of modes from a tensor
## S4 method for signature 'Tensor' dim(x)## S4 method for signature 'Tensor' dim(x)
x |
the Tensor instance |
dim(x)
an integer vector of the modes associated with x
tnsr <- rand_tensor() dim(tnsr)tnsr <- rand_tensor() dim(tnsr)
General folding of a matrix into a Tensor. This is designed to be the inverse function to unfold-methods, with the same ordering of the indices. This amounts to following: if we were to unfold a Tensor using a set of row_idx and col_idx, then we can fold the resulting matrix back into the original Tensor using the same row_idx and col_idx.
fold(mat, row_idx = NULL, col_idx = NULL, modes = NULL)fold(mat, row_idx = NULL, col_idx = NULL, modes = NULL)
mat |
matrix to be folded into a Tensor |
row_idx |
the indices of the modes that are mapped onto the row space |
col_idx |
the indices of the modes that are mapped onto the column space |
modes |
the modes of the output Tensor |
This function uses aperm as the primary workhorse.
Tensor object with modes given by modes
T. Kolda, B. Bader, "Tensor decomposition and applications". SIAM Applied Mathematics and Applications 2009, Vol. 51, No. 3 (September 2009), pp. 455-500. URL: https://www.jstor.org/stable/25662308.
tnsr <- new('Tensor',3L,c(3L,4L,5L),data=runif(60)) matT3<-unfold(tnsr,row_idx=2,col_idx=c(3,1)) identical(fold(matT3,row_idx=2,col_idx=c(3,1),modes=c(3,4,5)),tnsr)tnsr <- new('Tensor',3L,c(3L,4L,5L),data=runif(60)) matT3<-unfold(tnsr,row_idx=2,col_idx=c(3,1)) identical(fold(matT3,row_idx=2,col_idx=c(3,1),modes=c(3,4,5)),tnsr)
Given observations from two populations X and Y, compute the differential matrix
where N() is the covariance matrix, or the weighted adjacency matrices defined as
for some constant beta > 0, 1 <= i, j <= p. Let N represent the regular correlation matrix when beta=0, and covariance matrix when beta<0.
get_diffnet_from_exp(X, Y, adj.beta = -1, trans = FALSE, location = NULL)get_diffnet_from_exp(X, Y, adj.beta = -1, trans = FALSE, location = NULL)
X |
n1-by-p matrix for samples from the first population. Rows are samples/observations, while columns are the features. |
Y |
n2-by-p matrix for samples from the second population. Rows are samples/observations, while columns are the features. |
adj.beta |
Power to transform correlation matrices to weighted adjacency matrices
by |
trans |
logic variable, whether to only consider the trans-correlation (between genes from two different chromosomes or regions); see "details" |
location |
vector, the (chromosome) locations for items |
The p-by-p differential matrix .
Given a list of expression data, , compute the list of differential matrix
where N() is the covariance matrix, or the weighted adjacency matrices defined as
for some constant beta > 0, 1 <= i, j <= p. Let N represent the regular correlation matrix when beta=0, and covariance matrix when beta<0. In total, we will have K*(K-1)/2 pairwise differential networks in the list.
If trans = TRUE, we let if are from the same region based on location.
Under gene co-expression context, trans-correlation usually refer to the correlation between
two genes from two chromosomes.
get_diffnet_list_from_exp( exp_list, adj.beta = -1, trans = FALSE, location = NULL )get_diffnet_list_from_exp( exp_list, adj.beta = -1, trans = FALSE, location = NULL )
exp_list |
a list of nk-by-p matrices from the K populations. Rows are samples/observations, while columns are the features. |
adj.beta |
Power to transform correlation matrices to weighted adjacency matrices
by |
trans |
logic variable, whether to only consider the trans-correlation (between genes from two different chromosomes or regions) |
location |
vector, the (chromosome) locations for items |
A list of p-by-p differential matrix .
Returns the Kronecker product from a list of matrices or vectors. Commonly used for n-mode products and various Tensor decompositions.
kronecker_list(L)kronecker_list(L)
L |
list of matrices or vectors |
matrix that is the Kronecker product
smalllizt <- list('mat1' = matrix(runif(12),ncol=4), 'mat2' = matrix(runif(12),ncol=4), 'mat3' = matrix(runif(12),ncol=4)) dim(kronecker_list(smalllizt))smalllizt <- list('mat1' = matrix(runif(12),ncol=4), 'mat2' = matrix(runif(12),ncol=4), 'mat3' = matrix(runif(12),ncol=4)) dim(kronecker_list(smalllizt))
L2 norm for vector
l2n(vec)l2n(vec)
vec |
a numeric vector |
the L2 norm of vec.
Conformable elementwise operators for Tensor
## S4 method for signature 'Tensor,Tensor' Ops(e1, e2)## S4 method for signature 'Tensor,Tensor' Ops(e1, e2)
e1 |
left-hand object |
e2 |
right-hand object |
tnsr <- rand_tensor(c(3,4,5)) tnsr2 <- rand_tensor(c(3,4,5)) tnsrsum <- tnsr + tnsr2 tnsrdiff <- tnsr - tnsr2 tnsrelemprod <- tnsr * tnsr2 tnsrelemquot <- tnsr / tnsr2 for (i in 1:3L){ for (j in 1:4L){ for (k in 1:5L){ stopifnot(tnsrsum@data[i,j,k]==tnsr@data[i,j,k]+tnsr2@data[i,j,k]) stopifnot(tnsrdiff@data[i,j,k]==(tnsr@data[i,j,k]-tnsr2@data[i,j,k])) stopifnot(tnsrelemprod@data[i,j,k]==tnsr@data[i,j,k]*tnsr2@data[i,j,k]) stopifnot(tnsrelemquot@data[i,j,k]==tnsr@data[i,j,k]/tnsr2@data[i,j,k]) } } }tnsr <- rand_tensor(c(3,4,5)) tnsr2 <- rand_tensor(c(3,4,5)) tnsrsum <- tnsr + tnsr2 tnsrdiff <- tnsr - tnsr2 tnsrelemprod <- tnsr * tnsr2 tnsrelemquot <- tnsr / tnsr2 for (i in 1:3L){ for (j in 1:4L){ for (k in 1:5L){ stopifnot(tnsrsum@data[i,j,k]==tnsr@data[i,j,k]+tnsr2@data[i,j,k]) stopifnot(tnsrdiff@data[i,j,k]==(tnsr@data[i,j,k]-tnsr2@data[i,j,k])) stopifnot(tnsrelemprod@data[i,j,k]==tnsr@data[i,j,k]*tnsr2@data[i,j,k]) stopifnot(tnsrelemquot@data[i,j,k]==tnsr@data[i,j,k]/tnsr2@data[i,j,k]) } } }
Generate a Tensor with specified modes with iid normal(0,1) entries.
rand_tensor(modes = c(3, 4, 5), drop = FALSE)rand_tensor(modes = c(3, 4, 5), drop = FALSE)
modes |
the modes of the output Tensor |
drop |
whether or not modes equal to 1 should be dropped |
a Tensor object with modes given by modes
Default rand_tensor() generates a 3-Tensor with modes c(3,4,5).
rand_tensor() rand_tensor(c(4,4,4)) rand_tensor(c(10,2,1),TRUE)rand_tensor() rand_tensor(c(4,4,4)) rand_tensor(c(10,2,1),TRUE)
Tensor Row Space Unfolding
rs_unfold(tnsr, m) ## S4 method for signature 'Tensor' rs_unfold(tnsr, m = NULL)rs_unfold(tnsr, m) ## S4 method for signature 'Tensor' rs_unfold(tnsr, m = NULL)
tnsr |
Tensor instance |
m |
mode to be unfolded on |
rs_unfold(tnsr,m=NULL)
Generate one single snQTL test statistics from a given list of expression data. This function takes a list of expression data, the choice of test statistics, the choice to permute or not, the choice of considering trans-correlation or not, and other computational tuning parameters as inputs. Outputs include the calculated statistics, recall of the choices, and the decomposition components associated with the statistics.
single_exp_to_snQTL_stats( seed = NULL, permute = FALSE, exp_list, method = c("sum", "sum_square", "max", "tensor"), rho = 1000, sumabs = 0.2, niter = 20, trace = FALSE, adj.beta = -1, tensor_iter = 20, tensor_tol = 10^(-3), trans = FALSE, location = NULL )single_exp_to_snQTL_stats( seed = NULL, permute = FALSE, exp_list, method = c("sum", "sum_square", "max", "tensor"), rho = 1000, sumabs = 0.2, niter = 20, trace = FALSE, adj.beta = -1, tensor_iter = 20, tensor_tol = 10^(-3), trans = FALSE, location = NULL )
seed |
number, the random seed to shuffle the expression data if |
permute |
logic variable, whether to shuffle the samples in expression data; see "details" |
exp_list |
list, a list of expression data from samples with different genotypes; see "details" |
method |
character, the choice of test statistics (see |
rho |
number, a large positive constant adding to the diagonal elements to ensure positive definiteness in symmetric matrix spectral decomposition |
sumabs |
number, the number specify the sparsity level in the matrix/tensor eigenvector; |
niter |
integer, the number of iterations to use in the PMD algorithm (see |
trace |
logic variable, whether to trace the progress of PMD algorithm (see |
adj.beta |
number, the power transformation to the correlation matrices (see |
tensor_iter |
integer, the maximal number of iteration in SSTD algorithm (see |
tensor_tol |
number, a small positive constant for error difference to indicate the SSTD convergence (see |
trans |
logic variable, whether to only consider the trans-correlation (between genes from two different chromosomes or regions); see "details" |
location |
vector, the (chromosome) locations for genes if |
In exp_list, the dimensions for data matrices are n1-by-p, n2-by-p, and n3-by-p, respectively.
The expression data is usually normalized. We use expression data to generate the Pearson's correlation co-expression networks.
If permute = TRUE, we shuffle the samples in three expression matrices while keeping the same dimensions.
The test statistics from randomly shuffled data are considered as the statistics from null distribution.
If trans = TRUE, we only consider the trans-correlation between the genes from two different chromosomes or regions in co-expression networks.
The entries in correlation matrices if gene i and gene j are from the same chromosome or region.
a list containing the following:
method |
character, recall of the choice of test statistics |
permute |
logic variable, recall of the choice of permutation |
stats |
number, the calculated test statistics with given expression list and choices |
decomp_result |
list, if |
Hu, J., Weber, J. N., Fuess, L. E., Steinel, N. C., Bolnick, D. I., & Wang, M. (2025). A spectral framework to map QTLs affecting joint differential networks of gene co-expression. PLOS Computational Biology, 21(4), e1012953.
Calculate the sLME given a matrix .
For any symmetric matrix , sLME test statistic is defined as
where sEig() is the sparse leading eigenvalue, defined as
subject to
.
sLME(Dmat, rho = 1000, sumabs.seq = 0.2, niter = 20, trace = FALSE)sLME(Dmat, rho = 1000, sumabs.seq = 0.2, niter = 20, trace = FALSE)
Dmat |
p-by-p numeric matrix, the differential matrix |
rho |
a large positive constant such that |
sumabs.seq |
a numeric vector specifing the sequence of sparsity parameters, each between |
niter |
the number of iterations to use in the PMD algorithm (see |
trace |
whether to trace the progress of PMD algorithm (see |
A list containing the following components:
sumabs.seq |
the sequence of sparsity parameters |
rho |
a positive constant to augment the diagonal of the differential matrix
such that |
stats |
a numeric vector of test statistics when using different sparsity parameters
(corresponding to |
sign |
a vector of signs when using different sparsity parameters (corresponding to |
v |
the sequence of sparse leading eigenvectors, each row corresponds to one sparsity
parameter given by |
leverage |
the leverage score for genes (defined as |
Zhu, Lingxue, et al. "Testing high-dimensional covariance matrices, with application to detecting schizophrenia risk genes." The annals of applied statistics 11.3 (2017): 1810.
Spectral framework to detect network QTLs affecting the co-expression networks. This is the main function for snQTL test.
Given a list of expression data matrices from samples with different gentoypes, we test whether there are significant difference among three co-expression networks. Statistically, we consider the hypothesis testing task:
where refer to different genotypes, refers to the adjacency matrices corresponding to the co-expression network.
We provide four options for the test statistics, composed by sparse matrix/tensor eigenvalues. We perform permutation test to obtain the empirical p-values for the hypothesis testing.
NOTE: This function is also applicable for generalized cases to compare multiple (K > 3) biological networks. Instead of separating the samples by genotypes, people can separate the samples into K groups based on other interested metrics, e.g., locations, treatments. The generalized hypothesis testing problem becomes
where refers to the correlation-based network corresponding to the group k.
For consistency, we stick with the original genotype-based setting in this help document.
See details and examples for the generalization on the Github manual https://github.com/Marchhu36/snQTL.
snQTL_test_corrnet( exp_list, method = c("sum", "sum_square", "max", "tensor"), npermute = 100, seeds = 1:100, stats_seed = NULL, rho = 1000, sumabs = 0.2, niter = 20, trace = FALSE, adj.beta = -1, tensor_iter = 20, tensor_tol = 10^(-3), trans = FALSE, location = NULL )snQTL_test_corrnet( exp_list, method = c("sum", "sum_square", "max", "tensor"), npermute = 100, seeds = 1:100, stats_seed = NULL, rho = 1000, sumabs = 0.2, niter = 20, trace = FALSE, adj.beta = -1, tensor_iter = 20, tensor_tol = 10^(-3), trans = FALSE, location = NULL )
exp_list |
list, a list of expression data from samples with different genotypes; the dimensions for data matrices are n1-by-p, n2-by-p, and n3-by-p, respectively; see "details" |
method |
character, the choice of test statistics; see "details" |
npermute |
number, the number of permutations to obtain empirical p-values |
seeds |
vector, the random seeds for permutation; length of the vector is equal to the |
stats_seed |
number, the random seed for test statistics calculation with non-permuted data |
rho |
number, a large positive constant adding to the diagonal elements to ensure positive definiteness in symmetric matrix spectral decomposition |
sumabs |
number, the number specify the sparsity level in the matrix/tensor eigenvector; |
niter |
integer, the number of iterations to use in the PMD algorithm (see |
trace |
logic variable, whether to trace the progress of PMD algorithm (see |
adj.beta |
number, the power transformation to the correlation matrices (see |
tensor_iter |
integer, the maximal number of iteration in SSTD algorithm (see |
tensor_tol |
number, a small positive constant for error difference to indicate the SSTD convergence (see |
trans |
logic variable, whether to only consider the trans-correlation (between genes from two different chromosomes or regions); see "details" |
location |
vector, the (chromosome) locations for genes if |
In exp_list, the data matrices are usually ordered with marker's genotypes AA, BB, and AB.
The expression data is usually normalized. We use expression data to generate the Pearson's correlation co-expression networks.
Given the list of co-expression networks, we generate pairwise differential networks
We use pairwise differential networks to generate the snQTL test statistics.
We provide four options of test statistics with different choices of method:
sum, the sum of sparse leading matrix eigenvalues (sLMEs) of all pairwise differential networks:
where refers to the sLME operation with given sparsity level set up by sumabs.
sum_square, the sum of squared sLMEs:
max, the maximal of sLMEs:
tensor, the sparse leading tensor eigenvalue (sLTE) of the differential tensor:
where refers to the sLTE operation with given sparsity level set up by sumabs,
and is the differential tensor composed by stacking three pairwise differential networks.
Additionally, if trans = TRUE, we only consider the trans-correlation between the genes from two different chromosomes or regions in co-expression networks.
The entries in correlation matrices if gene i and gene j are from the same chromosome or region.
The gene location information is required if trans = TRUE.
a list containing the following:
method |
character, recall of the choice of test statistics |
res_original |
list, test result for non-permuted data, including the recall of method choices, test statistics, and decomposition components |
res_permute |
list, test results for each permuted data, including the recall of method choices, test statistics, and decomposition components |
emp_p_value |
number, the empirical p-value from permutation test |
Hu, J., Weber, J. N., Fuess, L. E., Steinel, N. C., Bolnick, D. I., & Wang, M. (2025). A spectral framework to map QTLs affecting joint differential networks of gene co-expression. PLOS Computational Biology, 21(4), e1012953.
### artificial example n1 = 50 n2 = 60 n3 = 100 p = 200 location = c(rep(1,20), rep(2, 50), rep(3, 100), rep(4, 30)) ## expression data from null set.seed(0416) # random seeds for example data exp1 = matrix(rnorm(n1*p, mean = 0, sd = 1), nrow = n1) exp2 = matrix(rnorm(n2*p, mean = 0, sd = 1), nrow = n2) exp3 = matrix(rnorm(n3*p, mean = 0, sd = 1), nrow = n3) exp_list = list(exp1, exp2, exp3) result = snQTL_test_corrnet(exp_list = exp_list, method = 'tensor', npermute = 30, seeds = 1:30, stats_seed = 0416, trans = TRUE, location = location) result$emp_p_value### artificial example n1 = 50 n2 = 60 n3 = 100 p = 200 location = c(rep(1,20), rep(2, 50), rep(3, 100), rep(4, 30)) ## expression data from null set.seed(0416) # random seeds for example data exp1 = matrix(rnorm(n1*p, mean = 0, sd = 1), nrow = n1) exp2 = matrix(rnorm(n2*p, mean = 0, sd = 1), nrow = n2) exp3 = matrix(rnorm(n3*p, mean = 0, sd = 1), nrow = n3) exp_list = list(exp1, exp2, exp3) result = snQTL_test_corrnet(exp_list = exp_list, method = 'tensor', npermute = 30, seeds = 1:30, stats_seed = 0416, trans = TRUE, location = location) result$emp_p_value
Soft threshold
soft(x, d)soft(x, d)
x |
a numeric vector |
d |
the soft threshold level |
the vector after soft thresholding x at level d.
symmPMD().
An iterative algorithm that solves the Sparse Principal Component Analysis problem: given a positive definite matrix A:
subject to
The solution v is the sparse leading eigenvector, and the corresponding objective
is the sparse leading eigenvalue.
solvePMD(x, sumabsv, v, niter = 50, trace = TRUE)solvePMD(x, sumabsv, v, niter = 50, trace = TRUE)
x |
p-by-p matrix, symmetric and positive definite |
sumabsv |
the upperbound of the L_1 norm of |
v |
the starting value of the algorithm. |
niter |
number of iterations to perform the iterative optimizations |
trace |
whether to print tracing info during optimization |
A list containing the following components:
v |
the sparse leading eigenvector v |
d |
the sparse leading eigenvalue |
v.init |
the initial value of v |
symmPMD().
SSTD solves the rank-1 approximation to the a p-by-p-by-q sparse symmetric tensor :
subject to
The solution is the sparse leading tensor eigenvalue (sLTE),
is the sparse leading tensor eigenvector, and is the loading vector.
The Symmetric Penalized Matrix Decomposition symmPMD() is used in the iterative algorithm.
SSTD_R1( T_obs, u_ini, v_ini, max_iter = 20, sumabs = 0.5, niter = 20, rho = 1000, tol = 10^(-3), verbose = FALSE )SSTD_R1( T_obs, u_ini, v_ini, max_iter = 20, sumabs = 0.5, niter = 20, rho = 1000, tol = 10^(-3), verbose = FALSE )
T_obs |
array, a p-by-p-by-q tensor; each p-by-p layer in |
u_ini |
vector, with length q; the random initialization for loading vector |
v_ini |
vector, with length p; the random initialization for tensor eigenvector |
max_iter |
integer, the maximal iteration number |
sumabs |
number, the number specify the sparsity level in the matrix/tensor eigenvector; |
niter |
integer, the number of iterations to use in the PMD algorithm (see |
rho |
number, a large positive constant adding to the diagonal elements to ensure positive definiteness in symmetric matrix spectral decomposition |
tol |
number, the tolerance threshold for SSTD convergence; if the error difference between two iterations is smaller than |
verbose |
logic variable, whether to print the progress during permutation tests |
a list containing the following:
u_hat |
vector, with length q; the estimated loading vector |
v_hat |
vector, with length p; the estimated tensor eigenvector |
gamma_hat |
number, the estimated sLTE |
Hu, J., Weber, J. N., Fuess, L. E., Steinel, N. C., Bolnick, D. I., & Wang, M. (2025). A spectral framework to map QTLs affecting joint differential networks of gene co-expression. PLOS Computational Biology, 21(4), e1012953.
Sun, W. W., Lu, J., Liu, H., & Cheng, G. (2017). "Provable sparse tensor decomposition." Journal of the Royal Statistical Society Series B: Statistical Methodology, 79(3), 899-916.
symmPMD()
This function solves for the Sparse Principal Component Analysis given a positive definite matrix A:
subject to
The solution v is the sparse leading eigenvector, and the corresponding objective
is the sparse leading engenvalue.
The algorithm uses an iterative procedure similar to the R Package "PMA", but speeds up the computation using the extra constraint that the decomposition is symmetric.
symmPMD(x, sumabs = 0.3, niter = 50, v = NULL, trace = TRUE)symmPMD(x, sumabs = 0.3, niter = 50, v = NULL, trace = TRUE)
x |
p-by-p matrix, symmetric and positive definite |
sumabs |
sumabs* |
niter |
number of iterations to perform the iterative optimizations |
v |
the starting value of the algorithm, either a pre-calculated first singular vector of x, or NULL. |
trace |
whether to print tracing info during optimization |
A list containing the following components:
v |
the sparse leading eigenvector v |
d |
the sparse leading eigenvalue |
sumabs |
sumabs* |
Zhu, Lingxue, et al. "Testing high-dimensional covariance matrices, with application to detecting schizophrenia risk genes." The annals of applied statistics 11.3 (2017): 1810.
Witten, Tibshirani and Hastie (2009), "A penalized matrix decomposition, with applications to sparse principal components and canonical correlation analysis", Biostatistics 10(3):515-534.
An S4 class for a tensor with arbitrary number of modes. The Tensor class extends the base "array" class to include additional tensor manipulation (folding, unfolding, reshaping, subsetting) as well as a formal class definition that enables more explicit tensor algebra.
number of modes (integer)
vector of modes (integer), aka sizes/extents/dimensions
actual data of the tensor, which can be 'array' or 'vector'
All of the decompositions and regression models in this package require a Tensor input.
James Li [email protected]
James Li, Jacob Bien, Martin T. Wells (2018). rTensor: An R Package for Multidimensional Array (Tensor) Unfolding, Multiplication, and Decomposition. Journal of Statistical Software, Vol. 87, No. 10, 1-31. URL: http://www.jstatsoft.org/v087/i10/.
Contracted (m-Mode) product between a Tensor of arbitrary number of modes and a list of matrices. The result is folded back into Tensor.
ttl(tnsr, list_mat, ms = NULL)ttl(tnsr, list_mat, ms = NULL)
tnsr |
Tensor object with K modes |
list_mat |
a list of matrices |
ms |
a vector of modes to contract on (order should match the order of |
Performs ttm repeated for a single Tensor and a list of matrices on multiple modes. For instance, suppose we want to do multiply a Tensor object tnsr with three matrices mat1, mat2, mat3 on modes 1, 2, and 3. We could do ttm(ttm(ttm(tnsr,mat1,1),mat2,2),3), or we could do ttl(tnsr,list(mat1,mat2,mat3),c(1,2,3)). The order of the matrices in the list should obviously match the order of the modes. This is a common operation for various Tensor decompositions such as CP and Tucker. For the math on the m-Mode Product, see Kolda and Bader (2009).
Tensor object with K modes
The returned Tensor does not drop any modes equal to 1.
T. Kolda, B. Bader, "Tensor decomposition and applications". SIAM Applied Mathematics and Applications 2009, Vol. 51, No. 3 (September 2009), pp. 455-500. URL: https://www.jstor.org/stable/25662308
tnsr <- new('Tensor',3L,c(3L,4L,5L),data=runif(60)) lizt <- list('mat1' = matrix(runif(30),ncol=3), 'mat2' = matrix(runif(40),ncol=4), 'mat3' = matrix(runif(50),ncol=5)) ttl(tnsr,lizt,ms=c(1,2,3))tnsr <- new('Tensor',3L,c(3L,4L,5L),data=runif(60)) lizt <- list('mat1' = matrix(runif(30),ncol=3), 'mat2' = matrix(runif(40),ncol=4), 'mat3' = matrix(runif(50),ncol=5)) ttl(tnsr,lizt,ms=c(1,2,3))
Contracted (m-Mode) product between a Tensor of arbitrary number of modes and a matrix. The result is folded back into Tensor.
ttm(tnsr, mat, m = NULL)ttm(tnsr, mat, m = NULL)
tnsr |
Tensor object with K modes |
mat |
input matrix with same number columns as the |
m |
the mode to contract on |
By definition, the number of columns in mat must match the mth mode of tnsr. For the math on the m-Mode Product, see Kolda and Bader (2009).
a Tensor object with K modes
The mth mode of tnsr must match the number of columns in mat. By default, the returned Tensor does not drop any modes equal to 1.
T. Kolda, B. Bader, "Tensor decomposition and applications". SIAM Applied Mathematics and Applications 2009, Vol. 51, No. 3 (September 2009), pp. 455-500. URL: https://www.jstor.org/stable/25662308
tnsr <- new('Tensor',3L,c(3L,4L,5L),data=runif(60)) mat <- matrix(runif(50),ncol=5) ttm(tnsr,mat,m=3)tnsr <- new('Tensor',3L,c(3L,4L,5L),data=runif(60)) mat <- matrix(runif(50),ncol=5) ttm(tnsr,mat,m=3)
Unfolds the tensor into a matrix, with the modes in rs onto the rows and modes in cs onto the columns. Note that c(rs,cs) must have the same elements (order doesn't matter) as x@modes. Within the rows and columns, the order of the unfolding is determined by the order of the modes. This convention is consistent with Kolda and Bader (2009).
unfold(tnsr, row_idx, col_idx)unfold(tnsr, row_idx, col_idx)
tnsr |
the Tensor instance |
row_idx |
the indices of the modes to map onto the row space |
col_idx |
the indices of the modes to map onto the column space |
unfold(tnsr,row_idx=NULL,col_idx=NULL)
matrix with prod(row_idx) rows and prod(col_idx) columns
T. Kolda, B. Bader, "Tensor decomposition and applications". SIAM Applied Mathematics and Applications 2009, Vol. 51, No. 3 (September 2009), pp. 455-500. URL: https://www.jstor.org/stable/25662308.
tnsr <- rand_tensor() matT3<-unfold(tnsr,row_idx=2,col_idx=c(3,1))tnsr <- rand_tensor() matT3<-unfold(tnsr,row_idx=2,col_idx=c(3,1))