R/preProcessing.R

Defines functions preCheck

Documented in preCheck

#' @include generics.R
#'
NULL

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Functions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#' Parameter check 
#' @param X input matrix for dataset1
#' @param Y input matrix for dataset2
#' @param Z0 input initial transition matrix 
#' @param num.D number of reduced dimensions between X and Z0
#' @param num.E number of reduced dimensions between Y and Z0
#' @param num.iteration maximal number of iteration [default 100]
#'
#' @return Return TRUE if all parameters are correct

preCheck <- function(X=NULL, Z0=NULL, Y=NULL, num.D = 6, 
    num.E = 6, num.iteration = 100){

    if (!is.matrix(X)){
        stop("Please input X as a matrix!")
    }
    if (!is.matrix(Z0)){
        stop("Please input Z0 as a matrix!")
    }
    if (!is.matrix(Y)){
        stop("Please input Y as a matrix!")
    }

    if(dim(X)[1]!=dim(Z0)[1]){
        stop("X and Z0 should have the same row number!")
    }
    if(dim(Z0)[2]!=dim(Y)[2]){
        stop("Z0 and Y should have the same column number!")
    }
    tp <- min(dim(X)[2], dim(Z0)[2])
    if(!all.equal(num.D, as.integer(num.D)) || num.D<0 || num.D >tp){
        stop(paste("The num.D should be integer ranging from 2 to", tp))
    }

    tp <- min(dim(Z0)[1], dim(Y)[1])

    if(!all.equal(num.E, as.integer(num.E)) || num.E<0 || num.E >tp){
        stop(paste("The num.E should be integer ranging from 2 to", tp))
    }

    return(TRUE)
}
jinzhuangdou/DCCA documentation built on June 29, 2020, 12:54 a.m.