Skip to content
Browse files

new scores method for phyl.pca

  • Loading branch information...
liamrevell committed Aug 21, 2019
1 parent 68ae5cf commit bb71dab53f8d0d5b466eceda5e3bba9c50520e77
Showing with 51 additions and 8 deletions.
  1. +4 −4 DESCRIPTION
  2. +3 −2 NAMESPACE
  3. +38 −1 R/phyl.pca.R
  4. +6 −1 man/phyl.pca.Rd
@@ -1,6 +1,6 @@
Package: phytools
Version: 0.7-02
Date: 2019-7-31
Version: 0.7-03
Date: 2019-8-21
Title: Phylogenetic Tools for Comparative Biology (and Other Things)
Author: Liam J. Revell
Maintainer: Liam J. Revell <>
@@ -13,6 +13,6 @@ ZipData: no
Description: A wide range of functions for phylogenetic analysis. Functionality is concentrated in phylogenetic comparative biology, but also includes a diverse array of methods for visualizing, manipulating, reading or writing, and even inferring phylogenetic trees and data. Included among the functions in phylogenetic comparative biology are various for ancestral state reconstruction, model-fitting, simulation of phylogenies and data, and multivariate analysis. There are a broad range of plotting methods for phylogenies and comparative data which include, but are not restricted to, methods for mapping trait evolution on trees, for projecting trees into phenotypic space or a geographic map, and for visualizing correlated speciation between trees. Finally, there are a number of functions for reading, writing, analyzing, inferring, simulating, and manipulating phylogenetic trees and comparative data not covered by other packages. For instance, there are functions for randomly or non-randomly attaching species or clades to a phylogeny, for estimating supertrees or consensus phylogenies from a set, for simulating trees and phylogenetic data under a range of models, and for a wide variety of other manipulations and analyses that phylogenetic biologists might find useful in their research.
License: GPL (>= 2)
Packaged: 2019-7-31 12:00:00 EST
Packaged: 2019-8-21 12:00:00 EST
Date/Publication: 2019-7-31 12:00:00 EST
Date/Publication: 2019-8-21 12:00:00 EST
@@ -26,8 +26,8 @@ export(plotTree.singletons, plotTree.splits, plotTree.wBars, posterior.evolrate,
export(ratebystate, ratebytree, rateshift, read.newick, read.simmap, reorder.backbonePhylo, reorderSimmap, rep.multiPhylo, rep.phylo)
export(repPhylo, reroot, rerootingMethod, rescaleSimmap, resolveAllNodes, resolveNode, rotate.multi, rotateNodes,
export(roundBranches, roundPhylogram, rstate)
export(sampleFrom, setMap, sim.corrs, sim.ctt, sim.history, sim.Mk, sim.multiCtt, sim.multiMk, sim.ratebystate, sim.rates, skewers, splitEdgeColor)
export(splitplotTree, splitTree, starTree, strahlerNumber)
export(sampleFrom, scores.phyl.pca, setMap, sim.corrs, sim.ctt, sim.history, sim.Mk, sim.multiCtt, sim.multiMk, sim.ratebystate, sim.rates, skewers)
export(splitEdgeColor, splitplotTree, splitTree, starTree, strahlerNumber)
export(threshBayes, threshDIC, threshState, tiplabels.cophylo, tipRotate, to.matrix, treeSlice)
@@ -175,6 +175,7 @@ S3method(logLik, fitDiversityModel)
S3method(print, gammatest)
S3method(print, geo.legend)
S3method(print, geo.palette)
S3method(scores, phyl.pca)

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,
@@ -1,7 +1,7 @@
## function to perform phylogenetic principal components analysis
## multiple morphological traits in Y
## also can use lambda transformation in which lambda is optimized by ML or REML (in progress)
## written by Liam Revell 2010, 2011, 2013, 2015, 2016, 2017 ref. Revell (2009; Evolution)
## written by Liam Revell 2010, 2011, 2013, 2015, 2016, 2017, 2019 ref. Revell (2009; Evolution)

## get optional argument
@@ -91,6 +91,9 @@ phyl.pca<-function(tree,Y,method="BM",mode="cov",...){
## assign class attribute (for S3 methods)
# return obj
@@ -176,3 +179,37 @@ plot.phyl.pca<- function(x,...){

## S3 scores method to extract or compute scores

scores<-function(object,...) UseMethod("scores")

"scores does not know how to handle objects of class ",

else newdata<-NULL
if(!is.matrix(newdata)) newdata<-as.matrix(newdata)
if(nrow(newdata)==ncol(object$Evec)) newdata<-t(newdata)
else stop("Dimensions of newdata incorrect.")
} else Y<-newdata-A
} else {

@@ -1,17 +1,20 @@
\title{Phylogenetic principal components analysis}
phyl.pca(tree, Y, method="BM", mode="cov", ...)
\method{biplot}{phyl.pca}(x, ...)
\method{scores}{phyl.pca}(object, ...)
\item{tree}{phylogeny as an object of class \code{"phylo"}.}
\item{Y}{data matrix with traits in columns.}
\item{method}{method to obtain the correlation structure: can be \code{"BM"} or \code{"lambda"}.}
\item{mode}{is the mode for the PCA: can be \code{"cov"} or \code{"corr"}.}
\item{x}{object of class \code{"phyl.pca"} for \code{biplot.phyl.pca}.}
\item{x}{object of class \code{"phyl.pca"} for \code{biplot} method.}
\item{object}{object of class \code{"phyl.pca"} for \code{scores} method.}
\item{...}{for S3 plotting method \code{biplot.phyl.pca}, other arguments to be passed to \code{\link{biplot}}.}
@@ -21,6 +24,8 @@ phyl.pca(tree, Y, method="BM", mode="cov", ...)
If \code{method="lambda"} then \eqn{\lambda} will be optimized on the interval (0,1) using \code{\link{optimize}}. Optimization method can be set using the option \code{opt} which can take values \code{"ML"}, \code{"REML"}, or \code{"fixed"}. If the last of these is selected than the user should also specify a value of \eqn{\lambda} to use via the argument \code{lambda}.

S3 methods (\code{print}, \code{summary}, and \code{biplot}) are modified from code provided by Joan Maspons and are based on the same methods for objects of class \code{"prcomp"}. Function \code{biplot} now permits the argument \code{choices} to be supplied, which should be a vector of length two indicated the two PC axes to be plotted.

S3 method \code{scores} extracts or computes (for a matrix of \code{newdata}) PC scores given an object of class \code{"phyl.pca"}.
An object of class \code{"phyl.pca"} consisting of a list with some or all of the following components:

0 comments on commit bb71dab

Please sign in to comment.
You can’t perform that action at this time.