Learn R Programming

Rsampletrees (version 0.1)

addTreeStat: Add tree statistics to a treeoutput object

Description

This function computes a summary statistic on each of the trees given in the treeoutput object. The results are stored in the procdata component of the treeoutput object.

Usage

addTreeStat(output, myfunc, funcname=NULL, maxlines=1000, treerange=NULL)

Arguments

output
An object of class `treeoutput'
myfunc
The function to be applied to each tree
funcname
The name of the function to be used for the column name of the TreeStat data frame
maxlines
The maximum number of lines of the tree file to read in at a time. This avoids large tree files from fully being read in.
treerange
A vector giving the indices of the trees to which the function should be applied. Only used if the trees haven't been read in

Value

the tree statistics have been added to the data frame TreeStats in the procdata component.The data frame TreeStats consists of a column for the tree index and a column for each of the tree statistics computed.

Details

As with the function treeapply, the tree statistics can be computed on a subset of all the trees (provided by treerange). Note, however, that if TreeStats already exists due to previous call to addTreeStat(), the function is applied to the same trees as indexed in the first column of TreeStats even if these are different from treerange (a warning is given). This ensures a data frame of the correct dimensions.

References

TBD

See Also

readOutput, treeapply

Examples

Run this code
# A function that computes the time to MRCA of a tree using the 
# ape package
mrca.age=function(tree)
{
	return(coalescent.intervals(tree)$total.depth)
}

# Read in the settings; Must change the RunName so that the example files can be found
filename=system.file("Examples/example_g_pars",package="Rsampletrees")
runpars=readArgs(filename, check=FALSE)
runname=paste(system.file(package="Rsampletrees"),runpars$RunName, sep="/")
runpars=changeArgs(runpars, RunName=runname)

# Read in the output and add the summary statistic
results=readOutput(runpars)
results=addTreeStat(results, myfunc=mrca.age, funcname="Time to MRCA")

Run the code above in your browser using DataLab