Title: | Covariate-Adjusted Tensor Classification in High-Dimensions |
---|---|
Description: | Performs classification and variable selection on high-dimensional tensors (multi-dimensional arrays) after adjusting for additional covariates (scalar or vectors) as CATCH model in Pan, Mai and Zhang (2018) <arXiv:1805.04421>. The low-dimensional covariates and the high-dimensional tensors are jointly modeled to predict a categorical outcome in a multi-class discriminant analysis setting. The Covariate-Adjusted Tensor Classification in High-dimensions (CATCH) model is fitted in two steps: (1) adjust for the covariates within each class; and (2) penalized estimation with the adjusted tensor using a cyclic block coordinate descent algorithm. The package can provide a solution path for tuning parameter in the penalized estimation step. Special case of the CATCH model includes linear discriminant analysis model and matrix (or tensor) discriminant analysis without covariates. |
Authors: | Yuqing Pan <[email protected]>, Qing Mai <[email protected]>, Xin Zhang <[email protected]> |
Maintainer: | Yuqing Pan <[email protected]> |
License: | GPL-2 |
Version: | 1.0.1 |
Built: | 2024-11-27 06:30:17 UTC |
Source: | CRAN |
Adjusts tensor with respect to covariates to achieve a more accurate performance. Tensor depends on the covariates through a linear regression model. The function returns the coefficients of covariates in regression and adjusted tensor list for further classifier modeling. It estimates coefficients based on training data, and then adjusts training tensor. When testing data is provided, the function will automatically adjust testing data by learned coefficients as well.
adjten(x, z, y, testx = NULL, testz = NULL, is.centered = FALSE)
adjten(x, z, y, testx = NULL, testz = NULL, is.centered = FALSE)
x |
Input tensor or matrix list of length |
z |
Input covariate matrix of dimension |
y |
Class label vector of dimention |
testx |
Input testing tensor or matrix list. Each element of the list is a test case. When |
testz |
Input testing covariate matrix with each row being an observation. |
is.centered |
Indicates whether the input tensor and covariates have already been centered by their within class mean or not. If |
The model CATCH assumes the linear relationship bewteen covariates and tensor as
where is the matrix of estimated coefficient of covariates.
The function removes the effects of covariates on response variable through tensor and obtain
as adjusted tensor to fit tensor discriminant analysis model.
In estimating , which is the
alpha
in the package, adjten
first centers both tensor and covariates within their individual classes, then performs tensor response regression which regresses on
.
gamma |
The estimated coefficients of covariates to plug in classifier. |
xres |
Adjusted training tensor list |
testxres |
Adjusted testing tensor list |
Yuqing Pan, Qing Mai, Xin Zhang
Pan, Y., Mai, Q., and Zhang, X. (2018) Covariate-Adjusted Tensor Classification in High-Dimensions, arXiv:1805.04421.
n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars),nrow=n,ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2),nrow=n,ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,],dim=c(p,p,p)) } obj <- adjten(x, z, y)
n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars),nrow=n,ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2),nrow=n,ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,],dim=c(p,p,p)) } obj <- adjten(x, z, y)
The catch
function solves classification problems and selects variables by fitting a covariate-adjusted tensor classification in high-dimensions (CATCH) model. The input training predictors include two parts: tensor data and low dimensional covariates. The tensor data could be matrix as a special case of tensor. In catch
, tensor data should be stored in a list form. If the dataset contains no covariate, catch
can also fit a classifier only based on the tensor predictors. If covariates are provided, the method will adjust tensor for covariates and then fit a classifier based on the adjusted tensor along with the covariates. If users specify testing data at the same time, predicted response will be obtained as well.
catch(x, z = NULL, y, testx = NULL, testz = NULL, nlambda = 100, lambda.factor = ifelse((nobs - nclass) <= nvars, 0.2, 1E-03), lambda = NULL,dfmax = nobs, pmax = min(dfmax * 2 + 20, nvars), pf = rep(1, nvars), eps = 1e-04, maxit = 1e+05, sml = 1e-06, verbose = FALSE, perturb = NULL)
catch(x, z = NULL, y, testx = NULL, testz = NULL, nlambda = 100, lambda.factor = ifelse((nobs - nclass) <= nvars, 0.2, 1E-03), lambda = NULL,dfmax = nobs, pmax = min(dfmax * 2 + 20, nvars), pf = rep(1, nvars), eps = 1e-04, maxit = 1e+05, sml = 1e-06, verbose = FALSE, perturb = NULL)
x |
Input tensor (or matrix) list of length |
z |
Input covariate matrix of dimension |
y |
Class label. For |
testx |
Input testing tensor or matrix list. Each element of the list is a test case. When |
testz |
Input testing covariate matrix. Can be omitted if covariate is absent. However, training covariates |
nlambda |
The number of tuning values in sequence |
lambda.factor |
When |
lambda |
A sequence of user-specified |
dfmax |
The maximum number of selected variables in the model. Default is the number of observations |
pmax |
The maximum number of potential selected variables during iteration. In middle step, the algorithm can select at most |
pf |
Weight of lasso penalty. Default is a vector of value |
eps |
Convergence threshold for coordinate descent difference between iterations. Default value is |
maxit |
Maximum iteration times for all lambda. Default value is |
sml |
Threshold for ratio of loss function change after each iteration to old loss function value. Default value is |
verbose |
Indicates whether print out lambda during iteration or not. Default value is |
perturb |
Perturbation scaler. If it is specified, the value will be added to diagonal of estimated covariance matrix. A small value can be used to accelerate iteration. Default value is |
The catch
function fits a linear discriminant analysis model as follows:
The categorical response is predicted from the estimated Bayes rule:
where is the tensor,
is the covariates,
,
and
are parameters estimated by CATCH. A detailed explanation can be found in reference. When
Z
is not NULL
, the function will first adjust tensor on covariates by modeling
where is an unobservable tensor normal error independent of
.
Then
catch
fits model on the adjusted training tensor and makes predictions on testing data by using the adjusted tensor list. If
Z
is NULL
, it reduces to a simple tensor discriminant analysis model.
The coefficient of tensor , represented by
beta
in package, is estimated by
When response is multi-class, the group lasso penalty over categories is added to objective function through parameter lambda
, and it reduces to a lasso penalty in binary problems.
The function catch
will predict categorical response when testing data is provided.
If testing data is not provided or if one wishes to perform prediction separately, catch
can be used to only fit model with a catch object outcome. The object outcome can be combined with the adjusted tensor list from adjten
to perform prediction by predict.catch
.
beta |
Output variable coefficients for each |
df |
The number of nonzero variables for each value in sequence |
dim |
Dimension of coefficient array. |
lambda |
The actual |
obj |
Objective function value for each value in sequence |
x |
The tensor list after adjustment in training data. If covariate is absent, this is the original input tensor list. |
y |
Class label in training data. |
npasses |
Total number of iterations. |
jerr |
Error flag. |
sigma |
Estimated covariance matrix on each mode. |
delta |
Estimated delta matrix |
mu |
Estimated mean array of |
prior |
Proportion of samples in each class. |
call |
The call that produces this object. |
pred |
Predicted categorical response for each value in sequence |
Yuqing Pan, Qing Mai, Xin Zhang
Pan, Y., Mai, Q., and Zhang, X. (2018) Covariate-Adjusted Tensor Classification in High-Dimensions, arXiv:1805.04421.
cv.catch
, predict.catch
, adjten
#without prediction n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars), nrow=n, ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2), nrow=n, ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,],dim=c(p,p,p)) } obj <- catch(x,z,y=y)
#without prediction n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars), nrow=n, ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2), nrow=n, ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,],dim=c(p,p,p)) } obj <- catch(x,z,y=y)
Fits a classifier for matrix data. catch_matrix
is a special case of catch
when each observation is a matrix. Different from
catch
takes list as input, data need to be formed in an array to call the function (see arguments). The function will perform prediction as well.
catch_matrix(x, z = NULL, y, testx = NULL, testz = NULL, ...)
catch_matrix(x, z = NULL, y, testx = NULL, testz = NULL, ...)
x |
Input matrix array. The array should be organized with dimension |
z |
Input covariate matrix of dimension |
y |
Class label. For |
testx |
Input testing matrix array. When |
testz |
Input testing covariate matrix. Can be omitted if there is no covariate. |
... |
Other arguments that can be passed to |
The function fits a matrix classifier as a special case of catch
. The fitted model and predictions should be identical to catch
when matrix data is provided. Input matrix should be organized as three-way array where sample size is the last dimension. If the matrix is organized in a list, users can either reorganize it or use catch
directly to fit model, which takes a matrix or tensor list as input and has the same output as catch_matrix
.
beta |
Output variable coefficients for each |
df |
The number of nonzero variables for each value in sequence |
dim |
Dimension of coefficient array. |
lambda |
The actual |
obj |
Objective function value for each value in sequence |
x |
The matrix list after adjustment in training data. If covariate is absent, this is the original input matrix. |
y |
Class label in training data. |
npasses |
Total number of iterations. |
jerr |
Error flag. |
sigma |
Estimated covariance matrix on each mode. |
delta |
Estimated delta matrix |
mu |
Estimated mean array. |
prior |
Prior proportion of observations in each class. |
call |
The call that produces this object. |
pred |
Predicted categorical response for each value in sequence |
Yuqing Pan, Qing Mai, Xin Zhang
Pan, Y., Mai, Q., and Zhang, X. (2018) Covariate-Adjusted Tensor Classification in High-Dimensions, arXiv:1805.04421.
#without prediction n <- 20 p <- 4 k <- 2 nvars <- p*p x=array(rnorm(n*nvars),dim=c(p,p,n)) x[,,11:20]=x[,,11:20]+0.3 z <- matrix(rnorm(n*2), nrow=n, ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) obj <- catch_matrix(x,z,y=y)
#without prediction n <- 20 p <- 4 k <- 2 nvars <- p*p x=array(rnorm(n*nvars),dim=c(p,p,n)) x[,,11:20]=x[,,11:20]+0.3 z <- matrix(rnorm(n*2), nrow=n, ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) obj <- catch_matrix(x,z,y=y)
A dataset collected from a series of CSA experiments to identify volatile chemical toxicants (VCT). Chemical dyes were exposed to VCT under different concentration conditions and colors of dyes were recorded to identify the class of VCT. There are two concentration conditions PEL (permissible exposure level) and IDLH (immediately dangerous to life of health).
data(csa)
data(csa)
Two lists, PEL and IDLH, and a numeric vector y. Each list contains 147 matrices of dimension .
PEL
A list of matrices containing the observations after exposure at PEL.
IDLH
A list of matrices containing the observations after exposure at IDLH level.
y
Class label ranging from 1 to 21.
This dataset is provided in the Supplementary matrial of Zhong (2015). In each concentration case, there are 147 observations and 21 classes. We reorganize the data into a list to be directly called by catch
. For matrices in the list, each row represents a dye and the three columns correspond to red, green and blue.
Wenxuan Zhong and Kenneth S. Suslick (2015). "Matrix discriminant analysis with application to colorimetric sensor array data" Technometrics 57(4), 524–534.
Performs k-fold cross validation for CATCH and returns the best tuning parameter in the user-specified or automatically generated choices.
cv.catch(x, z = NULL, y, nfolds = 5, lambda = NULL, lambda.opt = "min",...)
cv.catch(x, z = NULL, y, nfolds = 5, lambda = NULL, lambda.opt = "min",...)
x |
Input tensor or matrix list of length |
z |
Input covariate matrix of dimension |
y |
Class label. For |
nfolds |
Number of folds. Default value is |
lambda |
User-specified |
lambda.opt |
The optimal criteria when multiple elements in |
... |
Other arguments that can be passed to |
The function cv.catch
runs function catch
nfolds+1
times. The first one fits model on all data. If lambda
is specified, it will check if all lambda
satisfies the constraints of dfmax
and pmax
in catch
. If not, a lambda
sequence will be generated according to lambda.factor
in catch
. Then the rest nfolds
many replicates will fit model on nfolds-1
many folds data and predict on the omitted fold, repectively. Return the lambda
with minimum average cross validation error and the largest lambda
within one standard error of the minimum.
lambda |
The actual |
cvm |
The mean of cross validation errors for each |
cvsd |
The standard error of cross validaiton errors for each |
lambda.min |
The |
lambda.1se |
The largest |
catch.fit |
The fitted |
Yuqing Pan, Qing Mai, Xin Zhang
Pan, Y., Mai, Q., and Zhang, X. (2018) Covariate-Adjusted Tensor Classification in High-Dimensions, arXiv:1805.04421.
n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars), nrow=n, ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2),nrow=n,ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,], dim=c(p,p,p)) } objcv <- cv.catch(x, z, y=y)
n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars), nrow=n, ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2),nrow=n,ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,], dim=c(p,p,p)) } objcv <- cv.catch(x, z, y=y)
Predict categorical responses on new data given the fitted model input.
## S3 method for class 'catch' predict(object, newx, z = NULL, ztest = NULL, gamma = NULL,...)
## S3 method for class 'catch' predict(object, newx, z = NULL, ztest = NULL, gamma = NULL,...)
object |
Input |
newx |
Input adjusted testing tensor or matrix list. Each element of the list is a tensor. The tensor should of the same dimension as training data. |
z |
Input training covariates matrix. |
ztest |
Input testing covariates matrix. |
gamma |
Coefficients of covariates obtained from |
... |
Other arguments that can be passed to |
The function fits LDA model on selected discriminant vectors. Call predict
or predict.catch
to perform predictions.
There are two ways to make predictions. One way is to directly predict at the same time as fitting model by catch
since predict.catch
has already been embedded in catch
and it will predicts response when testing data is provided. The other way is to first use adjten
to adjuste tensor and catch
to fit model. predict.catch
will take the input adjusted tensor list newx
, covariate coefficient gamma
from adjten
and the fitted model from catch
to perform prediction. The prediction is identical to providing catch
testing data.
pred |
Predicted response of |
Yuqing Pan, Qing Mai, Xin Zhang
Pan, Y., Mai, Q., and Zhang, X. (2018) Covariate-Adjusted Tensor Classification in High-Dimensions, arXiv:1805.04421.
#generate training data n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars),nrow=n,ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2),nrow=n,ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,],dim=c(p,p,p)) } #generate testing data newx <- array(list(),n) vec_newx <- matrix(rnorm(n*nvars),nrow=n,ncol=nvars) vec_newx[1:10,] <- vec_newx[1:10,]+2 newz <- matrix(rnorm(n*2),nrow=n,ncol=2) newz[1:10,] <- newz[1:10,]+0.5 for (i in 1:n){ newx[[i]] <- array(vec_newx[i,],dim=c(p,p,p)) } #Make adjustment and fit model obj <- adjten(x, z, y, newx, newz) fit <- catch(x, z, y) #Predict pred <- predict.catch(fit, obj$testxres, z, newz, obj$gamma) #The adjusting, fitting model and predicting step can also be completed #by one command. pred <- catch(x, z, y, newx, newz)$pred
#generate training data n <- 20 p <- 4 k <- 2 nvars <- p*p*p x <- array(list(),n) vec_x <- matrix(rnorm(n*nvars),nrow=n,ncol=nvars) vec_x[1:10,] <- vec_x[1:10,]+2 z <- matrix(rnorm(n*2),nrow=n,ncol=2) z[1:10,] <- z[1:10,]+0.5 y <- c(rep(1,10),rep(2,10)) for (i in 1:n){ x[[i]] <- array(vec_x[i,],dim=c(p,p,p)) } #generate testing data newx <- array(list(),n) vec_newx <- matrix(rnorm(n*nvars),nrow=n,ncol=nvars) vec_newx[1:10,] <- vec_newx[1:10,]+2 newz <- matrix(rnorm(n*2),nrow=n,ncol=2) newz[1:10,] <- newz[1:10,]+0.5 for (i in 1:n){ newx[[i]] <- array(vec_newx[i,],dim=c(p,p,p)) } #Make adjustment and fit model obj <- adjten(x, z, y, newx, newz) fit <- catch(x, z, y) #Predict pred <- predict.catch(fit, obj$testxres, z, newz, obj$gamma) #The adjusting, fitting model and predicting step can also be completed #by one command. pred <- catch(x, z, y, newx, newz)$pred