}
x
}
+
+rTraitMult <-
+ function(phy, model, p = 1, root.value = rep(0, p), ancestor = FALSE,
+ as.factor = NULL, ...)
+{
+ phy <- reorder(phy, "pruningwise")
+ n <- length(phy$tip.label)
+ m <- phy$Nnode
+ N <- dim(phy$edge)[1]
+ ROOT <- n + 1L
+
+ x <- matrix(0, n + m, p)
+ x[ROOT, ] <- root.value
+
+ anc <- phy$edge[, 1]
+ des <- phy$edge[, 2]
+
+ el <- phy$edge.length
+ if (is.null(el)) el <- numeric(N)
+
+ for (i in N:1) x[des[i], ] <- model(x[anc[i], ], el[i], ...)
+
+ if (ancestor) {
+ if (is.null(phy$node.label)) phy <- makeNodeLabel(phy)
+ rownames(x) <- c(phy$tip.label, phy$node.label)
+ } else {
+ x <- x[1:n, , drop = FALSE]
+ rownames(x) <- phy$tip.label
+ }
+ x <- as.data.frame(x)
+ if (!is.null(as.factor)) {
+ for (i in as.factor) {
+ y <- x[, i]
+ x[, i] <- factor(y, labels = LETTERS[1:length(unique(y))])
+ }
+ }
+ x
+}