# liamrevell/phytools

update multi.mantel with object class & S3 methods

liamrevell committed Nov 29, 2017
1 parent 94abc4f commit 6a8076f4f0fdac73800b2d7370e8337937c4a3af
Showing with 52 additions and 6 deletions.
1. +1 −1 DESCRIPTION
2. +3 −0 NAMESPACE
3. +41 −4 R/multi.mantel.R
4. +7 −1 man/multi.mantel.Rd
 @@ -1,5 +1,5 @@ Package: phytools Version: 0.6-47 Version: 0.6-48 Date: 2017-11-29 Title: Phylogenetic Tools for Comparative Biology (and Other Things) Author: Liam J. Revell
 @@ -131,6 +131,9 @@ S3method(print, phyl.cca) S3method(print, anc.Bayes) S3method(plot, anc.Bayes) S3method(print, phyl.pairedttest) S3method(print, multi.mantel) S3method(residuals, multi.mantel) S3method(fitted, multi.mantel) importFrom(animation, ani.options, ani.record, ani.replay, saveVideo) importFrom(ape, .PlotPhyloEnv, .uncompressTipLabel, ace, all.equal.phylo, as.DNAbin, as.phylo, bind.tree, branching.times, collapse.singles)
 @@ -1,5 +1,5 @@ # function for multiple matrix regression with P-values computed by Mantel permutation of the dependent matrix # written by Liam J. Revell 2012 ## function for multiple matrix regression with P-values computed by Mantel permutation of the dependent matrix ## written by Liam J. Revell 2012, 2017 multi.mantel<-function(Y,X,nperm=1000){ y<-unfoldLower(Y) @@ -29,14 +29,17 @@ multi.mantel<-function(Y,X,nperm=1000){ names(fstatistic)<-NULL residuals<-foldtoLower(fit\$residuals); attr(residuals,"Labels")<-rownames(Y) fitted.values<-foldtoLower(fit\$fitted.values); attr(fitted.values,"Labels")<-rownames(Y) return(list(r.squared=r.squared, object<-list(r.squared=r.squared, coefficients=coefficients, tstatistic=tstatistic, fstatistic=fstatistic, probt=pT, probF=pF, residuals=residuals, fitted.values=fitted.values)) fitted.values=fitted.values, nperm=nperm) class(object)<-"multi.mantel" object } # function unfolds the sub-diagonal of a "dist" object or symmetric matrix into a vector @@ -62,3 +65,37 @@ foldtoLower<-function(x){ } return(as.dist(X)) } ## S3 methods (added 2017) print.multi.mantel<-function(x,...){ if(hasArg(digits)) digits<-list(...)\$digits else digits<-6 star<-function(p){ obj<-if(p>0.1) "" else if(p<=0.1&&p>0.05) "." else if(p<=0.05&&p>0.01) "*" else if(p<=0.01&&p>0.001) "**" else if(p<=0.001) "***" obj } cat("\nResults from a (multiple) Mantel regression using \"multi.mantel\":\n\n") cat("Coefficients:\n") object<-data.frame(x\$coefficients, x\$tstatistic,x\$probt, sapply(x\$probt,star)) rownames(object)<-names(x\$coefficients) colnames(object)<-c("Estimate","t value","Pr(>|t|)","") print(object) cat("---\n") cat(paste("Signif. codes: 0 \u2018***\u2019 0.001 \u2018**\u2019 0.01", "\u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n")) cat(paste("Pr(>|t|) based on",x\$nperm, "(Mantel) permutations of rows & columns together in Y.\n\n")) cat(paste("Multiple R-squared:",round(x\$r.squared,digits),"\n")) cat(paste("F-statistic: ",round(x\$fstatistic,digits), ", p-value (based on ",x\$nperm," permutations): ", x\$probF,"\n\n",sep="")) } residuals.multi.mantel<-function(object,...) object\$residuals fitted.multi.mantel<-function(object,...) object\$fitted.values
 @@ -13,7 +13,7 @@ multi.mantel(Y, X, nperm=1000) This function conducting a multiple matrix regression (partial Mantel test) and uses Mantel (1967) permutations to test the significance of the model and individual coefficients. It also returns the residual and predicted matrices. } \value{ A list with the following components: An object of class \code{"multi.mantel"} consisting of the following elements: \item{r.squared}{multiple R-squared.} \item{coefficients}{model coefficients, including intercept.} \item{tstatistic}{t-statistics for model coefficients.} @@ -22,7 +22,13 @@ multi.mantel(Y, X, nperm=1000) \item{probF}{probability of F, based on Mantel permutations.} \item{residuals}{matrix of residuals.} \item{predicted}{matrix of predicted values.} \item{nperm}{tne number of permutations used.} } \details{ Printing the object to screen will result in a summary of the analysis similar to \code{summary.lm}, but with p-values derived from Mantel permutations. Methods \code{residuals} and \code{fitted} can be used to return residual and fitted matrices, respectively. } \references{ Mantel, N. (1967) The detection of disease clustering and a generalized regression approach. \emph{Cancer Research}, \bold{27}, 209--220.