sizeAdj

Function to size adjust variables.

Arguments:

x: the m by n matrix of m specimens/taxa and n variables

method: either of the following: "GM", divide each variable by the geometric mean (GM) of the variables (Mosimann, 1970); "logGM", take the logarithm of the Mosimann variable (i.e., log [V/GM] or logV - logGM); "res", take the residuals from a regression of each variable V against the GM; "log_res", the residuals of the regression of logV against logGM; and "MQ", the morphological quotient (following encephalisation quotient) where the ratio of each V and the predicted value of V from a regression of logV against logGM is taken and standardised so that the expected value for a specimen of a certain size is 100, i.e., Vobserved/Vpredicted x 100. The default method is "GM".

##### Size adjustment #####

sizeAdj <- function(x,method="GM"){

X <- na.omit(x)

G <- exp(rowMeans(log(X),na.rm=T))

if(method=="GM"){

R <- X/G

return(R)

}

if(method=="logGM"){

R <- log(X,10) - log(G,10)

return(R)

}

if(method=="res"){

R <- matrix(nrow=length(X[,1]),ncol=length(X[1,]))

for(i in 1:length(X[1,])){

LM <- lm(X[,i]~G)

R[,i] <- LM$residuals

}

R <- data.frame(R,row.names=row.names(X))

colnames(R)<-colnames(X)

return(R)

}

if(method=="log_res"){

R <- matrix(nrow=length(X[,1]),ncol=length(X[1,]))

for(i in 1:length(X[1,])){

LM <- lm(log(X[,i],10)~log(G,10))

R[,i] <- LM$residuals

}

R <- data.frame(R,row.names=row.names(X))

colnames(R)<-colnames(X)

return(R)

}

if(method=="MQ"){

R <- matrix(nrow=length(X[,1]),ncol=length(X[1,]))

for(i in 1:length(X[1,])){

LM <- lm(log(X[,i],10)~log(G,10))

Q <- (X[,i]/(10^LM$fitted))*100

R[,i] <- round(Q,0)

}

R <- data.frame(R,row.names=row.names(X))

colnames(R)<-colnames(X)

return(R)

}

}

##### Function by Manabu Sakamoto, 2012: manabu.sakamoto@gmail.com