[Ecopd-commits] r90 - branches/single-tree/inst/unitTests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Nov 18 22:03:45 CET 2009
Author: regetz
Date: 2009-11-18 22:03:45 +0100 (Wed, 18 Nov 2009)
New Revision: 90
Modified:
branches/single-tree/inst/unitTests/runit.indices.R
Log:
rewrote active unit tests to work with new phylo4com implementation
Modified: branches/single-tree/inst/unitTests/runit.indices.R
===================================================================
--- branches/single-tree/inst/unitTests/runit.indices.R 2009-11-18 20:07:25 UTC (rev 89)
+++ branches/single-tree/inst/unitTests/runit.indices.R 2009-11-18 21:03:45 UTC (rev 90)
@@ -1,167 +1,152 @@
#
-# --- Create test trees (ape::phylo objects) ---
+# --- Load and create test data ---
#
-weed.com <- read.table(textConnection(
- "plot cover taxa
- A 5 Centaurea_alba
- A 5 Silybum_marianum
- A 10 Taraxacum_officinale
- A 25 Torilis_arvensis
- A 55 Trifolium_repens
- B 35 Centaurea_alba
- B 35 Silybum_marianum
- B 15 Taraxacum_officinale
- B 10 Torilis_arvensis
- B 5 Trifolium_repens
- C 20 Centaurea_alba
- C 20 Silybum_marianum
- C 20 Taraxacum_officinale
- C 20 Torilis_arvensis
- C 20 Trifolium_repens"
- ), header=TRUE)
-closeAllConnections()
+data(weeds)
-weed.tree <- read.tree(text="(((Taraxacum_officinale:0.2601451047,(Silybum_marianum:0.1088645027,Centaurea_alba:0.1088645027)0.997000:0.151280602)0.547000:0.5232373813,Torilis_arvensis:0.783382486)0.878000:0.216617514,Trifolium_repens:1)1.000000:0.04059;")
+weeds.tree.nu <- read.tree(text="(((Taraxacum_officinale:0.058133000000000004,(Silybum_marianum:0.022662,Centaurea_alba:0.02092)0.997000:0.026418999999999998)0.547000:0.075571,Torilis_arvensis:0.105052)0.878000:0.037612,Trifolium_repens:0.25731000000000004)1.000000:0.04059;")
-weed.tree.notultra <- read.tree(text="(((Taraxacum_officinale:0.058133000000000004,(Silybum_marianum:0.022662,Centaurea_alba:0.02092)0.997000:0.026418999999999998)0.547000:0.075571,Torilis_arvensis:0.105052)0.878000:0.037612,Trifolium_repens:0.25731000000000004)1.000000:0.04059;")
+pcom <- phylo4com(weeds.tree, weeds.data$cover, weeds.data$plot,
+ weeds.data$taxa)
-comtrees <- phylo4com(weed.com$plot, weed.com$taxa, weed.com$cover,
- phylo4d(weed.tree))
+pcom.nu <- phylo4com(weeds.tree.nu, weeds.data$cover,
+ weeds.data$plot, weeds.data$taxa)
-comtrees.notultra <- phylo4com(weed.com$plot, weed.com$taxa,
- weed.com$cover, phylo4d(weed.tree.notultra))
-
#
# --- Test utility functions ---
#
-test.phylobase <- function() {
- checkTrue(unique(sapply(comtrees, class))=="phylo4d")
- checkTrue(unique(sapply(comtrees.notultra, class))=="phylo4d")
+test.phylo4com <- function() {
+ checkTrue(is(pcom, "phylo4com"))
+ checkTrue(is(pcom.nu, "phylo4com"))
}
test.abundance <- function() {
- checkEqualsNumeric(abundance(comtrees$A), c(10, 5, 5, 25, 55))
- checkEqualsNumeric(abundance(comtrees$B), c(15, 35, 35, 10, 5))
- checkEqualsNumeric(abundance(comtrees$C), c(20, 20, 20, 20, 20))
+ N <- data.frame(A=c(10, 5, 5, 25, 55), B=c(15, 35, 35, 10, 5),
+ C=c(20, 20, 20, 20, 20), row.names=tipLabels(pcom))
+ checkIdentical(abundance(pcom), N)
+ checkIdentical(abundance(pcom, "B"), N["B"])
}
-test.genera <- function() {
- target <- structure(c("Taraxacum", "Silybum", "Centaurea", "Torilis",
- "Trifolium"), .Names = c("1", "2", "3", "4", "5"))
- checkIdentical(genera(comtrees$A), target)
- checkIdentical(genera(comtrees$B), target)
- checkIdentical(genera(comtrees$C), target)
+test.presence <- function() {
+ P <- data.frame(A=c(1, 1, 1, 1, 1), B=c(1, 1, 1, 1, 1),
+ C=c(1, 1, 1, 1, 1), row.names=tipLabels(pcom))
+ checkIdentical(presence(pcom), P)
+ checkIdentical(presence(pcom, "B"), P["B"])
}
test.siteBySpecies <- function() {
- target <- structure(c(10, 5, 5, 25, 55, 15, 35, 35, 10, 5, 20, 20, 20,
- 20, 20), .Dim = c(5L, 3L), .Dimnames =
- list(c("Taraxacum_officinale", "Silybum_marianum", "Centaurea_alba",
- "Torilis_arvensis", "Trifolium_repens"), c("A", "B", "C")))
- checkIdentical(siteBySpecies(comtrees), t(target))
- checkIdentical(siteBySpecies(comtrees, transpose=TRUE), target)
- # presence/absence only
- target[] <- 1
- checkIdentical(siteBySpecies(comtrees, presence=TRUE, transpose=TRUE),
- target)
-
+ checkIdentical(siteBySpecies(pcom), t(as.matrix(abundance(pcom))))
+ checkIdentical(siteBySpecies(pcom, transpose=TRUE),
+ as.matrix(abundance(pcom)))
+ checkIdentical(siteBySpecies(pcom, presence.only=TRUE),
+ t(as.matrix(presence(pcom))))
}
test.richness <- function() {
- target <- structure(c(5L, 5L, 5L), .Names = c("A", "B", "C"))
- checkIdentical(richness(comtrees), target)
+ R <- structure(c(5, 5, 5), .Names = c("A", "B", "C"))
+ checkIdentical(richness(pcom), R)
}
+test.genera <- function() {
+ G <- structure(c("Taraxacum", "Silybum", "Centaurea", "Torilis",
+ "Trifolium"), .Names = c("1", "2", "3", "4", "5"))
+ checkIdentical(genera(pcom), list(A=G, B=G, C=G))
+ checkIdentical(genera(pcom, "B"), list(B=G))
+}
+
#
# --- Test ecoPD indices ---
#
test.pd <- function() {
- # Note: pd would be 3.1523920934 if root edge is included; MC confirms
+ # Note: pd would be higher if root edge is included; MC confirms
# that we don't want the root edge included
- checkEqualsNumeric(pd(comtrees$A), 3.1523920934)
- checkEqualsNumeric(pd(comtrees$B), 3.1523920934)
- checkEqualsNumeric(pd(comtrees$C), 3.1523920934)
+ PD <- setNames(rep(3.1523920934, 3), c("A", "B", "C"))
+ checkEqualsNumeric(pd(pcom), PD)
- checkEqualsNumeric(pd(comtrees.notultra$A), 0.603679)
- checkEqualsNumeric(pd(comtrees.notultra$B), 0.603679)
- checkEqualsNumeric(pd(comtrees.notultra$C), 0.603679)
+ PD.nu <- setNames(rep(0.603679, 3), c("A", "B", "C"))
+ checkEqualsNumeric(pd(pcom.nu), PD.nu)
}
-test.PAE <- function() {
- # was 1.716026353 when root edge was included
- checkEquals(PAE(comtrees$A), 1.716656575899907)
- # was 0.5478761669 when root edge was included
- checkEquals(PAE(comtrees$B), 0.547478222537882)
- # was 1.0 when root edge was included
- checkEquals(PAE(comtrees$C), 1.0)
+test.pae <- function() {
- checkEquals(PAE(comtrees.notultra$A), 1.880577959657120)
- checkEquals(PAE(comtrees.notultra$B), 0.517350975072873)
- checkEquals(PAE(comtrees.notultra$C), 1.000000000000000)
-}
+ # was c(1.716026353, 0.5478761669, 1.0) when root edge was included
+ PAE <- setNames(c(1.716656575899907, 0.547478222537882, 1.0),
+ c("A", "B", "C"))
+ checkEquals(pae(pcom), PAE)
-test.IAC <- function() {
- checkEquals(IAC(comtrees$A), 2.5)
- checkEquals(IAC(comtrees$B), 30.0)
- checkEquals(IAC(comtrees$C), 17.5)
- checkEquals(IAC(comtrees.notultra$A), 2.5)
- checkEquals(IAC(comtrees.notultra$B), 30.0)
- checkEquals(IAC(comtrees.notultra$C), 17.5)
+ PAE.nu <- setNames(c(1.880577959657120, 0.517350975072873, 1.0),
+ c("A", "B", "C"))
+ checkEquals(pae(pcom.nu), PAE.nu)
}
-test.ED <- function() {
+test.iac <- function() {
+ IAC <- setNames(c(2.5, 30.0, 17.5), c("A", "B", "C"))
+ checkEquals(iac(pcom), IAC)
- checkEqualsNumeric(ED(comtrees$A), c(0.488711943633333,
- 0.413071642633333, 0.413071642633333, 0.8375368645, 1))
- checkEqualsNumeric(ED(comtrees$B), c(0.488711943633333,
- 0.413071642633333, 0.413071642633333, 0.8375368645, 1))
- checkEqualsNumeric(ED(comtrees$C), c(0.488711943633333,
- 0.413071642633333, 0.413071642633333, 0.8375368645, 1))
+ IAC.nu <- setNames(c(2.5, 30.0, 17.5), c("A", "B", "C"))
+ checkEquals(iac(pcom.nu), IAC)
+}
- checkEquals(EED(comtrees$A), 0.955592201964205)
- checkEquals(EED(comtrees$B), 0.955592201964205)
- checkEquals(EED(comtrees$C), 0.955592201964205)
- checkEquals(HED(comtrees$A), 1.53796631866758)
- checkEquals(HED(comtrees$B), 1.53796631866758)
- checkEquals(HED(comtrees$C), 1.53796631866758)
+test.ed <- function() {
+ ED <- list(
+ A = setNames(c(0.488711943633333, 0.413071642633333,
+ 0.413071642633333, 0.8375368645, 1), tipLabels(weeds)),
+ B = setNames(c(0.488711943633333, 0.413071642633333,
+ 0.413071642633333, 0.8375368645, 1), tipLabels(weeds)),
+ C = setNames(c(0.488711943633333, 0.413071642633333,
+ 0.413071642633333, 0.8375368645, 1), tipLabels(weeds)))
+ checkEquals(ed(pcom), ED)
- checkEquals(EED(comtrees.notultra$A), 0.910003541733306)
- checkEquals(EED(comtrees.notultra$B), 0.910003541733306)
- checkEquals(EED(comtrees.notultra$C), 0.910003541733306)
- checkEquals(HED(comtrees.notultra$A), 1.46459420051489)
- checkEquals(HED(comtrees.notultra$B), 1.46459420051489)
- checkEquals(HED(comtrees.notultra$C), 1.46459420051489)
+ EED <- setNames(rep(0.955592201964205, 3), c("A", "B", "C"))
+ checkEquals(eed(pcom), EED)
+ HED <- setNames(rep(1.53796631866758, 3), c("A", "B", "C"))
+ checkEquals(hed(pcom), HED)
+
+ EED.nu <- setNames(rep(0.910003541733306, 3), c("A", "B", "C"))
+ checkEquals(eed(pcom.nu), EED.nu)
+ HED.nu <- setNames(rep(1.46459420051489, 3), c("A", "B", "C"))
+ checkEquals(hed(pcom.nu), HED.nu)
}
-test.AED <- function() {
- checkEquals(EAED(comtrees$A), 0.970281697458673)
- checkEquals(EAED(comtrees$B), 0.880992381357733)
- checkEquals(EAED(comtrees$C), 0.984480140607184)
- checkEquals(HAED(comtrees$A), 4.46831234514660)
- checkEquals(HAED(comtrees$B), 4.05711984871128)
- checkEquals(HAED(comtrees$C), 4.53369859222157)
+test.aed <- function() {
- checkEquals(EAED(comtrees.notultra$A), 0.983944053257198)
- checkEquals(EAED(comtrees.notultra$B), 0.838740167266669)
- checkEquals(EAED(comtrees.notultra$C), 0.968547587587551)
- checkEquals(HAED(comtrees.notultra$A), 4.53122981874033)
- checkEquals(HAED(comtrees.notultra$B), 3.86254121208713)
- checkEquals(HAED(comtrees.notultra$C), 4.46032647406888)
+ AED <- list(
+ A = setNames(c(0.0569901020683333, 0.0678765523383333,
+ 0.0678765523383333, 0.0361490219733333, 0.0181818181818182),
+ tipLabels(weeds)),
+ B = setNames(c(0.0257789252355418, 0.0137074840755418,
+ 0.0137074840755418, 0.0806184329578947, 0.2), tipLabels(weeds)),
+ C = setNames(c(0.0244355971816667, 0.0206535821316667,
+ 0.0206535821316667, 0.041876843225, 0.05), tipLabels(weeds)))
+ checkEquals(aed(pcom), AED)
+
+ EAED <- setNames(c(0.970281697458673, 0.880992381357733,
+ 0.984480140607184), c("A", "B", "C"))
+ checkEquals(eaed(pcom), EAED)
+ HAED <- setNames(c(4.46831234514660, 4.05711984871128,
+ 4.53369859222157), c("A", "B", "C"))
+ checkEquals(haed(pcom), HAED)
+
+ EAED.nu <- setNames(c(0.983944053257198, 0.838740167266669,
+ 0.968547587587551), c("A", "B", "C"))
+ checkEquals(eaed(pcom.nu), EAED.nu)
+ HAED.nu <- setNames(c(4.53122981874033, 3.86254121208713,
+ 4.46032647406888), c("A", "B", "C"))
+ checkEquals(haed(pcom.nu), HAED.nu)
}
test.value <- function() {
- checkEqualsNumeric(value(comtrees$A), c(0.230660009755555,
- 0.274721498230706, 0.274721498230706, 0.146308454598398,
- 0.0735885391846351))
- checkEqualsNumeric(value(comtrees$B), c(0.0772258038456494,
- 0.0410634449172336, 0.0410634449172336, 0.241508256572558,
- 0.599139049747326))
- checkEqualsNumeric(value(comtrees$C), c(0.155028920627140,
- 0.131034348010884, 0.131034348010884, 0.265682960648679,
- 0.317219422702413))
+ VALUE <- setNames(list(
+ setNames(c(0.230660009755555, 0.274721498230706, 0.274721498230706,
+ 0.146308454598398, 0.0735885391846351), tipLabels(weeds)),
+ setNames(c(0.0772258038456494, 0.0410634449172336, 0.0410634449172336,
+ 0.241508256572558, 0.599139049747326), tipLabels(weeds)),
+ setNames(c(0.155028920627140, 0.131034348010884, 0.131034348010884,
+ 0.265682960648679, 0.317219422702413), tipLabels(weeds))
+ ), c("A", "B", "C"))
+ checkEquals(value(pcom), VALUE)
}
More information about the Ecopd-commits
mailing list