[Picante-commits] r215 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Feb 11 23:56:05 CET 2010
Author: skembel
Date: 2010-02-11 23:56:05 +0100 (Thu, 11 Feb 2010)
New Revision: 215
Modified:
pkg/R/phylosignal.R
pkg/R/raoD.R
pkg/man/Kcalc.Rd
pkg/man/data.checking.Rd
pkg/man/multiPhylosignal.Rd
pkg/man/phylosignal.Rd
Log:
Add checks for phylogeny-data label match to Kcalc, phylosignal, multiPhylosignal
Modified: pkg/R/phylosignal.R
===================================================================
--- pkg/R/phylosignal.R 2010-02-11 07:01:01 UTC (rev 214)
+++ pkg/R/phylosignal.R 2010-02-11 22:56:05 UTC (rev 215)
@@ -1,4 +1,11 @@
-Kcalc <- function(x,phy) {
+Kcalc <- function(x, phy, checkdata=TRUE) {
+
+ if (checkdata) {
+ dat <- match.phylo.data(phy, x)
+ x <- dat$data
+ phy <- dat$phy
+ }
+
mat <- vcv.phylo(phy, cor=TRUE) # correlation matrix
ntax = length(phy$tip.label)
ntax1 = ntax-1
@@ -23,14 +30,20 @@
}
pic.variance <- function(x,phy,scaled=TRUE) {
- pics <- pic(x,phy,scaled)
+ pics <- pic(x, phy, scaled)
N <- length(pics)
- sum(pics^2) / (N -1)
+ sum(pics^2) / (N-1)
}
-phylosignal <- function(x,phy,reps=999,...) {
+phylosignal <- function(x, phy, reps=999, checkdata=TRUE, ...) {
- K <- Kcalc(x,phy)
+ if (checkdata) {
+ dat <- match.phylo.data(phy, x)
+ x <- dat$data
+ phy <- dat$phy
+ }
+
+ K <- Kcalc(x, phy, checkdata=FALSE)
if (!is.vector(x)) {
x.orig <- x
@@ -56,8 +69,11 @@
}
-'multiPhylosignal' <-
-function(x,phy,...) {
+multiPhylosignal <- function(x, phy, checkdata=TRUE, ...) {
+
+ if (!(is.data.frame(x) | is.matrix(x))) {
+ stop("Expecting trait data in data.frame or matrix format")
+ }
trait <- x[,1]
names(trait) <- row.names(x)
pruned <- prune.missing(trait,phy)
@@ -66,8 +82,9 @@
for (i in 2:length(colnames(x))) {
trait <- x[,i]
names(trait) <- row.names(x)
- pruned <- prune.missing(trait,phy)
- output <- rbind(output,phylosignal(pruned$data,pruned$tree,...))
+ pruned <- prune.missing(trait, phy)
+ trait <- trait[phy$tip.label]
+ output <- rbind(output, phylosignal(pruned$data, pruned$tree, checkdata=FALSE, ...))
}
}
data.frame(output,row.names=colnames(x))
Modified: pkg/R/raoD.R
===================================================================
--- pkg/R/raoD.R 2010-02-11 07:01:01 UTC (rev 214)
+++ pkg/R/raoD.R 2010-02-11 22:56:05 UTC (rev 215)
@@ -51,7 +51,7 @@
res$total <- sum ( tij * outer(as.vector(t(x.combined)),as.vector(t(x.combined))) )
- res$alpha <- sum(res$D * samp.relabund)
+ res$alpha <- sum(res$Dkk * samp.relabund)
res$beta <- res$total - res$alpha
Modified: pkg/man/Kcalc.Rd
===================================================================
--- pkg/man/Kcalc.Rd 2010-02-11 07:01:01 UTC (rev 214)
+++ pkg/man/Kcalc.Rd 2010-02-11 22:56:05 UTC (rev 215)
@@ -6,12 +6,13 @@
Calculates K statistic of phylogenetic signal
}
\usage{
-Kcalc(x, phy)
+Kcalc(x, phy, checkdata=TRUE)
}
\arguments{
\item{x}{ Vector or data.frame of trait data (in phylo\$tip.label order) }
\item{phy}{ phylo object }
+ \item{checkdata}{ Check for match between trait and phylogeny taxa labels using \code{\link{match.phylo.data}}? (default=TRUE)}
}
\value{
@@ -24,7 +25,6 @@
\author{ Simon Blomberg <s.blomberg1 at uq.edu.au> and David Ackerly <dackerly at berkeley.edu> }
\seealso{ \code{\link{phylosignal}} }
-\section{Warning }{ Assumes that trait data are sorted in the same order as phylo\$tip.label }
\examples{
randtree <- rcoal(20)
randtraits <- evolve.brownian(randtree)
Modified: pkg/man/data.checking.Rd
===================================================================
--- pkg/man/data.checking.Rd 2010-02-11 07:01:01 UTC (rev 214)
+++ pkg/man/data.checking.Rd 2010-02-11 22:56:05 UTC (rev 215)
@@ -36,9 +36,10 @@
If trait data or distance matrix lack names, a warning is issued and the data are assumed to be sorted in the same order as the phylogeny's tip labels or community's column labels.
-These utility functions are used by several of the functions that assume taxa labels in phylogeny and data match, including \code{\link{Kcalc}}, \code{\link{phylosignal}}, and \code{\link{raoD}}.
+These utility functions are used by several functions that assume taxa labels in phylogeny and data match, including \code{\link{Kcalc}}, \code{\link{phylosignal}}, and \code{\link{raoD}}.
}
\author{ Steven Kembel <skembel at uoregon.edu> }
+\seealso{\code{\link{prune.missing}}, \code{\link{prune.sample}}}
\examples{
data(phylocom)
match.phylo.comm(phylocom$phylo, phylocom$sample)
Modified: pkg/man/multiPhylosignal.Rd
===================================================================
--- pkg/man/multiPhylosignal.Rd 2010-02-11 07:01:01 UTC (rev 214)
+++ pkg/man/multiPhylosignal.Rd 2010-02-11 22:56:05 UTC (rev 215)
@@ -5,16 +5,16 @@
Calculates phylogenetic signal for data.frame of traits. Traits may have missing values in which case the tree will be pruned prior to calculating phylogenetic signal for each trait.
}
\usage{
-multiPhylosignal(x, phy, ...)
+multiPhylosignal(x, phy, checkdata=TRUE, ...)
}
\arguments{
\item{x}{ Data frame of trait data (traits in columns) with row names corresponding to tip.labels}
\item{phy}{ phylo object }
+ \item{checkdata}{ Check for match between trait and phylogeny taxa labels using \code{\link{match.phylo.data}}? (default=TRUE)}
\item{...}{ Additional arguments to \link{phylosignal} }
}
\value{
Returns a data frame with phylogenetic signal results for each trait
}
-\section{Warning }{ Assumes that trait data are sorted in the same order as phylo tip.label }
\author{ Steven Kembel <skembel at uoregon.edu> }
\keyword{univar}
Modified: pkg/man/phylosignal.Rd
===================================================================
--- pkg/man/phylosignal.Rd 2010-02-11 07:01:01 UTC (rev 214)
+++ pkg/man/phylosignal.Rd 2010-02-11 22:56:05 UTC (rev 215)
@@ -6,13 +6,14 @@
Calculates K statistic of phylogenetic signal as well as P-value based on variance of phylogenetically independent contrasts relative to tip shuffling randomization.
}
\usage{
-phylosignal(x, phy, reps = 999, ...)
+phylosignal(x, phy, reps = 999, checkdata=TRUE, ...)
}
\arguments{
\item{x}{ Trait vector (same order as phy\$tip.label) }
\item{phy}{ phylo object }
\item{reps}{ Number of randomizations }
+ \item{checkdata}{ Check for match between trait and phylogeny taxa labels using \code{\link{match.phylo.data}}? (default=TRUE)}
\item{...}{ Additional arguments passed to pic }
}
\value{
@@ -28,7 +29,6 @@
Blomberg, S. P., T. Garland, Jr., and A. R. Ives. 2003. Testing for phylogenetic signal in comparative data: behavioral traits are more labile. Evolution 57:717-745. }
\author{ Steven Kembel <skembel at uoregon.edu> }
\seealso{ \code{\link{Kcalc}} }
-\section{Warning }{ Assumes that trait data are sorted in the same order as phylo\$tip.label }
\examples{
randtree <- rcoal(20)
randtraits <- evolve.brownian(randtree)
More information about the Picante-commits
mailing list