as.mulTree: Combines a data table and a "multiPhylo" object into a list...

View source: R/as.mulTree.R

as.mulTreeR Documentation

Combines a data table and a "multiPhylo" object into a list to be used by the mulTree function

Description

Combines a data table and a multiple phylogenies. Changes the name of the taxa column into "sp.col" to be read by MCMCglmm.

Usage

as.mulTree(data, tree, taxa, rand.terms, clean.data = FALSE)

Arguments

data

A data.frame or matrix containing at least two variable and taxa names.

tree

A phylo or multiPhylo object.

taxa

The name or the number of the column containing the list of taxa in the data.

rand.terms

A formula ontaining additional random terms to add to the default formula (phylogenetic effect). If missing, the random terms are the column containing the taxa names and a column containing the specimen names if more than one taxa per specimen is present.

clean.data

A logical value: whether to use the clean.data function. Default = FALSE.

Details

If rand.terms is specified by the user, the first element is forced to be called "animal".

Value

A mulTree object the data to be passed to the mulTree function.

Author(s)

Thomas Guillerme

See Also

mulTree

Examples

##Creates a data.frame
data_table <- data.frame(taxa = LETTERS[1:5], var1 = rnorm(5),
     var2 = c(rep("a",2), rep("b",3)))
##Creates a list of tree
tree_list <- rmtree(5,5, tip.label = LETTERS[1:5])
##Creates the "mulTree" object
as.mulTree(data_table, tree_list, taxa = "taxa")

##Creating a mulTree object with multiple specimens
##Creates a data.frame with taxa being labelled as "spec1"
data_table_sp1 <- data.frame(taxa = LETTERS[1:5], var1 = rnorm(5),
     var2 = c(rep("a",2), rep("b",3)), specimen = c(rep("spec1", 5)))
##Creates a data.frame with taxa being labelled as "spec2"
data_table_sp2 <- data.frame(taxa = LETTERS[1:5], var1 = rnorm(5),
     var2 = c(rep("a",2), rep("b",3)), specimen = c(rep("spec2", 5)))
##Combines both data.frames
data_table <- rbind(data_table_sp1, data_table_sp2)
##Creates a list of tree
tree_list <- rmtree(5,5, tip.label = LETTERS[1:5])
##Creates the "mulTree" object (with a random term formula)
as.mulTree(data_table, tree_list, taxa = "taxa", rand.terms = ~taxa+specimen)


TGuillerme/mulTree documentation built on Feb. 21, 2024, 9:18 a.m.