Permalink
Browse files

S3 methods for phyl.RMA

  • Loading branch information...
liamrevell committed Dec 29, 2016
1 parent 280eb00 commit c267edce7612f1cbaba4638e2e65e9c370d8d8b1
Showing with 49 additions and 7 deletions.
  1. +4 −4 DESCRIPTION
  2. +3 −0 NAMESPACE
  3. +36 −3 R/phyl.RMA.R
  4. +6 −0 man/phyl.RMA.Rd
View
@@ -1,6 +1,6 @@
Package: phytools
Version: 0.5-67
Date: 2016-12-27
Version: 0.5-68
Date: 2016-12-29
Title: Phylogenetic Tools for Comparative Biology (and Other Things)
Author: Liam J. Revell
Maintainer: Liam J. Revell <liam.revell@umb.edu>
@@ -56,6 +56,6 @@ Description: Package contains various functions for phylogenetic analysis.
research.
License: GPL (>= 2)
URL: http://github.com/liamrevell/phytools
Packaged: 2016-12-27 12:00:00 EST
Packaged: 2016-12-29 12:00:00 EST
Repository:
Date/Publication: 2016-12-27 12:00:00 EST
Date/Publication: 2016-12-29 12:00:00 EST
View
@@ -95,6 +95,9 @@ S3method(plot, phyloScattergram)
S3method(print, phyloScattergram)
S3method(di2multi, simmap)
S3method(print, aic.w)
S3method(print, phyl.RMA)
S3method(coef, phyl.RMA)
S3method(residuals, phyl.RMA)
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)
View
@@ -2,13 +2,15 @@
## written by Liam Revell 2010, 2011, 2012, 2015, 2016
phyl.RMA<-function(x,y,tree,method="BM",lambda=NULL,fixed=FALSE,h0=1.0){
if(!inherits(tree,"phylo")) stop("tree should be an object of class \"phylo\".")
if(!inherits(tree,"phylo"))
stop("tree should be an object of class \"phylo\".")
x<-x[tree$tip.label]; y<-y[tree$tip.label]
# bind the x & y into columns
X<-cbind(x,y)
if(method=="lambda")
if(fixed==FALSE)
result<-optimize(f=likMlambda,interval=c(0,1),X=X,C=vcv(tree),maximum=TRUE)
result<-optimize(f=likMlambda,interval=c(0,1),X=X,C=vcv(tree),
maximum=TRUE)
else
result<-list(objective=likMlambda(lambda,X,vcv(tree)),maximum=lambda)
else if(method=="BM")
@@ -31,5 +33,36 @@ phyl.RMA<-function(x,y,tree,method="BM",lambda=NULL,fixed=FALSE,h0=1.0){
df<-2+(Ntip(tree)-2)/(1+0.5*r2)
P<-2*pt(T,df=df,lower.tail=FALSE)
test<-c(r2,T,df,P); names(test)<-c("r2","T","df","P")
return(list(RMA.beta=c(beta0,beta1),V=temp$R,lambda=est.lambda,logL=as.numeric(result$objective),test=test,resid=as.matrix(r)))
object<-list(RMA.beta=c(beta0,beta1),V=temp$R,lambda=est.lambda,
logL=as.numeric(result$objective),test=test,h0=h0,
resid=as.matrix(r))
class(object)<-"phyl.RMA"
object
}
print.phyl.RMA<-function(x,...){
cat("\nCoefficients:\n")
print(coef(x))
cat("\nVCV matrix:\n")
print(x$V)
cat("\n")
if(is.null(x$lambda))
cat("Model for the covariance structure of the error is \"BM\"\n\n")
else {
cat("Model for the covariance structure of the error is \"lambda\"\n")
cat("\nEstimate(s):\n")
print(setNames(c(x$lambda,x$logL),c("lambda","log(L)")))
cat("\n")
}
cat("Hypothesis test based on Clarke (1980; Biometrika):\n")
print(x$test)
cat(paste("\nNote that the null hypothesis test is h0 =",x$h0,
"\n\n"))
}
coef.phyl.RMA<-function(object,...){
val<-setNames(object$RMA.beta,c("(Intercept)","x"))
val
}
residuals.phyl.RMA<-function(object,...) object$resid[,1]
View
@@ -18,6 +18,8 @@ phyl.RMA(x, y, tree, method="BM", lambda=NULL, fixed=FALSE, h0=1.0)
}
\details{
Optionally jointly estimates lambda if \code{method="lambda"}. Likelihood optimization of lambda is performed using \code{\link{optimize}} on the interval (0,1). Note that some statistician think there is \emph{never} a condition in which a reduced-major-axis regression should be used.
The statistical hypothesis testing is based on Clarke (1980; reviewed in McArdle 1988), which differs from some other implementations of non-phylogenetic major axis regression in R.
}
\value{
A list with the following components:
@@ -29,6 +31,10 @@ phyl.RMA(x, y, tree, method="BM", lambda=NULL, fixed=FALSE, h0=1.0)
\item{resid}{a vector of residuals for \code{y} given \code{x}.}
}
\references{
Clarke, M. R. B. (1980) The reduced major axis of a bivariate sample. \emph{Biometrika}, \bold{67}, 441-446.
McArdle, B. H. (1988) The structural relationship: Regression in biology. \emph{Can. J. Zool.}, \bold{66}, 2329-2339.
Revell, L. J. (2012) phytools: An R package for phylogenetic comparative biology (and other things). \emph{Methods Ecol. Evol.}, \bold{3}, 217-223.
}
\author{Liam Revell \email{liam.revell@umb.edu}}

0 comments on commit c267edc

Please sign in to comment.