## Function for computing the ratio of between-groups to ## within-groups sum of squares. ## ## TAKEN FROM THE SMA PACKAGE (BIOCONDUCTOR). # \references{S. Dudoit, J. Fridlyand, and T. P. Speed. Comparison of # Discrimination Methods for the Classification of Tumors Using Gene # Expression Data. June 2000. (Statistics, UC Berkeley, Tech Report \# # 576). } # # \author{ # Sandrine Dudoit, \email{sandrine@stat.berkeley.edu} \cr # Jane Fridlyand, \email{janef@stat.berkeley.edu} # } bwss<-function(x, cl) { # Compute BSS/WSS for each row of a matrix which may have NA # Columns have labels cl=consecutive integers K <- max(cl) - min(cl) + 1 tvar <- apply(x, 1, var.na) tn <- apply(!is.na(x), 1, sum) wvar <- matrix(0, nrow(x), K) wn <- matrix(0, nrow(x), K) for(i in (1:K)) { if(sum(cl == (i + min(cl) - 1)) == 1) { wvar[, i] <- 0 wn[, i] <- 1 } if(sum(cl == (i + min(cl) - 1)) > 1) { wvar[, i] <- apply(x[, cl == (i + min(cl) - 1)], 1, var.na) wn[, i] <- apply(!is.na(x[, cl == (i + min(cl) - 1)]), 1, sum) } } WSS <- apply(wvar * (wn - 1), 1, sum.na) TSS <- tvar * (tn - 1) BSS<- TSS - WSS BW <- BSS/WSS list(wn=wn,bw=BW,bss=BSS,wss=WSS,tss=TSS,tvar=tvar) } ## Other functions taken from the same SMA package. mean.na <- function(x,...) { mean(x[!(is.na(x) | is.infinite(x))]) } var.na <- function(x) { res <- NA tmp <- !(is.na(x) | is.infinite(x)) if(sum(tmp) > 1) res <- var(x[tmp]) res } cor.na <- function(x) { cor(x, use="pairwise.complete.obs") } sum.na <- function(x,...) { res <- NA tmp <- !(is.na(x) | is.infinite(x)) if(sum(tmp) > 0) res <- sum(x[tmp]) res } length.na <- function(x, ...) { tmp <- !(is.na(x) | is.infinite(x)) length(x[tmp],...) } log.na <- function(x, ...) { log(ifelse(x > 0, x, NA), ...) }