"validMBnetwork" <- function(object){ if(is.null(object@N) || is.na(object@N) || (object@N < 0) || (object@N != as.integer(object@N))) paste("@N must be a positive integer",sep="") else if(!all(c(length(object@Names),length(object@States),ncol(object@Cpds),ncol(object@Margs),length(object@Pvals)) %in% object@N)) paste("Incompatible dimensions of some attributes (must all match @N)",sep="") else if(!all(object@States %in% c(0,1,NA)) || !is.integer(object@States)) paste("@States can only have 0,1, or NA values of type integer",sep="") else if(!all(c(nrow(object@Cpds),nrow(object@Margs),nrow(object@Counts)) %in% 2)) paste("@Cpds, @Counts, and @Margs must have 2 rows",sep="") else if(!is.numeric(object@Cpds) || !is.numeric(object@Margs) || !is.numeric(object@Counts) || !is.numeric(object@Pvals)) paste("@Cpds, @Counts, @Margs, and @Pvals must be numeric",sep="") else if((object@N>0) && !all(is.na(object@Margs[1,]) == is.na(object@Margs[2,]))) paste("Both rows of any given Marg must either be defined or not defined",sep="") else if((object@N>0) && !all(is.na(object@Cpds[1,]) == is.na(object@Cpds[2,]))) paste("Both rows of any given Cpd must either be defined or not defined",sep="") else if((object@N>0) && !all(is.na(object@Counts[1,]) == is.na(object@Counts[2,]))) paste("Both rows of any given Count must either be defined or not defined",sep="") else if(!all(c(object@Cpds,object@Margs)>=0,na.rm=TRUE) || !all(c(object@Cpds,object@Margs)<=1,na.rm=TRUE)) paste("@Cpds and @Margs must all be between 0 and 1, or NA",sep="") else if(!all(c(object@Counts)>=0,na.rm=TRUE)) paste("@Counts must all be >= 0 or NA",sep="") else if((object@N>0) && !all(colSums(object@Margs) == 1,na.rm=TRUE)) paste("@Margs column sums, if defined, must all be 1",sep="") else if(!all((object@Pvals >= 0) & (object@Pvals <= 1),na.rm=TRUE)) paste("@Pvals must all be between 0 and 1 or NA",sep="") else TRUE }