# Rajarshi Guha # 8/12/2004 nbr.behavior <- function(act, desc, dist=FALSE, do.plot=TRUE, ...) { if (length(act) != nrow(desc)) { stop('Length of activity vector and rows of descriptor matrix must match') } if (!is.matrix(desc) && !is.data.frame(desc)) { stop('desc should be a matrix or data.frame') } x <- numeric(length(act)*(length(act)-1)/2) y <- numeric(length(act)*(length(act)-1)/2) cnt <- 1 # see if we were supplied a distance matrix if (!dist) { dm <- as.matrix(dist(desc)) } else { dm <- desc } for (i in 1:(length(act)-1)) { for (j in (i+1):length(act)) { x[cnt] <- dm[i,j] y[cnt] <- abs(act[i] - act[j]) cnt <- cnt + 1 } } if (do.plot) { par(pty='s',pch=19,col='black') plot(x,y, xlab='Pairwise Distance\'s', ylab='Absolute Difference in Activity', ...) } list(x=x,y=y) }