-## rTrait.R (2011-04-02)
+## rTrait.R (2011-06-16)
## Trait Evolution
rTraitMult <-
function(phy, model, p = 1, root.value = rep(0, p), ancestor = FALSE,
- as.factor = NULL, ...)
+ asFactor = NULL, trait.labels = paste("x", 1:p, sep = ""), ...)
{
phy <- reorder(phy, "pruningwise")
n <- length(phy$tip.label)
el <- phy$edge.length
if (is.null(el)) el <- numeric(N)
+ environment(model) <- environment() # to find 'p'
+
for (i in N:1) x[des[i], ] <- model(x[anc[i], ], el[i], ...)
if (ancestor) {
rownames(x) <- phy$tip.label
}
x <- as.data.frame(x)
- if (!is.null(as.factor)) {
- for (i in as.factor) {
+ names(x) <- trait.labels
+ if (!is.null(asFactor)) {
+ for (i in asFactor) {
y <- x[, i]
x[, i] <- factor(y, labels = LETTERS[1:length(unique(y))])
}