<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.r-phylo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hilmar</id>
	<title>Comparative Phylogenetics in R - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.r-phylo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hilmar"/>
	<link rel="alternate" type="text/html" href="https://www.r-phylo.org/wiki/Special:Contributions/Hilmar"/>
	<updated>2026-08-02T02:19:01Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=MediaWiki:Loginprompt&amp;diff=806</id>
		<title>MediaWiki:Loginprompt</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=MediaWiki:Loginprompt&amp;diff=806"/>
		<updated>2017-11-19T04:26:58Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: Created page with &amp;quot;You must have cookies enabled to log in to {{SITENAME}}.  '''If you created your account with a Google Login, you will need to reset your password to use local account login i...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;You must have cookies enabled to log in to {{SITENAME}}.&lt;br /&gt;
&lt;br /&gt;
'''If you created your account with a Google Login, you will need to reset your password to use local account login instead.'''&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-email-ph&amp;diff=805</id>
		<title>MediaWiki:Createacct-email-ph</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-email-ph&amp;diff=805"/>
		<updated>2017-11-19T04:26:20Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: Created page with &amp;quot;Leave empty - provided by Google&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Leave empty - provided by Google&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-submit&amp;diff=804</id>
		<title>MediaWiki:Createacct-submit</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-submit&amp;diff=804"/>
		<updated>2017-11-19T04:25:52Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: Created page with &amp;quot;DO NOT USE - use Google instead&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;DO NOT USE - use Google instead&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-yourpassword-ph&amp;diff=803</id>
		<title>MediaWiki:Createacct-yourpassword-ph</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-yourpassword-ph&amp;diff=803"/>
		<updated>2017-11-19T04:25:27Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: Created page with &amp;quot;Leave empty - not needed&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Leave empty - not needed&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-yourpasswordagain-ph&amp;diff=802</id>
		<title>MediaWiki:Createacct-yourpasswordagain-ph</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-yourpasswordagain-ph&amp;diff=802"/>
		<updated>2017-11-19T04:25:06Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: Created page with &amp;quot;Leave empty - not needed&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Leave empty - not needed&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-helpusername&amp;diff=801</id>
		<title>MediaWiki:Createacct-helpusername</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=MediaWiki:Createacct-helpusername&amp;diff=801"/>
		<updated>2017-11-19T04:24:45Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: Created page with &amp;quot;''username you desire, '''''not''''' your Google ID''&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''username you desire, '''''not''''' your Google ID''&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=User:Hilmar&amp;diff=800</id>
		<title>User:Hilmar</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=User:Hilmar&amp;diff=800"/>
		<updated>2016-06-06T22:34:36Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: Created page with &amp;quot;My most up-to-date profile and what I've recently been up to is usually at my ORCID record: http://orcid.org/0000-0001-9107-0714  You can also find me on [http://twitter.com/h...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;My most up-to-date profile and what I've recently been up to is usually at my ORCID record: http://orcid.org/0000-0001-9107-0714&lt;br /&gt;
&lt;br /&gt;
You can also find me on [http://twitter.com/hlapp Twitter], [http://www.linkedin.com/in/hlapp LinkedIn], [https://plus.google.com/117016856028818567812 Google+], [http://github.com/hlapp Github], and a few other social networks (usually with handle hlapp).&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=R-Phylo:About&amp;diff=799</id>
		<title>R-Phylo:About</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=R-Phylo:About&amp;diff=799"/>
		<updated>2016-06-06T22:33:56Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a community website and resource for, and by, the community of people interested in or developing phylogenetic and comparative methods in the statistics platform and programming language [http://r-project.org R]. &lt;br /&gt;
&lt;br /&gt;
The wiki grew out of a [http://hackathon.nescent.org/R_Hackathon_1 Hackathon on Comparative Methods in R] held at and sponsored by the [http://nescent.org National Evolutionary Synthesis Center] (NESCent) 10-14 December 2007, specifically from the work accomplished by the [http://hackathon.nescent.org/R_Hackathon_1/Documentation_SG documentation subgroup].&lt;br /&gt;
&lt;br /&gt;
The [[:Image:R-phylologo.PNG|logo]] was designed by [http://www.nescent.org/dir/postdoctoral_fellow.php?id=00022 Samantha Price]. &lt;br /&gt;
&lt;br /&gt;
== History of this site ==&lt;br /&gt;
&lt;br /&gt;
This community wiki was hosted and administered by [http://nescent.org NESCent] until 2015, when NESCent's NSF funding ended. This wiki, and several other evolutionary informatics community wikis initiated as a result of NESCent's informatics activities, were publicly archived as part of NESCent's wind down ([http://dx.doi.org/10.5281/zenodo.19018 doi:10.5281/zenodo.19018], [http://dx.doi.org/10.5281/zenodo.19000 doi:10.5281/zenodo.19000], [http://dx.doi.org/10.5281/zenodo.18998 doi:10.5281/zenodo.18998], [http://dx.doi.org/10.5281/zenodo.19004 doi:10.5281/zenodo.19004]). This wiki, as well as the [https://www.evoio.org EvoIO wiki], the [https://informatics.nescent.org Phyloinformatics Wiki], and the [https://evoinfo.nescent.org Evolutionary Informatics Working Group wiki] have since been restored from those archives, and are now independently hosted and maintained.&lt;br /&gt;
&lt;br /&gt;
Originally this site used a skin (designed by [http://www.paulgu.com/ Paul Gu]) and selected by [http://brianomeara.info Brian O'Meara].&lt;br /&gt;
&lt;br /&gt;
== Contact ==&lt;br /&gt;
&lt;br /&gt;
Please email admin at r-phylo dot org to reach the site's administrators.&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=635</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=635"/>
		<updated>2009-08-27T20:35:03Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* Packages and Analyses available in R */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
'''Ancestral state reconstruction''' : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Diversification Analysis''': Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. The &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; diversitree &amp;lt;/span&amp;gt; package includes the BiSSE method (Binary State Speciation and Extinction; Maddison et al. 2007) and extensions for terminally unresolved trees and skeleton trees (FitzJohn et al., Syst. Biol., in press).&lt;br /&gt;
&lt;br /&gt;
'''Divergence Times''': Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Phylogenetic Inference''': Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Phylogenetic trees can be reconstructed using Maximum likelihood, Maximum Parsimony or Hadamard conjugation with &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; phangorn &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
'''Time series''': Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Simulations''': Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
'''Trait evolution''': Independent contrasts for continuous characters can be calculated using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Matticce &amp;lt;/span&amp;gt; implements an information-theoretic approach to estimating where transitions in a continuous character have occurred on a phylogenetic tree, provides helper functions for &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt; to automate the process of painting regimes and to summarize analyses over trees and over regimes, and provides a simulation functions for visualizing how diﬀerent model parameters affect inference of the evolution of a continuous character. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;. The package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; smatr &amp;lt;/span&amp;gt; fits bivariate lines in allometry using the major axis (MA) or standardised major axis (SMA), and allows to make inferences about such lines, including confidence intervals, one-sample tests for slope and elevation, and testing for a common slope or elevation amongst several allometric lines.&lt;br /&gt;
&lt;br /&gt;
'''Trait Simulations''' : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Manipulation''' : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Plotting and Visualization''': User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
== R packages as lists ==&lt;br /&gt;
&lt;br /&gt;
=== Packages on CRAN ===&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/phangorn/index.html phangorn]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html PhySim]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/picante/index.html picante]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/psmatr/index.html smatr]&lt;br /&gt;
&lt;br /&gt;
=== Packages not yet on CRAN ===&lt;br /&gt;
&lt;br /&gt;
* [http://www.zoology.ubc.ca/prog/diversitree/ Diversitree]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
=== Development links for packages ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ade4/ ade4]&lt;br /&gt;
* ape: [http://ape.mpl.ird.fr/ home page] and [https://svn.mpl.ird.fr/ape/ svn repository]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ouch/ OUCH]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://picante.r-forge.r-project.org/ picante]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
# Warton, David I., Ian J. Wright, Daniel S. Falster and Mark Westoby (2006). Bivariate line-fitting methods for allometry. Biological Reviews  81: 259-291&lt;br /&gt;
&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=634</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=634"/>
		<updated>2009-08-27T20:26:27Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* Packages not yet on CRAN */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
'''Ancestral state reconstruction''' : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Diversification Analysis''': Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Divergence Times''': Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Phylogenetic Inference''': Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Phylogenetic trees can be reconstructed using Maximum likelihood, Maximum Parsimony or Hadamard conjugation with &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; phangorn &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
'''Time series''': Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Simulations''': Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
'''Trait evolution''': Independent contrasts for continuous characters can be calculated using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Matticce &amp;lt;/span&amp;gt; implements an information-theoretic approach to estimating where transitions in a continuous character have occurred on a phylogenetic tree, provides helper functions for &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt; to automate the process of painting regimes and to summarize analyses over trees and over regimes, and provides a simulation functions for visualizing how diﬀerent model parameters affect inference of the evolution of a continuous character. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;. The package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; smatr &amp;lt;/span&amp;gt; fits bivariate lines in allometry using the major axis (MA) or standardised major axis (SMA), and allows to make inferences about such lines, including confidence intervals, one-sample tests for slope and elevation, and testing for a common slope or elevation amongst several allometric lines. &lt;br /&gt;
&lt;br /&gt;
'''Trait Simulations''' : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Manipulation''' : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Plotting and Visualization''': User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
== R packages as lists ==&lt;br /&gt;
&lt;br /&gt;
=== Packages on CRAN ===&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/phangorn/index.html phangorn]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html PhySim]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/picante/index.html picante]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/psmatr/index.html smatr]&lt;br /&gt;
&lt;br /&gt;
=== Packages not yet on CRAN ===&lt;br /&gt;
&lt;br /&gt;
* [http://www.zoology.ubc.ca/prog/diversitree/ Diversitree]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
=== Development links for packages ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ade4/ ade4]&lt;br /&gt;
* ape: [http://ape.mpl.ird.fr/ home page] and [https://svn.mpl.ird.fr/ape/ svn repository]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ouch/ OUCH]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://picante.r-forge.r-project.org/ picante]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
# Warton, David I., Ian J. Wright, Daniel S. Falster and Mark Westoby (2006). Bivariate line-fitting methods for allometry. Biological Reviews  81: 259-291&lt;br /&gt;
&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=633</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=633"/>
		<updated>2009-01-23T20:24:31Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
'''Ancestral state reconstruction''' : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Diversification Analysis''': Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Divergence Times''': Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Phylogenetic Inference''': Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Phylogenetic trees can be reconstructed using Maximum likelihood, Maximum Parsimony or Hadamard conjugation with &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; phangorn &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
'''Time series''': Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Simulations''': Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
'''Trait evolution''': Independent contrasts for continuous characters can be calculated using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Matticce &amp;lt;/span&amp;gt; implements an information-theoretic approach to estimating where transitions in a continuous character have occurred on a phylogenetic tree, provides helper functions for &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt; to automate the process of painting regimes and to summarize analyses over trees and over regimes, and provides a simulation functions for visualizing how diﬀerent model parameters affect inference of the evolution of a continuous character. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;. The package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; smatr &amp;lt;/span&amp;gt; fits bivariate lines in allometry using the major axis (MA) or standardised major axis (SMA), and allows to make inferences about such lines, including confidence intervals, one-sample tests for slope and elevation, and testing for a common slope or elevation amongst several allometric lines. &lt;br /&gt;
&lt;br /&gt;
'''Trait Simulations''' : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Manipulation''' : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Plotting and Visualization''': User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
== R packages as lists ==&lt;br /&gt;
&lt;br /&gt;
=== Packages on CRAN ===&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/phangorn/index.html phangorn]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html PhySim]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/picante/index.html picante]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/psmatr/index.html smatr]&lt;br /&gt;
&lt;br /&gt;
=== Packages not yet on CRAN ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
=== Development links for packages ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ade4/ ade4]&lt;br /&gt;
* ape: [http://ape.mpl.ird.fr/ home page] and [https://svn.mpl.ird.fr/ape/ svn repository]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ouch/ OUCH]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://picante.r-forge.r-project.org/ picante]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
# Warton, David I., Ian J. Wright, Daniel S. Falster and Mark Westoby (2006). Bivariate line-fitting methods for allometry. Biological Reviews  81: 259-291&lt;br /&gt;
&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=632</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=632"/>
		<updated>2009-01-23T20:23:21Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* Packages on CRAN */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
'''Ancestral state reconstruction''' : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Diversification Analysis''': Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Divergence Times''': Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Phylogenetic Inference''': Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Phylogenetic trees can be reconstructed using Maximum likelihood, Maximum Parsimony or Hadamard conjugation with &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; phangorn &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
'''Time series''': Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Simulations''': Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
'''Trait evolution''': Independent contrasts for continuous characters can be calculated using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Matticce &amp;lt;/span&amp;gt; implements an information-theoretic approach to estimating where transitions in a continuous character have occurred on a phylogenetic tree, provides helper functions for &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt; to automate the process of painting regimes and to summarize analyses over trees and over regimes, and provides a simulation functions for visualizing how diﬀerent model parameters affect inference of the evolution of a continuous character. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;. The package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; smatr &amp;lt;/span&amp;gt; fits bivariate lines in allometry using the major axis (MA) or standardised major axis (SMA), and allows to make inferences about such lines, including confidence intervals, one-sample tests for slope and elevation, and testing for a common slope or elevation amongst several allometric lines. &lt;br /&gt;
&lt;br /&gt;
'''Trait Simulations''' : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Manipulation''' : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Plotting and Visualization''': User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
== R packages as lists ==&lt;br /&gt;
&lt;br /&gt;
=== Packages on CRAN ===&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/phangorn/index.html phangorn]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html PhySim]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/picante/index.html picante]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/psmatr/index.html smatr]&lt;br /&gt;
&lt;br /&gt;
=== Packages not yet on CRAN ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
=== Development links for packages ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ade4/ ade4]&lt;br /&gt;
* ape: [http://ape.mpl.ird.fr/ home page] and [https://svn.mpl.ird.fr/ape/ svn repository]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ouch/ OUCH]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://picante.r-forge.r-project.org/ picante]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:R Help]][[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=631</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=631"/>
		<updated>2009-01-23T20:22:41Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* Packages and Analyses available in R */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
'''Ancestral state reconstruction''' : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Diversification Analysis''': Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Divergence Times''': Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Phylogenetic Inference''': Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Phylogenetic trees can be reconstructed using Maximum likelihood, Maximum Parsimony or Hadamard conjugation with &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; phangorn &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
'''Time series''': Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Simulations''': Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
'''Trait evolution''': Independent contrasts for continuous characters can be calculated using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Matticce &amp;lt;/span&amp;gt; implements an information-theoretic approach to estimating where transitions in a continuous character have occurred on a phylogenetic tree, provides helper functions for &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt; to automate the process of painting regimes and to summarize analyses over trees and over regimes, and provides a simulation functions for visualizing how diﬀerent model parameters affect inference of the evolution of a continuous character. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;. The package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; smatr &amp;lt;/span&amp;gt; fits bivariate lines in allometry using the major axis (MA) or standardised major axis (SMA), and allows to make inferences about such lines, including confidence intervals, one-sample tests for slope and elevation, and testing for a common slope or elevation amongst several allometric lines. &lt;br /&gt;
&lt;br /&gt;
'''Trait Simulations''' : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Manipulation''' : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Plotting and Visualization''': User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
== R packages as lists ==&lt;br /&gt;
&lt;br /&gt;
=== Packages on CRAN ===&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/phangorn/index.html phangorn]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html PhySim]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/picante/index.html picante]&lt;br /&gt;
&lt;br /&gt;
=== Packages not yet on CRAN ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
=== Development links for packages ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ade4/ ade4]&lt;br /&gt;
* ape: [http://ape.mpl.ird.fr/ home page] and [https://svn.mpl.ird.fr/ape/ svn repository]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ouch/ OUCH]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://picante.r-forge.r-project.org/ picante]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:R Help]][[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=630</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=630"/>
		<updated>2009-01-16T18:58:05Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* Packages and Analyses available in R */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
'''Ancestral state reconstruction''' : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Diversification Analysis''': Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Divergence Times''': Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Phylogenetic Inference''': Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Phylogenetic trees can be reconstructed using Maximum likelihood, Maximum Parsimony or Hadamard conjugation with &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; phangorn &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
'''Time series''': Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Simulations''': Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
'''Trait evolution''': Independent contrasts for continuous characters can be calculated using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Matticce &amp;lt;/span&amp;gt; implements an information-theoretic approach to estimating where transitions in a continuous character have occurred on a phylogenetic tree, provides helper functions for &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt; to automate the process of painting regimes and to summarize analyses over trees and over regimes, and provides a simulation functions for visualizing how diﬀerent model parameters affect inference of the evolution of a continuous character. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Trait Simulations''' : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Manipulation''' : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Plotting and Visualization''': User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
== R packages as lists ==&lt;br /&gt;
&lt;br /&gt;
=== Packages on CRAN ===&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/phangorn/index.html phangorn]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html PhySim]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/picante/index.html picante]&lt;br /&gt;
&lt;br /&gt;
=== Packages not yet on CRAN ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
=== Development links for packages ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ade4/ ade4]&lt;br /&gt;
* ape: [http://ape.mpl.ird.fr/ home page] and [https://svn.mpl.ird.fr/ape/ svn repository]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ouch/ OUCH]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://picante.r-forge.r-project.org/ picante]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:R Help]][[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=629</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=629"/>
		<updated>2009-01-16T18:50:24Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* CRAN packages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
'''Ancestral state reconstruction''' : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Diversification Analysis''': Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Divergence Times''': Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Phylogenetic Inference''': Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Phylogenetic trees can be reconstructed using Maximum likelihood, Maximum Parsimony or Hadamard conjugation with &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; phangorn &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
'''Time series''': Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Simulations''': Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
'''Trait evolution''': Independent contrasts for continuous characters can be calculated using ape. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Trait Simulations''' : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Manipulation''' : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Tree Plotting and Visualization''': User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
== R packages as lists ==&lt;br /&gt;
&lt;br /&gt;
=== Packages on CRAN ===&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/phangorn/index.html phangorn]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html PhySim]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/picante/index.html picante]&lt;br /&gt;
&lt;br /&gt;
=== Packages not yet on CRAN ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
=== Development links for packages ===&lt;br /&gt;
&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ade4/ ade4]&lt;br /&gt;
* ape: [http://ape.mpl.ird.fr/ home page] and [https://svn.mpl.ird.fr/ape/ svn repository]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/mattice/ maticce]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/ouch/ OUCH]&lt;br /&gt;
* [http://phylobase.r-forge.r-project.org/ phylobase]&lt;br /&gt;
* [http://picante.r-forge.r-project.org/ picante]&lt;br /&gt;
* [http://r-forge.r-project.org/projects/rmesquite/ RMesquite]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:R Help]][[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=R-Phylo:About&amp;diff=727</id>
		<title>R-Phylo:About</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=R-Phylo:About&amp;diff=727"/>
		<updated>2008-04-05T19:04:29Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a community website and resource for, and by, the community of people interested in or developing phylogenetic and comparative methods in the statistics platform and programming language [http://r-project.org R]. &lt;br /&gt;
&lt;br /&gt;
The wiki grew out of a [http://hackathon.nescent.org/R_Hackathon_1 Hackathon on Comparative Methods in R] held at and sponsored by the [http://nescent.org National Evolutionary Synthesis Center] (NESCent) 10-14 December 2007, specifically from the work accomplished by the [http://hackathon.nescent.org/R_Hackathon_1/Documentation_SG documentation subgroup].&lt;br /&gt;
&lt;br /&gt;
The [[:Image:R-phylologo.PNG|logo]] was designed by [http://www.nescent.org/dir/postdoctoral_fellow.php?id=00022 Samantha Price]. The skin (designed by [http://www.paulgu.com/ Paul Gu]) was selected by [http://brianomeara.info Brian O'Meara].&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=R-Phylo:About&amp;diff=726</id>
		<title>R-Phylo:About</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=R-Phylo:About&amp;diff=726"/>
		<updated>2008-04-05T19:01:18Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: New page: This is a community website and resource for, and by, the community of people interested in or developing phylogenetic and comparative methods in the statistics platform and programming la...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a community website and resource for, and by, the community of people interested in or developing phylogenetic and comparative methods in the statistics platform and programming language [http://r-project.org R]. &lt;br /&gt;
&lt;br /&gt;
The wiki grew out of a [http://hackathon.nescent.org/R_Hackathon_1 Hackathon on Comparative Methods in R] held at and sponsored by the [http://nescent.org National Evolutionary Synthesis Center] (NESCent) 10-14 December 2007, specifically from the work accomplished by the [http://hackathon.nescent.org/R_Hackathon_1/Documentation_SG documentation subgroup].&lt;br /&gt;
&lt;br /&gt;
The [[:Image:R-phylo-Logo.png|logo]] was designed by [http://www.nescent.org/dir/postdoctoral_fellow.php?id=00022 Samantha Price]. The skin (designed by [http://www.paulgu.com/ Paul Gu]) was selected by [http://brianomeara.info Brian O'Meara].&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=622</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=622"/>
		<updated>2008-03-16T02:41:37Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Packages and Analyses available in R==&lt;br /&gt;
&lt;br /&gt;
The history of life unfolds within a phylogenetic context. Comparative phylogenetic methods are statistical approaches for analyzing historical patterns along phylogenetic trees. This task view describes R packages that implement a variety of different comparative phylogenetic methods. This is an active research area and much of the information is subject to change.&lt;br /&gt;
&lt;br /&gt;
Ancestral state reconstruction : Continuous characters can be reconstructed using maximum likelihood, generalised least squares or independent contrasts in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Root ancestral character states under Brownian motion or Ornstein-Uhlenbeck models can be reconstructed in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;, though ancestral states at the internal nodes are not. Discrete characters can be reconstructed using a variety of Markovian models that parameterize the transition rates among states using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Diversification Analysis: Lineage through time plots can be done in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser &amp;lt;/span&amp;gt;. A simple birth-death model for when you have extant species only (sensu Nee et al. 1994) can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; as can survival models and goodness-of-fit tests (as applied to testing of models of diversification). &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; Laser&amp;lt;/span&amp;gt; implements likelihood methods using a model testing approach for inferring temporal shifts in diversification rates based on a birth-death or pure-birth process. The gamma statistic (Pybus and Harvey 2000) is also available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; laser&amp;lt;/span&amp;gt;. Colless and Sackin's topological methods for analyzing diversification are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; as is the test for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004). Net rates of diversification (sensu Magellon and Sanderson) can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Divergence Times: Non-parametric rate smoothing (NPRS) and penalized likelihood can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Phylogenetic Inference: Maximum likelihood, UPGMA, neighbour joining, bio-nj and fast ME methods of phylogenetic reconstruction are all implemented in the package &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. For more information on importing sequence data, see the Genetics task view.&lt;br /&gt;
&lt;br /&gt;
Time series: Paleontological time series data can be analyzed using a likelihood-based framework for fitting and comparing models (using a model testing approach) of phyletic evolution (based on the random walk or stasis model) using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; paleoTS&amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Tree Simulations: Trees can be simulated using a Yule, PDA, biased or speciation specified model in apTreeshape, a birth-death process in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PhySim &amp;lt;/span&amp;gt;. Random trees can be generated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; by random splitting of edges (for non-parametric trees) or random clustering of tips (for coalescent trees).&lt;br /&gt;
&lt;br /&gt;
Trait evolution: Independent contrasts for continuous characters can be calculated using ape. Pagel's continuous and discrete analyzes can be calculated in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Ornstein-Uhlenbeck (OU) models can be fitted in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH&amp;lt;/span&amp;gt;. In its current implementation, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt; fits only single-optimum models. ANOVA's and MANOVA's in a phylogenetic context can also be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger&amp;lt;/span&amp;gt;. A GLS linear model (sensu Garland and Ives 2000) can be fitted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; PHYLOGR&amp;lt;/span&amp;gt;; the more traditional GLS methods (senu Grafen or Martins) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape&amp;lt;/span&amp;gt;. Phylogenetic autoregression (sensu Cheverud et al) and Phylogenetic autocorrelation (Moran's I) can be implemented in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; or--if you wish the significance test of Moran's I to be calculated via a randomization procedure--in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Trait Simulations : Continuous traits can be simulated using brownian motion in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;, the Hansen model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt; and a speciational model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Discrete traits can be simulated using a continuous time Markov model in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Both discrete and continuous traits can be simulated under models where rates change through time in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Tree Manipulation : Branch length scaling using ACDC; Pagel's (1999) lambda, delta and kappa parameters; and the Ornstein-Uhlenbeck alpha parameter (for ultrametric trees only) are available in &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;. Rooting, resolving polytomies, dropping of tips, setting of branch lengths including Grafen's method can all be done using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;. Trees can be pruned from specified nodes using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; apTreeshape &amp;lt;/span&amp;gt; and extinct taxa can be pruned using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; geiger &amp;lt;/span&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Tree Plotting and Visualization: User inputted trees can be plotted using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt;, &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ade4 &amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; OUCH &amp;lt;/span&amp;gt;. Trees can also be examined (zoomed) and viewed as correlograms using ape. Ancestral state reconstructions can be visualized along branches using &amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt; ape &amp;lt;/span&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
==CRAN packages==&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ape/index.html| ade4]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ade4/index.html| ape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/apTreeshape/index.html| apTreeshape]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/geiger/index.html| geiger]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/laser/index.html| laser]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/ouch/index.html| OUCH]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/paleoTS/index.html| PaleoTS]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PHYLOGR/index.html| PHYLOGR]&lt;br /&gt;
* [http://cran.r-project.org/web/packages/PhySim/index.html| PhySim]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
# Butler MA, King AA 2004 Phylogenetic comparative analysis: A modeling approach for adaptive evolution. American Naturalist 164, 683-695.&lt;br /&gt;
# Cheverud JM, Dow MM, Leutenegger W 1985 The quantitative assessment of phylogenetic constraints in comparative analyses: Sexual dimorphism in body weight among primates. Evolution 39, 1335-1351.&lt;br /&gt;
# Garland T, Harvey PH, Ives AR 1992 Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41, 18-32.&lt;br /&gt;
# Hansen TF 1997. Stabilizing selection and the comparative analysis of adaptation. Evolution 51: 1341-1351.&lt;br /&gt;
# Magallon S, Sanderson, M.J. 2001. Absolute Diversification Rates in Angiosperm Clades. Evolution 55(9):1762-1780.&lt;br /&gt;
# Moore, BR, Chan, KMA, Donoghue, MJ (2004) Detecting diversification rate variation in supertrees. In Bininda-Emonds ORP (ed) Phylogenetic Supertrees: Combining Information to Reveal the Tree of Life, Kluwer Academic pgs 487-533.&lt;br /&gt;
# Nee S, May RM, Harvey PH 1994. The reconstructed evolutionary process. Philosophical Transactions of the Royal Society of London Series B Biological Sciences 344: 305-311.&lt;br /&gt;
# Pagel M 1999 Inferring the historical patterns of biological evolution. Nature 401, 877-884&lt;br /&gt;
# Pybus OG, Harvey PH 2000. Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London Series B Biological Sciences 267, 2267-2272.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:R Help]][[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Taskview&amp;diff=722</id>
		<title>HowTo/Taskview</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Taskview&amp;diff=722"/>
		<updated>2008-03-16T02:39:45Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: HowTo/Taskview moved to Available Packages and Analyses&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Available Packages and Analyses]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=621</id>
		<title>Available Packages and Analyses</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Available_Packages_and_Analyses&amp;diff=621"/>
		<updated>2008-03-16T02:39:45Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: HowTo/Taskview moved to Available Packages and Analyses&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Packages&amp;amp;AnalysesAvailable]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=552</id>
		<title>Packages&amp;AnalysesAvailable</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=552"/>
		<updated>2008-03-03T19:59:43Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;embedurl&amp;gt;http://www.bio.unc.edu/faculty/vision/lab/CPM_taskview.html&amp;lt;/embedurl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:R Help]][[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=551</id>
		<title>Packages&amp;AnalysesAvailable</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=551"/>
		<updated>2008-03-03T19:59:12Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;embedurl&amp;gt;http://www.bio.unc.edu/faculty/vision/lab/CPM_taskview.html&amp;lt;/embedurl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:R Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/CorrelatedDiscrete&amp;diff=204</id>
		<title>HowTo/CorrelatedDiscrete</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/CorrelatedDiscrete&amp;diff=204"/>
		<updated>2008-03-03T19:57:47Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Not developed yet in R!&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]][[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=550</id>
		<title>Packages&amp;AnalysesAvailable</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=550"/>
		<updated>2008-03-03T19:09:36Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon1/Taskview moved to HowTo/Taskview: Fixed URL.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;embedurl&amp;gt;http://www.bio.unc.edu/faculty/vision/lab/CPM_taskview.html&amp;lt;/embedurl&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=549</id>
		<title>Packages&amp;AnalysesAvailable</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=Packages%26AnalysesAvailable&amp;diff=549"/>
		<updated>2008-03-03T17:44:57Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;embedurl&amp;gt;http://www.bio.unc.edu/faculty/vision/lab/CPM_taskview.html&amp;lt;/embedurl&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/UsingVignettes&amp;diff=607</id>
		<title>HowTo/UsingVignettes</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/UsingVignettes&amp;diff=607"/>
		<updated>2008-02-06T19:25:50Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/UsingVignettes moved to HowTo/UsingVignettes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h2&amp;gt;UNDER CONSTRUCTION!&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Vignettes are package tutorials that contain both narrative descriptions for how to perform an analysis as well as working code snippets.&lt;br /&gt;
&lt;br /&gt;
To list available vignettes, type&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; vignette()&lt;br /&gt;
&lt;br /&gt;
To see a specific vignette, type, for example,&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; vignette(&amp;quot;grid&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
You can extract the R code from a vignette by typing&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; vigSrc = list.files(pattern=&amp;quot;Rnw$&amp;quot;,&lt;br /&gt;
                    system.file(&amp;quot;doc&amp;quot;,package=&amp;quot;GOstats&amp;quot;),&lt;br /&gt;
                    full.names=TRUE)&lt;br /&gt;
 &amp;gt; vigSrc&lt;br /&gt;
 &amp;gt; for (v in vigSrc) Stangle(v)&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:R Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Basics&amp;diff=156</id>
		<title>HowTo/Basics</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Basics&amp;diff=156"/>
		<updated>2008-02-06T19:25:39Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/Basics moved to HowTo/Basics&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Basics of Using R &lt;br /&gt;
&lt;br /&gt;
'''Loading packages'''&lt;br /&gt;
&lt;br /&gt;
Any packages needed for your analysis must be loaded at the beginning of each session in R.  To load a package, type at the command prompt:&lt;br /&gt;
&lt;br /&gt;
      library(ape)&lt;br /&gt;
&lt;br /&gt;
'''Accessing help'''&lt;br /&gt;
&lt;br /&gt;
You can obtain information about a package (e.g. its authors, a description of what it does, an index of functions) by typing at the command prompt:&lt;br /&gt;
&lt;br /&gt;
      library(help=ape)&lt;br /&gt;
&lt;br /&gt;
You can also get information about specific functions within packages.  For example, if you wanted help with the phylogenetically independent constrasts function, pic, you could type:&lt;br /&gt;
&lt;br /&gt;
      ?pic&lt;br /&gt;
&lt;br /&gt;
This command will open a help window with a description of the function and typically  an example of how to use it.&lt;br /&gt;
&lt;br /&gt;
To find all documents relating to phylogenetic methods, you could enter:&lt;br /&gt;
&lt;br /&gt;
      help.search(&amp;quot;phylogenetic&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Changing working directory'''&lt;br /&gt;
&lt;br /&gt;
It is useful to keep files associated with analyses in R in a ''working'' directory (a folder on your computer).  To access this directory, you can use the menu options (File-&amp;gt;Change dir.. for Windows and Misc-&amp;gt;Change Working Directory on Macs).  After changing to your working directory, you can ask R to retrieve input data from this folder (see [[R_Hackathon/InputtingTrees|data input]]). Also, any items you save will automatically go to this directory.&lt;br /&gt;
&lt;br /&gt;
'''Saving your work'''&lt;br /&gt;
&lt;br /&gt;
Analyses in R involve the creation and manipulation of objects (see [http://cran.r-project.org/doc/manuals/R-intro.html intro to R]), which in the case of comparative analyses might include phylogenetic trees and tip data. You can save the objects created during an R session in several ways.  Mac users can select Save Workspace File from the Workspace menu, and PC users can select Save Workspace from the File Menu.  Alternately, you can type:&lt;br /&gt;
&lt;br /&gt;
     save.image(&amp;quot;mywork.Rdata&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
This command will save your work in your current directory.  When you re-open R, you can load these object by typing:&lt;br /&gt;
&lt;br /&gt;
     load(&amp;quot;mywork.Rdata&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Similarly, you can save the command input during the session as .Rhistory files. This history can be used as a script for repeating or modifying previous analyses (see below).  &lt;br /&gt;
&lt;br /&gt;
'''Scripting'''&lt;br /&gt;
&lt;br /&gt;
Many users will find it helpful to write a script containing their commands, so that the commands can be copied and pasted into the prompt instead of being typed in each time.  R has a built-in editor that makes it easy to create and use scripts.  For PC users, select New Script under the File menu.  Commands typed into the scripts can be run by highlighting the commands in the script editor and using the CTRL+R or the Run Line or Selection button.  Mac users can create scripts by opening a new document and can run commands by highlighting the commands and typing Apple+Return.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:R Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Divergence_Time_Estimation&amp;diff=301</id>
		<title>HowTo/Divergence Time Estimation</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Divergence_Time_Estimation&amp;diff=301"/>
		<updated>2008-02-06T19:24:25Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
Many of the comparative methods require a ultrmetric tree. Currently, there are many programs available that estimate divergence times  (e.g., [http://paup.csit.fsu.edu/ PAUP*], [http://abacus.gene.ucl.ac.uk/software/paml.html paml], [http://beast.bio.ed.ac.uk/ BEAST], [http://loco.biosci.arizona.edu/r8s/ r8s][http://statgen.ncsu.edu/thorne/multidivtime.html multidivtime], [http://www.math.su.se/PATHd8/ PATHd8]). Different methods making different assumptions about how the tree may be parameterized with respect to branching times. The other available way to estimate divergence times is in R with the [http://pbil.univ-lyon1.fr/R/ape/ ape] package. In each of the following examples you will need a rooted tree with branch lengths. Likewise, your tree will need to be dichotomous (i.e., with no polytomies), therefore it might need a little massaging. See the page on [https://www.nescent.org/wg_phyloinformatics/R_Hackathon/DataTreeManipulation Tree &amp;amp; Data manipulation].&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using nonparametric rate smoothing (NPRS) ==&lt;br /&gt;
&lt;br /&gt;
The first step for each of these methods is to load the functions from the '''ape''' package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(ape)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
next, you will want to read in your rooted tree with branch lengths equal or proportional to number of base pair substitutions with the '''read.tree''' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mytree &amp;lt;- read.tree(file=&amp;quot;PATH_TO_FILE&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mytree &amp;lt;- read.nexus(file=&amp;quot;PATH_TO_FILE&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
depending on how your tree is formatted. The variable ''mytree'' is now an object of class ''phylo''. This tree can be used with all of the following examples. The first is to transform your branch lengths using nonparametric rate smoothing (NPRS; see [http://mbe.oxfordjournals.org/cgi/reprint/14/12/1218 Sanderson, 1997]). This is achieved by issuing the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronotree &amp;lt;- chronogram(mytree)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command takes three additional subcommand:&lt;br /&gt;
&lt;br /&gt;
scale-- This assigns a age to the root of the tree.&lt;br /&gt;
&lt;br /&gt;
expo-- This defines the exponent of the exponential function.&lt;br /&gt;
&lt;br /&gt;
minEdgeLength-- Minimum edge length in the phylogram (default value: 1e-06). If any branches in the tree are shorter then this value, then they will be assigned it.&lt;br /&gt;
&lt;br /&gt;
It is then possible to view the tree by passing the '''chronogram''' argument to the '''plot''' function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plot(chronogram(mytree))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Likewise, you can save the tree to file by passing the '''chronogram''' argument to the '''write.tree''' function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
write.tree(chronogram(mytree), file=&amp;quot;/Users/cbell/tree&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;/Users/cbell/tree&amp;quot; is the path to where I want the file to be saved.&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using penalized likelihood (PL) ==&lt;br /&gt;
&lt;br /&gt;
This next function estimates the node ages of a tree using a semi-parametric method based on penalized likelihood (Sanderson 2002).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronopl(phy, lambda, node.age = 1, node = &amp;quot;root&amp;quot;, CV = FALSE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The branch lengths of the input tree are interpreted as (mean) numbers of substitutions where 'phy' is an object of class &amp;quot;phylo.&amp;quot; lambda equals a value of the smoothing parameter; node.age is a numeric values specifying the fixed node ages; 'node' is the numbers of the nodes whose ages are given by node.age; &amp;quot;root&amp;quot; is a short-cut for the number of the node; and 'CV' is whether to perform cross-validation (see [http://mbe.oxfordjournals.org/cgi/content/full/19/1/101 Sanderson, 2002]). One thing to keep in mind, however, is that the likelihood function is calculated based on a [http://en.wikipedia.org/wiki/Poisson_distribution Poisson] approximation using the number of substitutions observed to perform the calculations. This is not a problem if parsimony was used to calculate branch lengths, where the branch length represents the inferred number of changes that occurred along any given branch. If maximum likelihood was used to infer branch lengths, the values are in expected substitutions per site. In the program r8s, the user provides the number of sites used to infer the branch lengths to convert branch lengths to the observed number of substitutions. In ape, there is no such conversion/option. The user my want to convert there user tree branch lengths to observed number of substitutions by issuing the following commands in R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- mytree$edge.length&lt;br /&gt;
&lt;br /&gt;
for (i in x)&lt;br /&gt;
    y&amp;lt;-x*7999&lt;br /&gt;
&lt;br /&gt;
mytree$edge.length &amp;lt;-y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above, 'mytree' is the tree with branch lengths (edge.length) I read into R. I then converted the branch lengths by a factor of 7999 (the number of sites used in the original dataset to calculate the branch lengths). &lt;br /&gt;
&lt;br /&gt;
Now your tree is ready for the penalized likelihood analysis. However, you need to determine a lambda value (smoothing parameter). Determining an appropriate 'lambda' value is the crux of the matter. This is where the cross-validation procedure comes in. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
l &amp;lt;- 10^(-1:6)&lt;br /&gt;
cv &amp;lt;- numeric(length(l))&lt;br /&gt;
&lt;br /&gt;
for (i in 1:length(l))&lt;br /&gt;
    cv[i] &amp;lt;- sum(attr(chronopl(mammals, lambda = l[i], CV=TRUE), &amp;quot;D2&amp;quot;))&lt;br /&gt;
plot(l, cv)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using mean path length (MPL) ==&lt;br /&gt;
Another method available in '''ape''' is the mean path length method of Britton et al. (2002, [http://www.informaworld.com/smpp/content~content=a782130970~db=all~jumptype=rss 2007]). This is achieved by issuing the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronoMPL(phy)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function has two sub commands:&lt;br /&gt;
&lt;br /&gt;
se-- a logical specifying whether to compute the standard-errors of the node ages (TRUE by default).&lt;br /&gt;
&lt;br /&gt;
test--a logical specifying whether to test the molecular clock at each node (TRUE by default).&lt;br /&gt;
&lt;br /&gt;
The tests performed if test = TRUE is a comparison of the MPL of the two subtrees originating from a node; the null hypothesis is that the rate of substitution was the same in both subtrees (Britton et al. 2002). The test statistic follows, under the null hypothesis, a standard normal distribution. The returned P-value is the probability of observing a greater absolute value (i.e., a two-sided test). No correction for multiple testing is applied: this is left to the user.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Credit: Some of the information on this page is paraphrased from the book ''Analysis of Phylogenetics and Evolution with R&amp;quot; (Paradis, 2006) or from documentation within ape itself.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Divergence_Time_Estimation&amp;diff=300</id>
		<title>HowTo/Divergence Time Estimation</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Divergence_Time_Estimation&amp;diff=300"/>
		<updated>2008-02-06T19:24:10Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
Many of the comparative methods require a ultrmetric tree. Currently, there are many programs available that estimate divergence times  (e.g., [http://paup.csit.fsu.edu/ PAUP*], [http://abacus.gene.ucl.ac.uk/software/paml.html paml], [http://beast.bio.ed.ac.uk/ BEAST], [http://loco.biosci.arizona.edu/r8s/ r8s][http://statgen.ncsu.edu/thorne/multidivtime.html multidivtime], [http://www.math.su.se/PATHd8/ PATHd8]). Different methods making different assumptions about how the tree may be parameterized with respect to branching times. The other available way to estimate divergence times is in R with the [http://pbil.univ-lyon1.fr/R/ape/ ape] package. In each of the following examples you will need a rooted tree with branch lengths. Likewise, your tree will need to be dichotomous (i.e., with no polytomies), therefore it might need a little massaging. See the page on [https://www.nescent.org/wg_phyloinformatics/R_Hackathon/DataTreeManipulation Tree &amp;amp; Data manipulation].&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using nonparametric rate smoothing (NPRS) ==&lt;br /&gt;
&lt;br /&gt;
The first step for each of these methods is to load the functions from the '''ape''' package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(ape)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
next, you will want to read in your rooted tree with branch lengths equal or proportional to number of base pair substitutions with the '''read.tree''' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mytree &amp;lt;- read.tree(file=&amp;quot;PATH_TO_FILE&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mytree &amp;lt;- read.nexus(file=&amp;quot;PATH_TO_FILE&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
depending on how your tree is formatted. The variable ''mytree'' is now an object of class ''phylo''. This tree can be used with all of the following examples. The first is to transform your branch lengths using nonparametric rate smoothing (NPRS; see [http://mbe.oxfordjournals.org/cgi/reprint/14/12/1218 Sanderson, 1997]). This is achieved by issuing the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronotree &amp;lt;- chronogram(mytree)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command takes three additional subcommand:&lt;br /&gt;
&lt;br /&gt;
scale-- This assigns a age to the root of the tree.&lt;br /&gt;
&lt;br /&gt;
expo-- This defines the exponent of the exponential function.&lt;br /&gt;
&lt;br /&gt;
minEdgeLength-- Minimum edge length in the phylogram (default value: 1e-06). If any branches in the tree are shorter then this value, then they will be assigned it.&lt;br /&gt;
&lt;br /&gt;
It is then possible to view the tree by passing the '''chronogram''' argument to the '''plot''' function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plot(chronogram(mytree))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Likewise, you can save the tree to file by passing the '''chronogram''' argument to the '''write.tree''' function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
write.tree(chronogram(mytree), file=&amp;quot;/Users/cbell/tree&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;/Users/cbell/tree&amp;quot; is the path to where I want the file to be saved.&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using penalized likelihood (PL) ==&lt;br /&gt;
&lt;br /&gt;
This next function estimates the node ages of a tree using a semi-parametric method based on penalized likelihood (Sanderson 2002).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronopl(phy, lambda, node.age = 1, node = &amp;quot;root&amp;quot;, CV = FALSE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The branch lengths of the input tree are interpreted as (mean) numbers of substitutions where 'phy' is an object of class &amp;quot;phylo.&amp;quot; lambda equals a value of the smoothing parameter; node.age is a numeric values specifying the fixed node ages; 'node' is the numbers of the nodes whose ages are given by node.age; &amp;quot;root&amp;quot; is a short-cut for the number of the node; and 'CV' is whether to perform cross-validation (see [http://mbe.oxfordjournals.org/cgi/content/full/19/1/101 Sanderson, 2002]). One thing to keep in mind, however, is that the likelihood function is calculated based on a [http://en.wikipedia.org/wiki/Poisson_distribution Poisson] approximation using the number of substitutions observed to perform the calculations. This is not a problem if parsimony was used to calculate branch lengths, where the branch length represents the inferred number of changes that occurred along any given branch. If maximum likelihood was used to infer branch lengths, the values are in expected substitutions per site. In the program r8s, the user provides the number of sites used to infer the branch lengths to convert branch lengths to the observed number of substitutions. In ape, there is no such conversion/option. The user my want to convert there user tree branch lengths to observed number of substitutions by issuing the following commands in R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- mytree$edge.length&lt;br /&gt;
&lt;br /&gt;
for (i in x)&lt;br /&gt;
    y&amp;lt;-x*7999&lt;br /&gt;
&lt;br /&gt;
mytree$edge.length &amp;lt;-y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above, 'mytree' is the tree with branch lengths (edge.length) I read into R. I then converted the branch lengths by a factor of 7999 (the number of sites used in the original dataset to calculate the branch lengths). &lt;br /&gt;
&lt;br /&gt;
Now your tree is ready for the penalized likelihood analysis. However, you need to determine a lambda value (smoothing parameter). Determining an appropriate 'lambda' value is the crux of the matter. This is where the cross-validation procedure comes in. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
l &amp;lt;- 10^(-1:6)&lt;br /&gt;
cv &amp;lt;- numeric(length(l))&lt;br /&gt;
&lt;br /&gt;
for (i in 1:length(l))&lt;br /&gt;
    cv[i] &amp;lt;- sum(attr(chronopl(mammals, lambda = l[i], CV=TRUE), &amp;quot;D2&amp;quot;))&lt;br /&gt;
plot(l, cv)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using mean path length (MPL) ==&lt;br /&gt;
Another method available in '''ape''' is the mean path length method of Britton et al. (2002, [http://www.informaworld.com/smpp/content~content=a782130970~db=all~jumptype=rss 2007]). This is achieved by issuing the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronoMPL(phy)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function has two sub commands:&lt;br /&gt;
&lt;br /&gt;
se-- a logical specifying whether to compute the standard-errors of the node ages (TRUE by default).&lt;br /&gt;
&lt;br /&gt;
test--a logical specifying whether to test the molecular clock at each node (TRUE by default).&lt;br /&gt;
&lt;br /&gt;
The tests performed if test = TRUE is a comparison of the MPL of the two subtrees originating from a node; the null hypothesis is that the rate of substitution was the same in both subtrees (Britton et al. 2002). The test statistic follows, under the null hypothesis, a standard normal distribution. The returned P-value is the probability of observing a greater absolute value (i.e., a two-sided test). No correction for multiple testing is applied: this is left to the user.&lt;br /&gt;
&lt;br /&gt;
Credit: Some of the information on this page is paraphrased from the book ''Analysis of Phylogenetics and Evolution with R&amp;quot; (Paradis, 2006) or from documentation within ape itself.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Divergence_Time_Estimation&amp;diff=299</id>
		<title>HowTo/Divergence Time Estimation</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Divergence_Time_Estimation&amp;diff=299"/>
		<updated>2008-02-06T19:23:38Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/Divergence Time Estimation moved to HowTo/Divergence Time Estimation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
Many of the comparative methods require a ultrmetric tree. Currently, there are many programs available that estimate divergence times  (e.g., [http://paup.csit.fsu.edu/ PAUP*], [http://abacus.gene.ucl.ac.uk/software/paml.html paml], [http://beast.bio.ed.ac.uk/ BEAST], [http://loco.biosci.arizona.edu/r8s/ r8s][http://statgen.ncsu.edu/thorne/multidivtime.html multidivtime], [http://www.math.su.se/PATHd8/ PATHd8]). Different methods making different assumptions about how the tree may be parameterized with respect to branching times. The other available way to estimate divergence times is in R with the [http://pbil.univ-lyon1.fr/R/ape/ ape] package. In each of the following examples you will need a rooted tree with branch lengths. Likewise, your tree will need to be dichotomous (i.e., with no polytomies), therefore it might need a little massaging. See the page on [https://www.nescent.org/wg_phyloinformatics/R_Hackathon/DataTreeManipulation Tree &amp;amp; Data manipulation].&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using nonparametric rate smoothing (NPRS) ==&lt;br /&gt;
&lt;br /&gt;
The first step for each of these methods is to load the functions from the '''ape''' package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(ape)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
next, you will want to read in your rooted tree with branch lengths equal or proportional to number of base pair substitutions with the '''read.tree''' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mytree &amp;lt;- read.tree(file=&amp;quot;PATH_TO_FILE&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mytree &amp;lt;- read.nexus(file=&amp;quot;PATH_TO_FILE&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
depending on how your tree is formatted. The variable ''mytree'' is now an object of class ''phylo''. This tree can be used with all of the following examples. The first is to transform your branch lengths using nonparametric rate smoothing (NPRS; see [http://mbe.oxfordjournals.org/cgi/reprint/14/12/1218 Sanderson, 1997]). This is achieved by issuing the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronotree &amp;lt;- chronogram(mytree)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command takes three additional subcommand:&lt;br /&gt;
&lt;br /&gt;
scale-- This assigns a age to the root of the tree.&lt;br /&gt;
&lt;br /&gt;
expo-- This defines the exponent of the exponential function.&lt;br /&gt;
&lt;br /&gt;
minEdgeLength-- Minimum edge length in the phylogram (default value: 1e-06). If any branches in the tree are shorter then this value, then they will be assigned it.&lt;br /&gt;
&lt;br /&gt;
It is then possible to view the tree by passing the '''chronogram''' argument to the '''plot''' function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plot(chronogram(mytree))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Likewise, you can save the tree to file by passing the '''chronogram''' argument to the '''write.tree''' function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
write.tree(chronogram(mytree), file=&amp;quot;/Users/cbell/tree&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;/Users/cbell/tree&amp;quot; is the path to where I want the file to be saved.&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using penalized likelihood (PL) ==&lt;br /&gt;
&lt;br /&gt;
This next function estimates the node ages of a tree using a semi-parametric method based on penalized likelihood (Sanderson 2002).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronopl(phy, lambda, node.age = 1, node = &amp;quot;root&amp;quot;, CV = FALSE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The branch lengths of the input tree are interpreted as (mean) numbers of substitutions where 'phy' is an object of class &amp;quot;phylo.&amp;quot; lambda equals a value of the smoothing parameter; node.age is a numeric values specifying the fixed node ages; 'node' is the numbers of the nodes whose ages are given by node.age; &amp;quot;root&amp;quot; is a short-cut for the number of the node; and 'CV' is whether to perform cross-validation (see [http://mbe.oxfordjournals.org/cgi/content/full/19/1/101 Sanderson, 2002]). One thing to keep in mind, however, is that the likelihood function is calculated based on a [http://en.wikipedia.org/wiki/Poisson_distribution Poisson] approximation using the number of substitutions observed to perform the calculations. This is not a problem if parsimony was used to calculate branch lengths, where the branch length represents the inferred number of changes that occurred along any given branch. If maximum likelihood was used to infer branch lengths, the values are in expected substitutions per site. In the program r8s, the user provides the number of sites used to infer the branch lengths to convert branch lengths to the observed number of substitutions. In ape, there is no such conversion/option. The user my want to convert there user tree branch lengths to observed number of substitutions by issuing the following commands in R:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- mytree$edge.length&lt;br /&gt;
&lt;br /&gt;
for (i in x)&lt;br /&gt;
    y&amp;lt;-x*7999&lt;br /&gt;
&lt;br /&gt;
mytree$edge.length &amp;lt;-y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above, 'mytree' is the tree with branch lengths (edge.length) I read into R. I then converted the branch lengths by a factor of 7999 (the number of sites used in the original dataset to calculate the branch lengths). &lt;br /&gt;
&lt;br /&gt;
Now your tree is ready for the penalized likelihood analysis. However, you need to determine a lambda value (smoothing parameter). Determining an appropriate 'lambda' value is the crux of the matter. This is where the cross-validation procedure comes in. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
l &amp;lt;- 10^(-1:6)&lt;br /&gt;
cv &amp;lt;- numeric(length(l))&lt;br /&gt;
&lt;br /&gt;
for (i in 1:length(l))&lt;br /&gt;
    cv[i] &amp;lt;- sum(attr(chronopl(mammals, lambda = l[i], CV=TRUE), &amp;quot;D2&amp;quot;))&lt;br /&gt;
plot(l, cv)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How do I estimate divergence times using mean path length (MPL) ==&lt;br /&gt;
Another method available in '''ape''' is the mean path length method of Britton et al. (2002, [http://www.informaworld.com/smpp/content~content=a782130970~db=all~jumptype=rss 2007]). This is achieved by issuing the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chronoMPL(phy)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function has two sub commands:&lt;br /&gt;
&lt;br /&gt;
se-- a logical specifying whether to compute the standard-errors of the node ages (TRUE by default).&lt;br /&gt;
&lt;br /&gt;
test--a logical specifying whether to test the molecular clock at each node (TRUE by default).&lt;br /&gt;
&lt;br /&gt;
The tests performed if test = TRUE is a comparison of the MPL of the two subtrees originating from a node; the null hypothesis is that the rate of substitution was the same in both subtrees (Britton et al. 2002). The test statistic follows, under the null hypothesis, a standard normal distribution. The returned P-value is the probability of observing a greater absolute value (i.e., a two-sided test). No correction for multiple testing is applied: this is left to the user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Credit: Some of the information on this page is paraphrased from the book ''Analysis of Phylogenetics and Evolution with R&amp;quot; (Paradis, 2006) or from documentation within ape itself.&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Ancestral_State_Reconstruction&amp;diff=122</id>
		<title>HowTo/Ancestral State Reconstruction</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Ancestral_State_Reconstruction&amp;diff=122"/>
		<updated>2008-02-06T19:23:11Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
The primary ancestral state reconstruction algorithms in R are accessed through the function &amp;quot;ace&amp;quot; in package &amp;quot;ape&amp;quot;.  To work through the following example using the Geospiza dataset, make sure that you have installed and loaded ape into your R session and loaded the Geospiza phylogeny and tip data into memory.&lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
   geotree &amp;lt;- read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
   geodata &amp;lt;- read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Tip data is not available for the outgroup &amp;quot;olivacea&amp;quot;, so drop that taxon from the analysis.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- drop.tip(geotree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
IMPORTANT.  The row.names of your dataframe must match the tip.labels of your phylogeny.  In the example above, the row.names for geodata will match the tip.labels for geotree after &amp;quot;olivacea&amp;quot; has been culled.  However, the individual columns of geodata (e.g. geodata$wingL) do not automatically have the row.names of the whole data table associated with them! If you call a column of the data.table with ace without first dealing with this issue, the analysis will run, but the tip data will be disassociated from the proper tips! There are two workarounds.&lt;br /&gt;
&lt;br /&gt;
One option is to sort the datatable so that the taxa appear in the same order in the table as in the phylogeny. For example:&lt;br /&gt;
&lt;br /&gt;
   geodata &amp;lt;- geodata[geotree$tip.label, ]&lt;br /&gt;
&lt;br /&gt;
The other, and better option is to extract the column of data of interest from the overall datatable, creating a new vector, and to transfer the row.names of the datatable to the NAMES of the vector. This is the option least likely to inadverently disassociate the tip data from the tips. &lt;br /&gt;
&lt;br /&gt;
   wingL &amp;lt;- geodata$wingL&lt;br /&gt;
   names(wingL) &amp;lt;- row.names(geodata)&lt;br /&gt;
   &lt;br /&gt;
The worked examples below assume that you have used the second solution (vector extraction and name assignment).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reconstructing Ancestral States for Continuous Variables ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are three general options for continuous variables: reconstructions based on maximum likelihood (ML), reconstructions based upon phylogenetic independent contrasts (pic) and reconstructions based on generalized least squares (GLS).  Be aware that the generalized least squares algorithms seem to give spurious results near the root of the phylogeny at present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''MAXIMUM LIKELIHOOD'''&lt;br /&gt;
&lt;br /&gt;
This syntax will reconstruct the ancestral states for the variable &amp;quot;wingL&amp;quot; (extracted from geodata) using the Brownian motion-based maximum likelihood (ML) estimator of Schluter et. al. (1997). This is the default method. &lt;br /&gt;
&lt;br /&gt;
   MLreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;ML&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Why am I getting all these warning messages?''&lt;br /&gt;
&lt;br /&gt;
ML reconstruction using ace tends to generate a large number of not-a-number error messages. These result when the program calculates the likelihood of particularly poor fits. You can safely ignore these messages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''PHYLOGENETIC INDEPENDENT CONSTRASTS'''&lt;br /&gt;
&lt;br /&gt;
This syntax will reconstruct the ancestral states for the variable &amp;quot;wingL&amp;quot; (extracted from geodata) using Felsenstein's  (1985) phylogenetic independent contrasts (pic). This is also a Brownian-motion based estimator, but it only takes descendants of each node into account in reconstructing the state at that node. More basal nodes are ignored. &lt;br /&gt;
&lt;br /&gt;
   picreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;pic&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GENERALIZED LEAST SQUARES'''&lt;br /&gt;
&lt;br /&gt;
WARNING: The current implementation of GLS in ace is unreliable, giving spurious results or error messages that seem to vary between computers and R platforms.  Use these at your own risk. &lt;br /&gt;
&lt;br /&gt;
Reconstructions based upon generalized least squares require specification of a correlation structure for the generalized linear model. There are three basic options for the specification of the correlation structure: 1) corBrownian, which uses a simple Brownian motion model; corMartins, which uses an Ornstein-Uhlenbeck (constrained random-walk) model; and corGrafen, which uses a modified Brownian motion model based upon an ultrametricization of tree as specified by Grafen (1989).&lt;br /&gt;
&lt;br /&gt;
This is the syntax for the simple Brownian model&lt;br /&gt;
&lt;br /&gt;
   GLSreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;GLS&amp;quot;, corStruct = corBrownian(1, geotree))&lt;br /&gt;
&lt;br /&gt;
GLS ancestral state reconstruction using corBrownian currently gives spurious results near the root of the phylogeny, at least at present. Specifically, the root node is always reconstructed as possessing state zero, and internal nodes near the root may receive reconstructed values out of the range of values observed among the tips.   &lt;br /&gt;
&lt;br /&gt;
The syntax for the Ornstein-Uhlenbeck model requires specifying an alpha parameter (here, 0.5).&lt;br /&gt;
&lt;br /&gt;
   GLSreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;GLS&amp;quot;, corStruct = corMartins(0.5, geotree))&lt;br /&gt;
&lt;br /&gt;
Note that Orstein-Uhlenbeck model in this application is currently not working correctly. If you execute the command above, you will receive a Not a Number warning, the reconstructed node values are unreasonably low, and NaN appears in the returned confidence interval. &lt;br /&gt;
&lt;br /&gt;
The syntax for the Grafen model requires specifying a rho parameter (here, 1) which exponentiates the recalculated branch lengths.&lt;br /&gt;
&lt;br /&gt;
   GLSreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;GLS&amp;quot;, corStruct = corGrafen(1, geotree))&lt;br /&gt;
&lt;br /&gt;
The use of corGrafen generates an error on some computers on which we have executed this code, but not all. We are currently investigating the cause. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''WHAT ABOUT SQUARED CHANGE PARSIMONY?'''&lt;br /&gt;
&lt;br /&gt;
Squared change parsimony is mathematically equivalent to a special case of Schluter et. al.'s maximum likelihood method in which branch length information is ignored.  Thus, to perform a squared change parsimony reconstruction, set all branch lengths equal to 1 and calculate a maximum likelihood solution.&lt;br /&gt;
&lt;br /&gt;
   geotreeones &amp;lt;- compute.brlen(geotree, 1)&lt;br /&gt;
   SQPreconstruction &amp;lt;- ace(wingL, geotreeones, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;ML&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HOW DO I USE THE OUTPUT FROM ACE?'''&lt;br /&gt;
&lt;br /&gt;
Each of the objects (for example: MLreconstruction) that we reconstructed above is a list of several elements. These are loglik (the log-likelihood of the most likely reconstruction), ace (the vector of reconstructed node values), sigma2 (a two element vector of the rate estimate and its standard error) and CI95, the 95% confidence intervals around the vector of reconstructed node values.  Thus&lt;br /&gt;
&lt;br /&gt;
   MLreconstruction$ace&lt;br /&gt;
&lt;br /&gt;
returns the vector of node values for wing length (wingL) that were reconstructed using maximum likelihood, and&lt;br /&gt;
&lt;br /&gt;
   wingLfinal &amp;lt;- c(wingL, MLreconstruction$ace)&lt;br /&gt;
&lt;br /&gt;
concatenates the original tip data with the reconstructed node data into a single vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HOW DO I PLOT THE OUTPUT FROM ACE? (drawn from a course handout by Gene Hunt)'''&lt;br /&gt;
&lt;br /&gt;
Plot.phylo can scale symbols at tips and nodes of your tree to your character data. Try this to visualize the evolution of wing length (wingL) across the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
   plot(geotree, show.tip.label=FALSE)&lt;br /&gt;
   tiplabels(pch = 21, cex=(wingL-3.9)*10)&lt;br /&gt;
   nodelabels(pch = 21, cex=(MLreconstruction$ace-3.9)*10)&lt;br /&gt;
   ## (pch = 21 is just telling plot.phylo which symbol to use)&lt;br /&gt;
&lt;br /&gt;
Note that cex argument determines the size at which the symbols will be plotted.  These have been rescaled so that the differences between species are visible on the screen.  Subtracting 3.9 and multiplying by 10 rescales the wingL to range from a little less than 1 to about 5, which is a pretty good range for plotting.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HOW DO I FIT A MODEL OF CHARACTER CHANGE TO CONTINUOUS DATA?'''&lt;br /&gt;
&lt;br /&gt;
While ace returns a rate of Brownian evolution (e.g. MLreconstruction$sigma2), that rate and its associated likelihood value (e.g., MLreconstruction$loglik) is conditioned on the specific ancestral states reconstructed by ace. More generally applicable model fits using Brownian motion and the Ornstein-Uhlenbeck model are available in the packages ouch and geiger.  [[R_Hackathon/ContinuousData|Please see here]] for more information.&lt;br /&gt;
&lt;br /&gt;
== Reconstructing Ancestral States for Discrete Variables ==&lt;br /&gt;
&lt;br /&gt;
The ace command in ape can reconstruct ancestral states for discrete characters using maximum likelihood.&lt;br /&gt;
&lt;br /&gt;
First, ensure that you have ape loaded. &lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
&lt;br /&gt;
Load or reload the Geospiza phylogeny, which will restore the taxon &amp;quot;olivacea&amp;quot; that you may have removed in the continuous example above.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
These commands will set up a new discrete character vector &amp;quot;char1&amp;quot; and assign the names of the terminal taxa in the Geospiza phylogeny to the elements in the new vector.  This is same vector used in [[R_Hackathon/TransitionProbability|the example on modeling discrete character evolution in R]].&lt;br /&gt;
&lt;br /&gt;
     char1&amp;lt;-c(1,1,1,1,1,0,1,0,0,1,0,1,1,1)&lt;br /&gt;
     names(char1)&amp;lt;-geotree$tip.label&lt;br /&gt;
&lt;br /&gt;
You will need to choose among several different options for the matrix that specifies the transition probabilitites  between the states of your discrete character. Ace offers shortcuts for a one-parameter equal rates model (ER), a symmetric model (SYM) in which forwards and reverse transitions between states are constrained to be equal, and an all rates different matrix (ARD) where all possible transitions between states receive distinct parameters. You can also specify your own matrix. &lt;br /&gt;
&lt;br /&gt;
Let's reconstruct ancestral states for the Geospiza data using the three standard methods (ER, SYM and ARD). &lt;br /&gt;
&lt;br /&gt;
   ERreconstruction &amp;lt;- ace(char1, geotree, type=&amp;quot;discrete&amp;quot;, model=&amp;quot;ER&amp;quot;)&lt;br /&gt;
   SYMreconstruction &amp;lt;- ace(char1, geotree, type=&amp;quot;discrete&amp;quot;, model=&amp;quot;SYM&amp;quot;)&lt;br /&gt;
   ARDreconstruction &amp;lt;- ace(char1, geotree, type=&amp;quot;discrete&amp;quot;, model=&amp;quot;ARD&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
These commands issue lots of output, of which you are likely to be most interested in the log likelihoods and the inferred transition rates. You can access the log likelihoods for each model as follows&lt;br /&gt;
&lt;br /&gt;
   ERreconstruction$loglik&lt;br /&gt;
   SYMreconstruction$loglik&lt;br /&gt;
   ARDreconstruction$loglik&lt;br /&gt;
&lt;br /&gt;
You should receive values of -9.00, -9.00 and -7.28, respectively.&lt;br /&gt;
&lt;br /&gt;
The transition rates are accessed with&lt;br /&gt;
 &lt;br /&gt;
   ERreconstruction$rates&lt;br /&gt;
   SYMreconstruction$rates&lt;br /&gt;
   ARDreconstruction$rates&lt;br /&gt;
&lt;br /&gt;
ER and SYM return a single rate of 51.6, while ARD returns a forward and reverse rate (6.00 and 17.9, respectively). &lt;br /&gt;
&lt;br /&gt;
You may have noticed that the output for the ER model matches that of the SYM model.  This is not surprising. For a binary character these models are identical, though they are distinct for characters with three or more states.  For a three-state character, ER is a one parameter model, SYM a three parameter model, and ARD a six parameter model. &lt;br /&gt;
&lt;br /&gt;
''Which model should you prefer?''&lt;br /&gt;
&lt;br /&gt;
In this example, the ARD model gives the highest likelihood. However, it also includes more parameters that the ER and SYM models, and it is well known that adding parameters to a model generally increases its likelihood.  To determine whether the use of the more heavily parameterized model is appropriate, you should execute a likelihood test.&lt;br /&gt;
&lt;br /&gt;
Twice the difference in log likelihood between two models (known as the G statistic) is distributed as chi square, with degrees of freedom equal to the number of parameters that differ between the models. Thus a likelihood test of these models asks whether the difference in likelihoods is large enough to lie in the rightmost tail of the chisquare distribution, typically considered to be the largest 5% of values. &lt;br /&gt;
&lt;br /&gt;
The command pchisq(value, df) gives the percentage of the cumulative distribution function for chisquare that lies to the left of the given value for a desired degree of freedom(df).  Thus, the following command gives the percentage of the chisquare distribution that lies to the right of the observed likelihood difference for the ER and ARD models (which differ by one parameter), given the Geospiza data. &lt;br /&gt;
&lt;br /&gt;
   1-pchisq(2*abs(ERreconstruction$loglik - ARDreconstruction$loglik), 1)&lt;br /&gt;
&lt;br /&gt;
Evaluation of the equation above yields the p-value for the likelihood test, in this case 0.064.  This is not a significant result at a 5% error rate (though it is very close to significance), so we do not accept the more heavily parameterized ARD model, and instead choose the single-parameter ER model.  &lt;br /&gt;
&lt;br /&gt;
For a single degree of freedom, the significance cutoff for the likelihood values lies at about 1.93 log-likelihood units of difference. &lt;br /&gt;
&lt;br /&gt;
''How do I define and use a custom transition model?''&lt;br /&gt;
&lt;br /&gt;
What if you want to use a transition model that isn't hardwired into ace?  You can do so by defining a custom transition matrix.  For example, let's create a custom four-parameter matrix for a three state character, in which the the probability of transitioning from state 1 to 2 equals the probability of state 2 to 1 (parameter 1), the probability of transitioning from 1 to 3 equals the probability of transitioning from state 3 to 1 (parameter 2), but the probability of transitioning from state 2 to 3 (parameter 3) does not necessarily equal the probability of transitioning from state 3 to 2 (parameter 4). &lt;br /&gt;
&lt;br /&gt;
This syntax will set up such a transition matrix. &lt;br /&gt;
&lt;br /&gt;
   transitions &amp;lt;- matrix (c(0, 1, 2, 1, 0, 3, 2, 4, 0), nrow=3)&lt;br /&gt;
   transitions&lt;br /&gt;
&lt;br /&gt;
You should see a matrix that looks like the following output to your screen. &lt;br /&gt;
&lt;br /&gt;
        [,1] [,2] [,3]&lt;br /&gt;
   [1,]    0    1    2&lt;br /&gt;
   [2,]    1    0    4&lt;br /&gt;
   [3,]    2    3    0&lt;br /&gt;
&lt;br /&gt;
Let's now define a three-state discrete character for the Geospiza and apply this custom transition model to the ancestral state reconstruction.&lt;br /&gt;
&lt;br /&gt;
     char2&amp;lt;-c(3,3,1,2,1,1,3,3,3,3,2,2,2,3)&lt;br /&gt;
     names(char2)&amp;lt;- geotree$tip.label&lt;br /&gt;
     CUSreconstruction &amp;lt;- ace(char2, geotree, type=&amp;quot;discrete&amp;quot;, model=transitions)&lt;br /&gt;
&lt;br /&gt;
You should obtain a log likelihood of -11.49&lt;br /&gt;
&lt;br /&gt;
''Are there any caveats about the reconstruction of discrete characters that I should be aware of?''&lt;br /&gt;
&lt;br /&gt;
Yes. Ace deals with this analysis by parameterizing each node within the phylogeny and reconstructing its ancestral state separately. This is a computationally intensive problem, and ace sometime returns spurious results when attempting a solution.  If the returned log likelihood is tiny or enormous, or some of the reconstructed ancestral states have greater than 100% probability (or negative probability) at certain nodes, it is likely that ape is not reconstructing an accurate solution for the character in question. You are most likely to run into this issue when using complicated transition models or trees that imply many character state changes.  &lt;br /&gt;
&lt;br /&gt;
You can see the probability of each of the possible ancestral states at each of the nodes by typing the following:&lt;br /&gt;
&lt;br /&gt;
   CUSreconstruction$lik.anc&lt;br /&gt;
&lt;br /&gt;
In other cases, the likelihood surface for the rates will be essentially flat, and you can place little confidence in the specific rates being reconstructed for each node. If the rate values are important in your application, check their standard errors. &lt;br /&gt;
&lt;br /&gt;
   CUSreconstruction$se&lt;br /&gt;
&lt;br /&gt;
If the standard errors are very large, or represented by NaN (not a number), then you are dealing with a flat or nearly flat likelihood surface, and should not place any confidence in the reconstructed rates.  This was true for the equal rates (ER) reconstruction of char1 above. Type&lt;br /&gt;
&lt;br /&gt;
   ERreconstruction$se&lt;br /&gt;
&lt;br /&gt;
to see the standard error for that reconstruction.  R should returned NaN for this value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Citations ==&lt;br /&gt;
&lt;br /&gt;
Felsenstein, J. 1985. Phylogenies and the comparative method. ''American Naturalist'' 125, 1-15.&lt;br /&gt;
&lt;br /&gt;
Grafen, A.  1989. The phylogenetic regression. ''Philosophical Transactions of the Royal Society of London. Series B, Biological Sciences'', Vol. 326, No. 1233. (Dec. 21, 1989), pp. 119-157.&lt;br /&gt;
&lt;br /&gt;
Paradis, E. 2006. ''Analysis of Phylogenetics and Evolution using R''.  New York, Springer . 211 pp. &lt;br /&gt;
Much of the text above is paraphrased from this source.&lt;br /&gt;
&lt;br /&gt;
Schluter D., Price T. Mooers A. O.  and Ludwig D. 1997. Likelihood of ancestral states in adaptive radiation. ''Evolution'' 51: 1699-1711.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Ancestral_State_Reconstruction&amp;diff=121</id>
		<title>HowTo/Ancestral State Reconstruction</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Ancestral_State_Reconstruction&amp;diff=121"/>
		<updated>2008-02-06T19:22:07Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/Ancestral State Reconstruction moved to HowTo/Ancestral State Reconstruction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
The primary ancestral state reconstruction algorithms in R are accessed through the function &amp;quot;ace&amp;quot; in package &amp;quot;ape&amp;quot;.  To work through the following example using the Geospiza dataset, make sure that you have installed and loaded ape into your R session and loaded the Geospiza phylogeny and tip data into memory.&lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
   geotree &amp;lt;- read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
   geodata &amp;lt;- read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Tip data is not available for the outgroup &amp;quot;olivacea&amp;quot;, so drop that taxon from the analysis.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- drop.tip(geotree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
IMPORTANT.  The row.names of your dataframe must match the tip.labels of your phylogeny.  In the example above, the row.names for geodata will match the tip.labels for geotree after &amp;quot;olivacea&amp;quot; has been culled.  However, the individual columns of geodata (e.g. geodata$wingL) do not automatically have the row.names of the whole data table associated with them! If you call a column of the data.table with ace without first dealing with this issue, the analysis will run, but the tip data will be disassociated from the proper tips! There are two workarounds.&lt;br /&gt;
&lt;br /&gt;
One option is to sort the datatable so that the taxa appear in the same order in the table as in the phylogeny. For example:&lt;br /&gt;
&lt;br /&gt;
   geodata &amp;lt;- geodata[geotree$tip.label, ]&lt;br /&gt;
&lt;br /&gt;
The other, and better option is to extract the column of data of interest from the overall datatable, creating a new vector, and to transfer the row.names of the datatable to the NAMES of the vector. This is the option least likely to inadverently disassociate the tip data from the tips. &lt;br /&gt;
&lt;br /&gt;
   wingL &amp;lt;- geodata$wingL&lt;br /&gt;
   names(wingL) &amp;lt;- row.names(geodata)&lt;br /&gt;
   &lt;br /&gt;
The worked examples below assume that you have used the second solution (vector extraction and name assignment).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reconstructing Ancestral States for Continuous Variables ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are three general options for continuous variables: reconstructions based on maximum likelihood (ML), reconstructions based upon phylogenetic independent contrasts (pic) and reconstructions based on generalized least squares (GLS).  Be aware that the generalized least squares algorithms seem to give spurious results near the root of the phylogeny at present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''MAXIMUM LIKELIHOOD'''&lt;br /&gt;
&lt;br /&gt;
This syntax will reconstruct the ancestral states for the variable &amp;quot;wingL&amp;quot; (extracted from geodata) using the Brownian motion-based maximum likelihood (ML) estimator of Schluter et. al. (1997). This is the default method. &lt;br /&gt;
&lt;br /&gt;
   MLreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;ML&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Why am I getting all these warning messages?''&lt;br /&gt;
&lt;br /&gt;
ML reconstruction using ace tends to generate a large number of not-a-number error messages. These result when the program calculates the likelihood of particularly poor fits. You can safely ignore these messages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''PHYLOGENETIC INDEPENDENT CONSTRASTS'''&lt;br /&gt;
&lt;br /&gt;
This syntax will reconstruct the ancestral states for the variable &amp;quot;wingL&amp;quot; (extracted from geodata) using Felsenstein's  (1985) phylogenetic independent contrasts (pic). This is also a Brownian-motion based estimator, but it only takes descendants of each node into account in reconstructing the state at that node. More basal nodes are ignored. &lt;br /&gt;
&lt;br /&gt;
   picreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;pic&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GENERALIZED LEAST SQUARES'''&lt;br /&gt;
&lt;br /&gt;
WARNING: The current implementation of GLS in ace is unreliable, giving spurious results or error messages that seem to vary between computers and R platforms.  Use these at your own risk. &lt;br /&gt;
&lt;br /&gt;
Reconstructions based upon generalized least squares require specification of a correlation structure for the generalized linear model. There are three basic options for the specification of the correlation structure: 1) corBrownian, which uses a simple Brownian motion model; corMartins, which uses an Ornstein-Uhlenbeck (constrained random-walk) model; and corGrafen, which uses a modified Brownian motion model based upon an ultrametricization of tree as specified by Grafen (1989).&lt;br /&gt;
&lt;br /&gt;
This is the syntax for the simple Brownian model&lt;br /&gt;
&lt;br /&gt;
   GLSreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;GLS&amp;quot;, corStruct = corBrownian(1, geotree))&lt;br /&gt;
&lt;br /&gt;
GLS ancestral state reconstruction using corBrownian currently gives spurious results near the root of the phylogeny, at least at present. Specifically, the root node is always reconstructed as possessing state zero, and internal nodes near the root may receive reconstructed values out of the range of values observed among the tips.   &lt;br /&gt;
&lt;br /&gt;
The syntax for the Ornstein-Uhlenbeck model requires specifying an alpha parameter (here, 0.5).&lt;br /&gt;
&lt;br /&gt;
   GLSreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;GLS&amp;quot;, corStruct = corMartins(0.5, geotree))&lt;br /&gt;
&lt;br /&gt;
Note that Orstein-Uhlenbeck model in this application is currently not working correctly. If you execute the command above, you will receive a Not a Number warning, the reconstructed node values are unreasonably low, and NaN appears in the returned confidence interval. &lt;br /&gt;
&lt;br /&gt;
The syntax for the Grafen model requires specifying a rho parameter (here, 1) which exponentiates the recalculated branch lengths.&lt;br /&gt;
&lt;br /&gt;
   GLSreconstruction &amp;lt;- ace(wingL, geotree, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;GLS&amp;quot;, corStruct = corGrafen(1, geotree))&lt;br /&gt;
&lt;br /&gt;
The use of corGrafen generates an error on some computers on which we have executed this code, but not all. We are currently investigating the cause. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''WHAT ABOUT SQUARED CHANGE PARSIMONY?'''&lt;br /&gt;
&lt;br /&gt;
Squared change parsimony is mathematically equivalent to a special case of Schluter et. al.'s maximum likelihood method in which branch length information is ignored.  Thus, to perform a squared change parsimony reconstruction, set all branch lengths equal to 1 and calculate a maximum likelihood solution.&lt;br /&gt;
&lt;br /&gt;
   geotreeones &amp;lt;- compute.brlen(geotree, 1)&lt;br /&gt;
   SQPreconstruction &amp;lt;- ace(wingL, geotreeones, type=&amp;quot;continuous&amp;quot;, method=&amp;quot;ML&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HOW DO I USE THE OUTPUT FROM ACE?'''&lt;br /&gt;
&lt;br /&gt;
Each of the objects (for example: MLreconstruction) that we reconstructed above is a list of several elements. These are loglik (the log-likelihood of the most likely reconstruction), ace (the vector of reconstructed node values), sigma2 (a two element vector of the rate estimate and its standard error) and CI95, the 95% confidence intervals around the vector of reconstructed node values.  Thus&lt;br /&gt;
&lt;br /&gt;
   MLreconstruction$ace&lt;br /&gt;
&lt;br /&gt;
returns the vector of node values for wing length (wingL) that were reconstructed using maximum likelihood, and&lt;br /&gt;
&lt;br /&gt;
   wingLfinal &amp;lt;- c(wingL, MLreconstruction$ace)&lt;br /&gt;
&lt;br /&gt;
concatenates the original tip data with the reconstructed node data into a single vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HOW DO I PLOT THE OUTPUT FROM ACE? (drawn from a course handout by Gene Hunt)'''&lt;br /&gt;
&lt;br /&gt;
Plot.phylo can scale symbols at tips and nodes of your tree to your character data. Try this to visualize the evolution of wing length (wingL) across the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
   plot(geotree, show.tip.label=FALSE)&lt;br /&gt;
   tiplabels(pch = 21, cex=(wingL-3.9)*10)&lt;br /&gt;
   nodelabels(pch = 21, cex=(MLreconstruction$ace-3.9)*10)&lt;br /&gt;
   ## (pch = 21 is just telling plot.phylo which symbol to use)&lt;br /&gt;
&lt;br /&gt;
Note that cex argument determines the size at which the symbols will be plotted.  These have been rescaled so that the differences between species are visible on the screen.  Subtracting 3.9 and multiplying by 10 rescales the wingL to range from a little less than 1 to about 5, which is a pretty good range for plotting.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HOW DO I FIT A MODEL OF CHARACTER CHANGE TO CONTINUOUS DATA?'''&lt;br /&gt;
&lt;br /&gt;
While ace returns a rate of Brownian evolution (e.g. MLreconstruction$sigma2), that rate and its associated likelihood value (e.g., MLreconstruction$loglik) is conditioned on the specific ancestral states reconstructed by ace. More generally applicable model fits using Brownian motion and the Ornstein-Uhlenbeck model are available in the packages ouch and geiger.  [[R_Hackathon/ContinuousData|Please see here]] for more information.&lt;br /&gt;
&lt;br /&gt;
== Reconstructing Ancestral States for Discrete Variables ==&lt;br /&gt;
&lt;br /&gt;
The ace command in ape can reconstruct ancestral states for discrete characters using maximum likelihood.&lt;br /&gt;
&lt;br /&gt;
First, ensure that you have ape loaded. &lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
&lt;br /&gt;
Load or reload the Geospiza phylogeny, which will restore the taxon &amp;quot;olivacea&amp;quot; that you may have removed in the continuous example above.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
These commands will set up a new discrete character vector &amp;quot;char1&amp;quot; and assign the names of the terminal taxa in the Geospiza phylogeny to the elements in the new vector.  This is same vector used in [[R_Hackathon/TransitionProbability|the example on modeling discrete character evolution in R]].&lt;br /&gt;
&lt;br /&gt;
     char1&amp;lt;-c(1,1,1,1,1,0,1,0,0,1,0,1,1,1)&lt;br /&gt;
     names(char1)&amp;lt;-geotree$tip.label&lt;br /&gt;
&lt;br /&gt;
You will need to choose among several different options for the matrix that specifies the transition probabilitites  between the states of your discrete character. Ace offers shortcuts for a one-parameter equal rates model (ER), a symmetric model (SYM) in which forwards and reverse transitions between states are constrained to be equal, and an all rates different matrix (ARD) where all possible transitions between states receive distinct parameters. You can also specify your own matrix. &lt;br /&gt;
&lt;br /&gt;
Let's reconstruct ancestral states for the Geospiza data using the three standard methods (ER, SYM and ARD). &lt;br /&gt;
&lt;br /&gt;
   ERreconstruction &amp;lt;- ace(char1, geotree, type=&amp;quot;discrete&amp;quot;, model=&amp;quot;ER&amp;quot;)&lt;br /&gt;
   SYMreconstruction &amp;lt;- ace(char1, geotree, type=&amp;quot;discrete&amp;quot;, model=&amp;quot;SYM&amp;quot;)&lt;br /&gt;
   ARDreconstruction &amp;lt;- ace(char1, geotree, type=&amp;quot;discrete&amp;quot;, model=&amp;quot;ARD&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
These commands issue lots of output, of which you are likely to be most interested in the log likelihoods and the inferred transition rates. You can access the log likelihoods for each model as follows&lt;br /&gt;
&lt;br /&gt;
   ERreconstruction$loglik&lt;br /&gt;
   SYMreconstruction$loglik&lt;br /&gt;
   ARDreconstruction$loglik&lt;br /&gt;
&lt;br /&gt;
You should receive values of -9.00, -9.00 and -7.28, respectively.&lt;br /&gt;
&lt;br /&gt;
The transition rates are accessed with&lt;br /&gt;
 &lt;br /&gt;
   ERreconstruction$rates&lt;br /&gt;
   SYMreconstruction$rates&lt;br /&gt;
   ARDreconstruction$rates&lt;br /&gt;
&lt;br /&gt;
ER and SYM return a single rate of 51.6, while ARD returns a forward and reverse rate (6.00 and 17.9, respectively). &lt;br /&gt;
&lt;br /&gt;
You may have noticed that the output for the ER model matches that of the SYM model.  This is not surprising. For a binary character these models are identical, though they are distinct for characters with three or more states.  For a three-state character, ER is a one parameter model, SYM a three parameter model, and ARD a six parameter model. &lt;br /&gt;
&lt;br /&gt;
''Which model should you prefer?''&lt;br /&gt;
&lt;br /&gt;
In this example, the ARD model gives the highest likelihood. However, it also includes more parameters that the ER and SYM models, and it is well known that adding parameters to a model generally increases its likelihood.  To determine whether the use of the more heavily parameterized model is appropriate, you should execute a likelihood test.&lt;br /&gt;
&lt;br /&gt;
Twice the difference in log likelihood between two models (known as the G statistic) is distributed as chi square, with degrees of freedom equal to the number of parameters that differ between the models. Thus a likelihood test of these models asks whether the difference in likelihoods is large enough to lie in the rightmost tail of the chisquare distribution, typically considered to be the largest 5% of values. &lt;br /&gt;
&lt;br /&gt;
The command pchisq(value, df) gives the percentage of the cumulative distribution function for chisquare that lies to the left of the given value for a desired degree of freedom(df).  Thus, the following command gives the percentage of the chisquare distribution that lies to the right of the observed likelihood difference for the ER and ARD models (which differ by one parameter), given the Geospiza data. &lt;br /&gt;
&lt;br /&gt;
   1-pchisq(2*abs(ERreconstruction$loglik - ARDreconstruction$loglik), 1)&lt;br /&gt;
&lt;br /&gt;
Evaluation of the equation above yields the p-value for the likelihood test, in this case 0.064.  This is not a significant result at a 5% error rate (though it is very close to significance), so we do not accept the more heavily parameterized ARD model, and instead choose the single-parameter ER model.  &lt;br /&gt;
&lt;br /&gt;
For a single degree of freedom, the significance cutoff for the likelihood values lies at about 1.93 log-likelihood units of difference. &lt;br /&gt;
&lt;br /&gt;
''How do I define and use a custom transition model?''&lt;br /&gt;
&lt;br /&gt;
What if you want to use a transition model that isn't hardwired into ace?  You can do so by defining a custom transition matrix.  For example, let's create a custom four-parameter matrix for a three state character, in which the the probability of transitioning from state 1 to 2 equals the probability of state 2 to 1 (parameter 1), the probability of transitioning from 1 to 3 equals the probability of transitioning from state 3 to 1 (parameter 2), but the probability of transitioning from state 2 to 3 (parameter 3) does not necessarily equal the probability of transitioning from state 3 to 2 (parameter 4). &lt;br /&gt;
&lt;br /&gt;
This syntax will set up such a transition matrix. &lt;br /&gt;
&lt;br /&gt;
   transitions &amp;lt;- matrix (c(0, 1, 2, 1, 0, 3, 2, 4, 0), nrow=3)&lt;br /&gt;
   transitions&lt;br /&gt;
&lt;br /&gt;
You should see a matrix that looks like the following output to your screen. &lt;br /&gt;
&lt;br /&gt;
        [,1] [,2] [,3]&lt;br /&gt;
   [1,]    0    1    2&lt;br /&gt;
   [2,]    1    0    4&lt;br /&gt;
   [3,]    2    3    0&lt;br /&gt;
&lt;br /&gt;
Let's now define a three-state discrete character for the Geospiza and apply this custom transition model to the ancestral state reconstruction.&lt;br /&gt;
&lt;br /&gt;
     char2&amp;lt;-c(3,3,1,2,1,1,3,3,3,3,2,2,2,3)&lt;br /&gt;
     names(char2)&amp;lt;- geotree$tip.label&lt;br /&gt;
     CUSreconstruction &amp;lt;- ace(char2, geotree, type=&amp;quot;discrete&amp;quot;, model=transitions)&lt;br /&gt;
&lt;br /&gt;
You should obtain a log likelihood of -11.49&lt;br /&gt;
&lt;br /&gt;
''Are there any caveats about the reconstruction of discrete characters that I should be aware of?''&lt;br /&gt;
&lt;br /&gt;
Yes. Ace deals with this analysis by parameterizing each node within the phylogeny and reconstructing its ancestral state separately. This is a computationally intensive problem, and ace sometime returns spurious results when attempting a solution.  If the returned log likelihood is tiny or enormous, or some of the reconstructed ancestral states have greater than 100% probability (or negative probability) at certain nodes, it is likely that ape is not reconstructing an accurate solution for the character in question. You are most likely to run into this issue when using complicated transition models or trees that imply many character state changes.  &lt;br /&gt;
&lt;br /&gt;
You can see the probability of each of the possible ancestral states at each of the nodes by typing the following:&lt;br /&gt;
&lt;br /&gt;
   CUSreconstruction$lik.anc&lt;br /&gt;
&lt;br /&gt;
In other cases, the likelihood surface for the rates will be essentially flat, and you can place little confidence in the specific rates being reconstructed for each node. If the rate values are important in your application, check their standard errors. &lt;br /&gt;
&lt;br /&gt;
   CUSreconstruction$se&lt;br /&gt;
&lt;br /&gt;
If the standard errors are very large, or represented by NaN (not a number), then you are dealing with a flat or nearly flat likelihood surface, and should not place any confidence in the reconstructed rates.  This was true for the equal rates (ER) reconstruction of char1 above. Type&lt;br /&gt;
&lt;br /&gt;
   ERreconstruction$se&lt;br /&gt;
&lt;br /&gt;
to see the standard error for that reconstruction.  R should returned NaN for this value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Citations ==&lt;br /&gt;
&lt;br /&gt;
Felsenstein, J. 1985. Phylogenies and the comparative method. ''American Naturalist'' 125, 1-15.&lt;br /&gt;
&lt;br /&gt;
Grafen, A.  1989. The phylogenetic regression. ''Philosophical Transactions of the Royal Society of London. Series B, Biological Sciences'', Vol. 326, No. 1233. (Dec. 21, 1989), pp. 119-157.&lt;br /&gt;
&lt;br /&gt;
Paradis, E. 2006. ''Analysis of Phylogenetics and Evolution using R''.  New York, Springer . 211 pp. &lt;br /&gt;
Much of the text above is paraphrased from this source.&lt;br /&gt;
&lt;br /&gt;
Schluter D., Price T. Mooers A. O.  and Ludwig D. 1997. Likelihood of ancestral states in adaptive radiation. ''Evolution'' 51: 1699-1711.&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=493</id>
		<title>HowTo/PGLS</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=493"/>
		<updated>2008-02-06T19:21:28Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: /* Fitting a Brownian Motion model in PGLS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Phylogenetic Generalized Least Squares==&lt;br /&gt;
&lt;br /&gt;
PGLS is a powerful method for analyzing continuous data that has been applied to estimating adaptive optima (Butler and King 2004) and estimating the relationships among traits (e.g., body size and geographic range size in carnivores).  PGLS allows the user to specify different ways in which the tree structure is expected to affect the covariance in trait values across taxa.  For example, the user might assume that the trait evolves by Brownian motion and thus that the trait covariance between any pair of taxa decreases linearly with the time (in branch length) since their divergence.  Alternately, the user might apply a Ornstein-Uhlenbeck model where the expected covariance decreases exponentially, as governed by the parameter alpha (Martins and Hansen 1997).    These methods are implemented in the ape package.&lt;br /&gt;
&lt;br /&gt;
===Fitting a Brownian Motion model in PGLS===&lt;br /&gt;
&lt;br /&gt;
Let's return to the ''Geospiza'' dataset (within the geiger package) to try PGLS.  We assume that you have already loaded the necessary packages (geiger for the data and ape for the function) [[R_Hackathon/TransitionProbability|as described]]. Let's say we want to test whether there is a significant relationship between wing length and tarsus length, accounting for possible dependence among the data points (trait values) due to phylogenetic relatedness.&lt;br /&gt;
&lt;br /&gt;
First, let's prepare our tree for the analysis.   Our original tree has 14 taxa but we only have data for 13, so we must prune the tree.  We can take out the species for which we have no data (olivacea) as follows:&lt;br /&gt;
&lt;br /&gt;
     data(geospiza)&lt;br /&gt;
     attach(geospiza)&lt;br /&gt;
     geospiza13.tree&amp;lt;-drop.tip(geospiza.tree,&amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Now let's create a data frame containing just our traits of interest, with the row.names matching the tip.labels.  Most users will bring their data in from a tab-delimited table, for example by typing:&lt;br /&gt;
&lt;br /&gt;
     geospiza.data&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;,row.names=1)&lt;br /&gt;
 &lt;br /&gt;
where the row names are the taxon names.  NOTE: you must associate the taxon names with the trait values so that the values can be correctly tied to the tips of the tree!  See also [[R_Hackathon 1/Ancestral_State_Reconstruction|Ancestral State Reconstruction]].  With the dataset in active memory, we can create the dataframe as follows:&lt;br /&gt;
&lt;br /&gt;
     wingL&amp;lt;-geospiza.data$wingL&lt;br /&gt;
     tarsusL&amp;lt;-geospiza.data$tarsusL&lt;br /&gt;
     DF.geospiza&amp;lt;-data.frame(wingL,tarsusL,row.names=geospiza13.tree$tip.label)&lt;br /&gt;
     DF.geospiza&lt;br /&gt;
&lt;br /&gt;
When you type the final command, you will see that you have a data frame where the row names are the tip.labels in the pruned tree.  Now we will first build the correlation structure expected if the traits evolve by Brownian motion and fit a generalized least squares model assuming this correlation structure.&lt;br /&gt;
&lt;br /&gt;
     bm.geospiza&amp;lt;-corBrownian(phy=geospiza13.tree)&lt;br /&gt;
     bm.gls&amp;lt;-gls(wingL~tarsusL,correlation=bm.geospiza,data=DF.geospiza)&lt;br /&gt;
     summary(bm.gls)&lt;br /&gt;
&lt;br /&gt;
The summary shows you that the log likelihood of this model is 9.6 and its AIC score is -13.21.  We also see that the effect of tarsus length on wing length is 1.37, and their relationship is signficant (p=0.001).&lt;br /&gt;
&lt;br /&gt;
===Fitting an Ornstein-Uhlenbeck Motion model in PGLS===&lt;br /&gt;
&lt;br /&gt;
Again we will first build the correlation structure, this time assuming if the traits evolve as expected under the Ornstein-Uhlenbeck process with a variance-restraining parameter, alpha.  Ape automatically estimates the best fitting value of alpha for your data.&lt;br /&gt;
&lt;br /&gt;
     ou.geospiza&amp;lt;-corMartins(1,phy=geospiza13.tree)&lt;br /&gt;
     ou.gls&amp;lt;-gls(wingL~tarsusL,correlation=bm.geospiza,data=DF.geospiza)&lt;br /&gt;
     summary(ou.gls)&lt;br /&gt;
&lt;br /&gt;
The summary shows you that the estimated alpha is 8.13, the log likelihood of this model is 10.73, and its AIC score is -13.47.  This model estimates that the effect of tarsus length on wing length is 0.73, and their relationship is still significant (p=0.01).&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=492</id>
		<title>HowTo/PGLS</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=492"/>
		<updated>2008-02-06T19:20:54Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Phylogenetic Generalized Least Squares==&lt;br /&gt;
&lt;br /&gt;
PGLS is a powerful method for analyzing continuous data that has been applied to estimating adaptive optima (Butler and King 2004) and estimating the relationships among traits (e.g., body size and geographic range size in carnivores).  PGLS allows the user to specify different ways in which the tree structure is expected to affect the covariance in trait values across taxa.  For example, the user might assume that the trait evolves by Brownian motion and thus that the trait covariance between any pair of taxa decreases linearly with the time (in branch length) since their divergence.  Alternately, the user might apply a Ornstein-Uhlenbeck model where the expected covariance decreases exponentially, as governed by the parameter alpha (Martins and Hansen 1997).    These methods are implemented in the ape package.&lt;br /&gt;
&lt;br /&gt;
===Fitting a Brownian Motion model in PGLS===&lt;br /&gt;
&lt;br /&gt;
Let's return to the ''Geospiza'' dataset (within the geiger package) to try PGLS.  We assume that you have already loaded the necessary packages (geiger for the data and ape for the function) [[R_Hackathon/TransitionProbability|as described]]. Let's say we want to test whether there is a significant relationship between wing length and tarsus length, accounting for possible dependence among the data points (trait values) due to phylogenetic relatedness.&lt;br /&gt;
&lt;br /&gt;
First, let's prepare our tree for the analysis.   Our original tree has 14 taxa but we only have data for 13, so we must prune the tree.  We can take out the species for which we have no data (olivacea) as follows:&lt;br /&gt;
&lt;br /&gt;
     data(geospiza)&lt;br /&gt;
     attach(geospiza)&lt;br /&gt;
     geospiza13.tree&amp;lt;-drop.tip(geospiza.tree,&amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Now let's create a data frame containing just our traits of interest, with the row.names matching the tip.labels.  Most users will bring their data in from a tab-delimited table, for example by typing:&lt;br /&gt;
&lt;br /&gt;
     geospiza.data&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;,row.names=1)&lt;br /&gt;
 &lt;br /&gt;
where the row names are the taxon names.  NOTE: you must associate the taxon names with the trait values so that the values can be correctly tied to the tips of the tree!  See also [https://www.nescent.org/wg_phyloinformatics/R_Hackathon/Ancestral_State_Reconstruction this page].  With the dataset in active memory, we can create the dataframe as follows:&lt;br /&gt;
&lt;br /&gt;
     wingL&amp;lt;-geospiza.data$wingL&lt;br /&gt;
     tarsusL&amp;lt;-geospiza.data$tarsusL&lt;br /&gt;
     DF.geospiza&amp;lt;-data.frame(wingL,tarsusL,row.names=geospiza13.tree$tip.label)&lt;br /&gt;
     DF.geospiza&lt;br /&gt;
&lt;br /&gt;
When you type the final command, you will see that you have a data frame where the row names are the tip.labels in the pruned tree.  Now we will first build the correlation structure expected if the traits evolve by Brownian motion and fit a generalized least squares model assuming this correlation structure.&lt;br /&gt;
&lt;br /&gt;
     bm.geospiza&amp;lt;-corBrownian(phy=geospiza13.tree)&lt;br /&gt;
     bm.gls&amp;lt;-gls(wingL~tarsusL,correlation=bm.geospiza,data=DF.geospiza)&lt;br /&gt;
     summary(bm.gls)&lt;br /&gt;
&lt;br /&gt;
The summary shows you that the log likelihood of this model is 9.6 and its AIC score is -13.21.  We also see that the effect of tarsus length on wing length is 1.37, and their relationship is signficant (p=0.001).&lt;br /&gt;
&lt;br /&gt;
===Fitting an Ornstein-Uhlenbeck Motion model in PGLS===&lt;br /&gt;
&lt;br /&gt;
Again we will first build the correlation structure, this time assuming if the traits evolve as expected under the Ornstein-Uhlenbeck process with a variance-restraining parameter, alpha.  Ape automatically estimates the best fitting value of alpha for your data.&lt;br /&gt;
&lt;br /&gt;
     ou.geospiza&amp;lt;-corMartins(1,phy=geospiza13.tree)&lt;br /&gt;
     ou.gls&amp;lt;-gls(wingL~tarsusL,correlation=bm.geospiza,data=DF.geospiza)&lt;br /&gt;
     summary(ou.gls)&lt;br /&gt;
&lt;br /&gt;
The summary shows you that the estimated alpha is 8.13, the log likelihood of this model is 10.73, and its AIC score is -13.47.  This model estimates that the effect of tarsus length on wing length is 0.73, and their relationship is still significant (p=0.01).&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=491</id>
		<title>HowTo/PGLS</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=491"/>
		<updated>2008-02-06T19:18:55Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/PGLS moved to HowTo/PGLS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Phylogenetic Generalized Least Squares'''&lt;br /&gt;
&lt;br /&gt;
PGLS is a powerful method for analyzing continuous data that has been applied to estimating adaptive optima (Butler and King 2004) and estimating the relationships among traits (e.g., body size and geographic range size in carnivores).  PGLS allows the user to specify different ways in which the tree structure is expected to affect the covariance in trait values across taxa.  For example, the user might assume that the trait evolves by Brownian motion and thus that the trait covariance between any pair of taxa decreases linearly with the time (in branch length) since their divergence.  Alternately, the user might apply a Ornstein-Uhlenbeck model where the expected covariance decreases exponentially, as governed by the parameter alpha (Martins and Hansen 1997).    These methods are implemented in the ape package.&lt;br /&gt;
&lt;br /&gt;
'''Fitting a Brownian Motion model in PGLS'''&lt;br /&gt;
&lt;br /&gt;
Let's return to the ''Geospiza'' dataset (within the geiger package) to try PGLS.  We assume that you have already loaded the necessary packages (geiger for the data and ape for the function) as described on [https://www.nescent.org/wg_phyloinformatics/R_Hackathon/TransitionProbability this page]. Let's say we want to test whether there is a significant relationship between wing length and tarsus length, accounting for possible dependence among the data points (trait values) due to phylogenetic relatedness.&lt;br /&gt;
&lt;br /&gt;
First, let's prepare our tree for the analysis.   Our original tree has 14 taxa but we only have data for 13, so we must prune the tree.  We can take out the species for which we have no data (olivacea) as follows:&lt;br /&gt;
&lt;br /&gt;
     data(geospiza)&lt;br /&gt;
     attach(geospiza)&lt;br /&gt;
     geospiza13.tree&amp;lt;-drop.tip(geospiza.tree,&amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Now let's create a data frame containing just our traits of interest, with the row.names matching the tip.labels.  Most users will bring their data in from a tab-delimited table, for example by typing:&lt;br /&gt;
&lt;br /&gt;
     geospiza.data&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;,row.names=1)&lt;br /&gt;
 &lt;br /&gt;
where the row names are the taxon names.  NOTE: you must associate the taxon names with the trait values so that the values can be correctly tied to the tips of the tree!  See also [https://www.nescent.org/wg_phyloinformatics/R_Hackathon/Ancestral_State_Reconstruction this page].  With the dataset in active memory, we can create the dataframe as follows:&lt;br /&gt;
&lt;br /&gt;
     wingL&amp;lt;-geospiza.data$wingL&lt;br /&gt;
     tarsusL&amp;lt;-geospiza.data$tarsusL&lt;br /&gt;
     DF.geospiza&amp;lt;-data.frame(wingL,tarsusL,row.names=geospiza13.tree$tip.label)&lt;br /&gt;
     DF.geospiza&lt;br /&gt;
&lt;br /&gt;
When you type the final command, you will see that you have a data frame where the row names are the tip.labels in the pruned tree.  Now we will first build the correlation structure expected if the traits evolve by Brownian motion and fit a generalized least squares model assuming this correlation structure.&lt;br /&gt;
&lt;br /&gt;
     bm.geospiza&amp;lt;-corBrownian(phy=geospiza13.tree)&lt;br /&gt;
     bm.gls&amp;lt;-gls(wingL~tarsusL,correlation=bm.geospiza,data=DF.geospiza)&lt;br /&gt;
     summary(bm.gls)&lt;br /&gt;
&lt;br /&gt;
The summary shows you that the log likelihood of this model is 9.6 and its AIC score is -13.21.  We also see that the effect of tarsus length on wing length is 1.37, and their relationship is signficant (p=0.001).&lt;br /&gt;
&lt;br /&gt;
'''Fitting an Ornstein-Uhlenbeck Motion model in PGLS'''&lt;br /&gt;
&lt;br /&gt;
Again we will first build the correlation structure, this time assuming if the traits evolve as expected under the Ornstein-Uhlenbeck process with a variance-restraining parameter, alpha.  Ape automatically estimates the best fitting value of alpha for your data.&lt;br /&gt;
&lt;br /&gt;
     ou.geospiza&amp;lt;-corMartins(1,phy=geospiza13.tree)&lt;br /&gt;
     ou.gls&amp;lt;-gls(wingL~tarsusL,correlation=bm.geospiza,data=DF.geospiza)&lt;br /&gt;
     summary(ou.gls)&lt;br /&gt;
&lt;br /&gt;
The summary shows you that the estimated alpha is 8.13, the log likelihood of this model is 10.73, and its AIC score is -13.47.  This model estimates that the effect of tarsus length on wing length is 0.73, and their relationship is still significant (p=0.01).&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Diversification&amp;diff=320</id>
		<title>HowTo/Diversification</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Diversification&amp;diff=320"/>
		<updated>2008-02-06T19:18:36Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/Diversification moved to HowTo/Diversification&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WARNING THIS IS INCOMPLETE AND NOT NECESSARILY ACCURATE - IF YOU WANT TO CHANGE IT AND MAKE IT BETTER PLEASE DO!&lt;br /&gt;
&lt;br /&gt;
Analyses of Diversification are currently (Dec. 07) divided between several different packages in R: ape, apTreeshape, laser and geiger.  We will use a different dataset and tree from the other examples as the analyses will make more sense with a larger tree with branch times in years.&lt;br /&gt;
&lt;br /&gt;
Before running these analyses think carefully about how polytomies or zero length branches might affect the results.&lt;br /&gt;
&lt;br /&gt;
First make sure that geiger, apTreeshape, laser and geiger are loaded into r&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; library(ape)&lt;br /&gt;
   &amp;gt; library(geiger)&lt;br /&gt;
   &amp;gt; library(apTreeshape)&lt;br /&gt;
   &amp;gt; library(laser)&lt;br /&gt;
&lt;br /&gt;
Unlike other comparative methods packages in r, laser currently (Dec. 07) doesn't work on a phylogenetic tree (represented as a phylo class in ape) instead it works upon branching times.  To get branching times from a tree with branch lengths (genetic distance or years) use the function branching.times in ape.  This will calculate branching times associated with each node in the phylogeny and place them in an object. &lt;br /&gt;
&lt;br /&gt;
   &amp;gt; mybranchtimes &amp;lt;- branching.times(mytree)&lt;br /&gt;
&lt;br /&gt;
Laser needs the string of branching times to be ordered from 1st (earliest in the phylogeny) to last (most recent), if your string is not ordered it will automatically do this for you.&lt;br /&gt;
&lt;br /&gt;
==How do I make a lineage through time plot?==&lt;br /&gt;
Lineage through time plots can be done in ape and laser. These can be used to graphically depict whether diversification has been constant through time.  This example uses the function ltt.plot in ape.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ltt.plot(mytree, log=&amp;quot;y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The number of lineages will obviously increase over time if the phylogeny contains only extant species as no extinction is observed.  When the log of the number of lineages is plotted through time a straight line indicates diversification has been constant over time.  Deviations from the straight line indicate diversification has been constant, if the observed plot lies above the straight line diversification rates have decreased over time and if the plot lives below the line diversification rates have increased over time.  WARNING if diversification rates are heterogeneous then lineage-through-time plots are difficult to interpret.&lt;br /&gt;
&lt;br /&gt;
If you want to add another lineage-through-time plot to the same graph you can use the ltt.lines function in ape (this assumes you have more than one tree).&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ltt.plot(mytree1, log=&amp;quot;y&amp;quot;)&lt;br /&gt;
   &amp;gt; ltt.lines(mytree2, lty=2)&lt;br /&gt;
&lt;br /&gt;
Notice that specifying that the y axis is logarhithmic in ltt.plot means that the second line is also plotted on a log scale.  The lty command specifies the type of line so that the second ltt plot can be distinguished from the first plot.&lt;br /&gt;
   &lt;br /&gt;
==How do I calculate topological measures of diversification?==&lt;br /&gt;
apTreeshape contains functions for implementing Colless and Sackin's methods for topological measures of diversification as well as tests for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004).&lt;br /&gt;
&lt;br /&gt;
==How do I calculate shifts in diversification rate?==&lt;br /&gt;
&lt;br /&gt;
==How do I calculate net rates of diversification?==&lt;br /&gt;
geiger contains a function to calculate net rates of diversification (sensu Magellon and Sanderson).&lt;br /&gt;
&lt;br /&gt;
==How do I fit a simple pure birth model?==&lt;br /&gt;
&lt;br /&gt;
A pure birth model (Yule model) assumes that there is no extinction and there is  an instantaneous speciation probability. A birth-death model assumes that there is an instantaneous speciation probability and an instantaneous extinction probability. There are various modifications to the birth-death model that allow the probabilty of extinction and speciation to vary over time (Nee et al., 1994) or for the speciation probability to vary with respect to species traits (Paradis, 2005).&lt;br /&gt;
&lt;br /&gt;
To fit a Yule model to a set of branching times using laser use the function pureBirth.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; yulemodel&amp;lt;- pureBirth(mybranchtimes)&lt;br /&gt;
   &lt;br /&gt;
This gives you the maximum log-likelihood, the Akaike Information Criterion (AIC) and the speciation rate given the maximum log-likelihood.&lt;br /&gt;
&lt;br /&gt;
WARNING - don't use the Yule function in ape as it will return an erroneous log-likelihood although the estimated birth rate will be correct.&lt;br /&gt;
&lt;br /&gt;
To fit a multi-rate pure birth model to a set of branching times using laser use the function yule-n-rate. For example, specifying a yule2rate assumes that a clade diversifies under a speciation rate until some time where it shifts to a new rate, this shift point is found by optimizing parameters and computing likelihoods for a set of possible shift time and selecting the parameter combinations that give the maximum log-likelihood.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; yulerate2 &amp;lt;- yule2rate(mybranchtimes)&lt;br /&gt;
&lt;br /&gt;
This function requires that your tree is fully dichotomous, if you have zero length branches you might find that several identical branching times are identified as the time when the rate shift occurs this will be because they belong to the same polytomy. The shift times are given given in the divergence units (oftentimes years or genetic divergence) before present.&lt;br /&gt;
&lt;br /&gt;
==How do I fit a pure birth-death model?==&lt;br /&gt;
&lt;br /&gt;
To fit a simple birth-death model with the Nee et al. (1994) method to take into account the difficulty of estimateing maximum likelihood parameters when only the extant species are observed, use the birthdeath function in ape.   &lt;br /&gt;
&lt;br /&gt;
   &amp;gt; birthdeathmytree &amp;lt;- birthdeath(mytree)&lt;br /&gt;
&lt;br /&gt;
==How do I calculate the gamma statistic of Pybus &amp;amp; Harvey 2001?==&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
Nee, S., May, R. M. &amp;amp; Harvey, P. H. (1994) The reconstructed evolutionary process. ''Phil. Trans. Roy. Soc. Lond. B.'' 349, 25-31.&lt;br /&gt;
&lt;br /&gt;
Paradis, E. (2005) Statistical analysis of diversification with species traits. ''Evolution'' 59, 1-12.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Diversification&amp;diff=319</id>
		<title>HowTo/Diversification</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Diversification&amp;diff=319"/>
		<updated>2008-02-06T19:17:45Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WARNING THIS IS INCOMPLETE AND NOT NECESSARILY ACCURATE - IF YOU WANT TO CHANGE IT AND MAKE IT BETTER PLEASE DO!&lt;br /&gt;
&lt;br /&gt;
Analyses of Diversification are currently (Dec. 07) divided between several different packages in R: ape, apTreeshape, laser and geiger.  We will use a different dataset and tree from the other examples as the analyses will make more sense with a larger tree with branch times in years.&lt;br /&gt;
&lt;br /&gt;
Before running these analyses think carefully about how polytomies or zero length branches might affect the results.&lt;br /&gt;
&lt;br /&gt;
First make sure that geiger, apTreeshape, laser and geiger are loaded into r&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; library(ape)&lt;br /&gt;
   &amp;gt; library(geiger)&lt;br /&gt;
   &amp;gt; library(apTreeshape)&lt;br /&gt;
   &amp;gt; library(laser)&lt;br /&gt;
&lt;br /&gt;
Unlike other comparative methods packages in r, laser currently (Dec. 07) doesn't work on a phylogenetic tree (represented as a phylo class in ape) instead it works upon branching times.  To get branching times from a tree with branch lengths (genetic distance or years) use the function branching.times in ape.  This will calculate branching times associated with each node in the phylogeny and place them in an object. &lt;br /&gt;
&lt;br /&gt;
   &amp;gt; mybranchtimes &amp;lt;- branching.times(mytree)&lt;br /&gt;
&lt;br /&gt;
Laser needs the string of branching times to be ordered from 1st (earliest in the phylogeny) to last (most recent), if your string is not ordered it will automatically do this for you.&lt;br /&gt;
&lt;br /&gt;
==How do I make a lineage through time plot?==&lt;br /&gt;
Lineage through time plots can be done in ape and laser. These can be used to graphically depict whether diversification has been constant through time.  This example uses the function ltt.plot in ape.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ltt.plot(mytree, log=&amp;quot;y&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The number of lineages will obviously increase over time if the phylogeny contains only extant species as no extinction is observed.  When the log of the number of lineages is plotted through time a straight line indicates diversification has been constant over time.  Deviations from the straight line indicate diversification has been constant, if the observed plot lies above the straight line diversification rates have decreased over time and if the plot lives below the line diversification rates have increased over time.  WARNING if diversification rates are heterogeneous then lineage-through-time plots are difficult to interpret.&lt;br /&gt;
&lt;br /&gt;
If you want to add another lineage-through-time plot to the same graph you can use the ltt.lines function in ape (this assumes you have more than one tree).&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ltt.plot(mytree1, log=&amp;quot;y&amp;quot;)&lt;br /&gt;
   &amp;gt; ltt.lines(mytree2, lty=2)&lt;br /&gt;
&lt;br /&gt;
Notice that specifying that the y axis is logarhithmic in ltt.plot means that the second line is also plotted on a log scale.  The lty command specifies the type of line so that the second ltt plot can be distinguished from the first plot.&lt;br /&gt;
   &lt;br /&gt;
==How do I calculate topological measures of diversification?==&lt;br /&gt;
apTreeshape contains functions for implementing Colless and Sackin's methods for topological measures of diversification as well as tests for significant shifts in diversification (sensu Moore, Chan and Donoghue 2004).&lt;br /&gt;
&lt;br /&gt;
==How do I calculate shifts in diversification rate?==&lt;br /&gt;
&lt;br /&gt;
==How do I calculate net rates of diversification?==&lt;br /&gt;
geiger contains a function to calculate net rates of diversification (sensu Magellon and Sanderson).&lt;br /&gt;
&lt;br /&gt;
==How do I fit a simple pure birth model?==&lt;br /&gt;
&lt;br /&gt;
A pure birth model (Yule model) assumes that there is no extinction and there is  an instantaneous speciation probability. A birth-death model assumes that there is an instantaneous speciation probability and an instantaneous extinction probability. There are various modifications to the birth-death model that allow the probabilty of extinction and speciation to vary over time (Nee et al., 1994) or for the speciation probability to vary with respect to species traits (Paradis, 2005).&lt;br /&gt;
&lt;br /&gt;
To fit a Yule model to a set of branching times using laser use the function pureBirth.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; yulemodel&amp;lt;- pureBirth(mybranchtimes)&lt;br /&gt;
   &lt;br /&gt;
This gives you the maximum log-likelihood, the Akaike Information Criterion (AIC) and the speciation rate given the maximum log-likelihood.&lt;br /&gt;
&lt;br /&gt;
WARNING - don't use the Yule function in ape as it will return an erroneous log-likelihood although the estimated birth rate will be correct.&lt;br /&gt;
&lt;br /&gt;
To fit a multi-rate pure birth model to a set of branching times using laser use the function yule-n-rate. For example, specifying a yule2rate assumes that a clade diversifies under a speciation rate until some time where it shifts to a new rate, this shift point is found by optimizing parameters and computing likelihoods for a set of possible shift time and selecting the parameter combinations that give the maximum log-likelihood.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; yulerate2 &amp;lt;- yule2rate(mybranchtimes)&lt;br /&gt;
&lt;br /&gt;
This function requires that your tree is fully dichotomous, if you have zero length branches you might find that several identical branching times are identified as the time when the rate shift occurs this will be because they belong to the same polytomy. The shift times are given given in the divergence units (oftentimes years or genetic divergence) before present.&lt;br /&gt;
&lt;br /&gt;
==How do I fit a pure birth-death model?==&lt;br /&gt;
&lt;br /&gt;
To fit a simple birth-death model with the Nee et al. (1994) method to take into account the difficulty of estimateing maximum likelihood parameters when only the extant species are observed, use the birthdeath function in ape.   &lt;br /&gt;
&lt;br /&gt;
   &amp;gt; birthdeathmytree &amp;lt;- birthdeath(mytree)&lt;br /&gt;
&lt;br /&gt;
==How do I calculate the gamma statistic of Pybus &amp;amp; Harvey 2001?==&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
Nee, S., May, R. M. &amp;amp; Harvey, P. H. (1994) The reconstructed evolutionary process. ''Phil. Trans. Roy. Soc. Lond. B.'' 349, 25-31.&lt;br /&gt;
&lt;br /&gt;
Paradis, E. (2005) Statistical analysis of diversification with species traits. ''Evolution'' 59, 1-12.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Phylogenetic_Independent_Contrasts&amp;diff=531</id>
		<title>HowTo/Phylogenetic Independent Contrasts</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Phylogenetic_Independent_Contrasts&amp;diff=531"/>
		<updated>2008-02-06T19:16:42Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Phylogenetic Independent Contrasts==&lt;br /&gt;
&lt;br /&gt;
This example assumes you have installed R and the package ape (if not start [[R_Hackathon/GettingStarted| here]]) and downloaded the tree and dataset Geospiza from [[Media:geospiza.rda|geospiza.rda]]. Upload the tree and data file into your R workspace as a phylo Class for the tree (read.nexus) and a dataframe for the data (read.table).&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; library(ape)&lt;br /&gt;
   &amp;gt; mydata&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
   &amp;gt; mytree&amp;lt;-read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The following example will calculate phylogenetic independent contrasts (Felsenstein, 1985) using the '''pic''' function in ape. &lt;br /&gt;
&lt;br /&gt;
IMPORTANT you can only calculate contrasts on a single variable, the soon to be released CAIC package will allow you to run more than one trait at a time as well as discrete traits.&lt;br /&gt;
&lt;br /&gt;
WARNING your tree must be fully dichotomous and there must be no gaps in your data. &lt;br /&gt;
&lt;br /&gt;
So remove the outgroup &amp;quot;olivacea&amp;quot; from the tree as there are no data for it in the dataframe.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; mytree &amp;lt;- drop.tip(mytree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
===Calculating Contrasts===&lt;br /&gt;
&lt;br /&gt;
Create a numeric vector for the traits wingL and tarsusL&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; wingL &amp;lt;- mydata$wingL&lt;br /&gt;
   &amp;gt; tarsusL &amp;lt;- mydata$tarsusL&lt;br /&gt;
&lt;br /&gt;
However if you leave the data like this the analysis will run but the data will not be associated with the correct tips. So as long as your row names in your dataframe (mydata) match the tip labels in the phylogeny (mytree$tip.label) you can associate the data with the correct tip by:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; names(wingL) &amp;lt;- row.names(mydata)&lt;br /&gt;
   &amp;gt; names(tarsusL) &amp;lt;- row.names(mydata)&lt;br /&gt;
&lt;br /&gt;
To calculate contrasts that have been scaled using the expected variances:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree)&lt;br /&gt;
   &amp;gt; ContrasttarsusL &amp;lt;- pic(tarsusL, mytree)&lt;br /&gt;
&lt;br /&gt;
If you want to extract the expected variances as well as the contrasts:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree, var.contrasts=TRUE)&lt;br /&gt;
&lt;br /&gt;
If you don't want to scale the contrasts using the expected variances:&lt;br /&gt;
&lt;br /&gt;
  &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree, scaled=FALSE)&lt;br /&gt;
&lt;br /&gt;
===Displaying Contrasts===&lt;br /&gt;
&lt;br /&gt;
To see the contrasts of the wingL variable type:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL&lt;br /&gt;
&lt;br /&gt;
To see the contrasts plotted at the appropriate nodes, when you have saved both expected variances and contrasts to the object ContrastwingL and ContrasttarsusL,  use the function nodelabels:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot (mytree)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrastwingL [,1], 3), adj = c(0, -0.5), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrasttarsusL [,1], 3), adj = c(0, 1), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
So what is this code actually doing?  it is plotting the first column ([,1]) of the object ContrastwingL to 3 decimal places (round(ContrastwingL [,1], 3). You will notice that the instructions for the 2 sets of contrasts are slightly different, this is to stop the 2 values being printed upon one another! &lt;br /&gt;
&lt;br /&gt;
To see the contrasts plotted at the appropriate nodes, when you have only saved the contrasts to the object ContrastwingL and ContrasttarsusL,  use the function nodelabels:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot (mytree)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrastwingL, 3), adj = c(0, -0.5), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrasttarsusL, 3), adj = c(0, 1), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
===Correlated Trait Evolution===&lt;br /&gt;
&lt;br /&gt;
To run a linear regression on the wing and tarsus contrasts when we have not extracted the variances:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; RegressTarsusWing &amp;lt;- lm(ContrastwingL~ContrasttarsusL -1)&lt;br /&gt;
&lt;br /&gt;
The -1 specifies that the regression is through the origin (the intercept is set to zero) as recommended by Garland et al., 1992.&lt;br /&gt;
 &lt;br /&gt;
If you have extracted the expected variances there will be more than one column in the objects ContrastwingL and ContrasttarsusL so you need to specify that the contrasts are in the first column:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; RegressTarsusWing &amp;lt;- lm(ContrastwingL [,1]~ContrasttarsusL [,1] -1)&lt;br /&gt;
&lt;br /&gt;
To see the regression statistics:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; summary.lm(RegressTarsusWing)&lt;br /&gt;
&lt;br /&gt;
To plot the contrasts to visualize the regression - which is always wise to check that they meet the assumption of linear relationship between the 2 variables:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot(ContrastwingL [,1], ContrasttarsusL [,1])&lt;br /&gt;
&lt;br /&gt;
To add the regression line to the plot you add the regression coefficients from the linear regression.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; abline(RegressTarsusWing)&lt;br /&gt;
&lt;br /&gt;
You can change lots of things about the plot such as the line thickness, colour etc. to see more information type:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; help(plot)&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
Felsenstein, J. (1985) Phylogenies and the comparative method. ''Am. Nat.'' 125, 1-15.&lt;br /&gt;
&lt;br /&gt;
Garland, Jr. T., Harvey, P.H. &amp;amp; Ives, A. R. (1992) Procedures for the analysis of comparative data using phylogenetically independent contrasts. ''Syst. Biol'' 41, 18-32.&lt;br /&gt;
&lt;br /&gt;
Purvis, A. &amp;amp; Rambaut, A. (1995) Comparative Analysis by Independent Contrasts (CAIC): an Apple Macintosh application for analysing comparative data. ''Bioinformatics'' 11(3), 247-251.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Phylogenetic_Independent_Contrasts&amp;diff=530</id>
		<title>HowTo/Phylogenetic Independent Contrasts</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Phylogenetic_Independent_Contrasts&amp;diff=530"/>
		<updated>2008-02-06T19:16:21Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Phylogenetic Independent Contrasts==&lt;br /&gt;
&lt;br /&gt;
This example assumes you have installed R and the package ape (if not start [[R_Hackathon/GettingStarted| here]]) and downloaded the tree and dataset Geospiza from [[Media:geospiza.rda|geospiza.rda]]. Upload the tree and data file into your R workspace as a phylo Class for the tree (read.nexus) and a dataframe for the data (read.table).&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; library(ape)&lt;br /&gt;
   &amp;gt; mydata&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
   &amp;gt; mytree&amp;lt;-read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The following example will calculate phylogenetic independent contrasts (Felsenstein, 1985) using the '''pic''' function in ape. &lt;br /&gt;
&lt;br /&gt;
IMPORTANT you can only calculate contrasts on a single variable, the soon to be released CAIC package will allow you to run more than one trait at a time as well as discrete traits.&lt;br /&gt;
&lt;br /&gt;
WARNING your tree must be fully dichotomous and there must be no gaps in your data. &lt;br /&gt;
&lt;br /&gt;
So remove the outgroup &amp;quot;olivacea&amp;quot; from the tree as there are no data for it in the dataframe.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; mytree &amp;lt;- drop.tip(mytree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
===Calculating Contrasts===&lt;br /&gt;
&lt;br /&gt;
Create a numeric vector for the traits wingL and tarsusL&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; wingL &amp;lt;- mydata$wingL&lt;br /&gt;
   &amp;gt; tarsusL &amp;lt;- mydata$tarsusL&lt;br /&gt;
&lt;br /&gt;
However if you leave the data like this the analysis will run but the data will not be associated with the correct tips. So as long as your row names in your dataframe (mydata) match the tip labels in the phylogeny (mytree$tip.label) you can associate the data with the correct tip by:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; names(wingL) &amp;lt;- row.names(mydata)&lt;br /&gt;
   &amp;gt; names(tarsusL) &amp;lt;- row.names(mydata)&lt;br /&gt;
&lt;br /&gt;
To calculate contrasts that have been scaled using the expected variances:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree)&lt;br /&gt;
   &amp;gt; ContrasttarsusL &amp;lt;- pic(tarsusL, mytree)&lt;br /&gt;
&lt;br /&gt;
If you want to extract the expected variances as well as the contrasts:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree, var.contrasts=TRUE)&lt;br /&gt;
&lt;br /&gt;
If you don't want to scale the contrasts using the expected variances:&lt;br /&gt;
&lt;br /&gt;
  &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree, scaled=FALSE)&lt;br /&gt;
&lt;br /&gt;
===Displaying Contrasts===&lt;br /&gt;
&lt;br /&gt;
To see the contrasts of the wingL variable type:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL&lt;br /&gt;
&lt;br /&gt;
To see the contrasts plotted at the appropriate nodes, when you have saved both expected variances and contrasts to the object ContrastwingL and ContrasttarsusL,  use the function nodelabels:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot (mytree)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrastwingL [,1], 3), adj = c(0, -0.5), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrasttarsusL [,1], 3), adj = c(0, 1), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
So what is this code actually doing?  it is plotting the first column ([,1]) of the object ContrastwingL to 3 decimal places (round(ContrastwingL [,1], 3). You will notice that the instructions for the 2 sets of contrasts are slightly different, this is to stop the 2 values being printed upon one another! &lt;br /&gt;
&lt;br /&gt;
To see the contrasts plotted at the appropriate nodes, when you have only saved the contrasts to the object ContrastwingL and ContrasttarsusL,  use the function nodelabels:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot (mytree)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrastwingL, 3), adj = c(0, -0.5), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrasttarsusL, 3), adj = c(0, 1), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
===Correlated Trait Evolution===&lt;br /&gt;
&lt;br /&gt;
To run a linear regression on the wing and tarsus contrasts when we have not extracted the variances:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; RegressTarsusWing &amp;lt;- lm(ContrastwingL~ContrasttarsusL -1)&lt;br /&gt;
&lt;br /&gt;
The -1 specifies that the regression is through the origin (the intercept is set to zero) as recommended by Garland et al., 1992.&lt;br /&gt;
 &lt;br /&gt;
If you have extracted the expected variances there will be more than one column in the objects ContrastwingL and ContrasttarsusL so you need to specify that the contrasts are in the first column:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; RegressTarsusWing &amp;lt;- lm(ContrastwingL [,1]~ContrasttarsusL [,1] -1)&lt;br /&gt;
&lt;br /&gt;
To see the regression statistics:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; summary.lm(RegressTarsusWing)&lt;br /&gt;
&lt;br /&gt;
To plot the contrasts to visualize the regression - which is always wise to check that they meet the assumption of linear relationship between the 2 variables:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot(ContrastwingL [,1], ContrasttarsusL [,1])&lt;br /&gt;
&lt;br /&gt;
To add the regression line to the plot you add the regression coefficients from the linear regression.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; abline(RegressTarsusWing)&lt;br /&gt;
&lt;br /&gt;
You can change lots of things about the plot such as the line thickness, colour etc. to see more information type:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; help(plot)&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
&lt;br /&gt;
Felsenstein, J. (1985) Phylogenies and the comparative method. ''Am. Nat.'' 125, 1-15.&lt;br /&gt;
&lt;br /&gt;
Garland, Jr. T., Harvey, P.H. &amp;amp; Ives, A. R. (1992) Procedures for the analysis of comparative data using phylogenetically independent contrasts. ''Syst. Biol'' 41, 18-32.&lt;br /&gt;
&lt;br /&gt;
Purvis, A. &amp;amp; Rambaut, A. (1995) Comparative Analysis by Independent Contrasts (CAIC): an Apple Macintosh application for analysing comparative data. ''Bioinformatics'' 11(3), 247-251.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/Phylogenetic_Independent_Contrasts&amp;diff=529</id>
		<title>HowTo/Phylogenetic Independent Contrasts</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/Phylogenetic_Independent_Contrasts&amp;diff=529"/>
		<updated>2008-02-06T19:12:27Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/PhylogeneticIndependentContrasts moved to HowTo/Phylogenetic Independent Contrasts&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Phylogenetic Independent Contrasts==&lt;br /&gt;
&lt;br /&gt;
This example assumes you have installed R and the package ape (if not start [[R_Hackathon/GettingStarted| here]]) and downloaded the tree and dataset Geospiza from [[ xxx| here]]. Upload the tree and data file ainto your R workspace as a phylo Class for the tree (read.nexus) and a dataframe for the data (read.table).&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; library(ape)&lt;br /&gt;
   &amp;gt; mydata&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
   &amp;gt; mytree&amp;lt;-read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The following example will calculate phylogenetic independent contrasts (Felsenstein, 1985) using the '''pic''' function in ape. &lt;br /&gt;
&lt;br /&gt;
IMPORTANT you can only calculate contrasts on a single variable, the soon to be released CAIC package will allow you to run more than one trait at a time as well as discrete traits.&lt;br /&gt;
&lt;br /&gt;
WARNING your tree must be fully dichotomous and there must be no gaps in your data. &lt;br /&gt;
&lt;br /&gt;
So remove the outgroup &amp;quot;olivacea&amp;quot; from the tree as there are no data for it in the dataframe.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; mytree &amp;lt;- drop.tip(mytree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
'''Calculating Contrasts'''&lt;br /&gt;
&lt;br /&gt;
Create a numeric vector for the traits wingL and tarsusL&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; wingL &amp;lt;- mydata$wingL&lt;br /&gt;
   &amp;gt; tarsusL &amp;lt;- mydata$tarsusL&lt;br /&gt;
&lt;br /&gt;
However if you leave the data like this the analysis will run but the data will not be associated with the correct tips. So as long as your row names in your dataframe (mydata) match the tip labels in the phylogeny (mytree$tip.label) you can associate the data with the correct tip by:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; names(wingL) &amp;lt;- row.names(mydata)&lt;br /&gt;
   &amp;gt; names(tarsusL) &amp;lt;- row.names(mydata)&lt;br /&gt;
&lt;br /&gt;
To calculate contrasts that have been scaled using the expected variances:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree)&lt;br /&gt;
   &amp;gt; ContrasttarsusL &amp;lt;- pic(tarsusL, mytree)&lt;br /&gt;
&lt;br /&gt;
If you want to extract the expected variances as well as the contrasts:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree, var.contrasts=TRUE)&lt;br /&gt;
&lt;br /&gt;
If you don't want to scale the contrasts using the expected variances:&lt;br /&gt;
&lt;br /&gt;
  &amp;gt; ContrastwingL &amp;lt;- pic(wingL, mytree, scaled=FALSE)&lt;br /&gt;
&lt;br /&gt;
'''Displaying Contrasts'''&lt;br /&gt;
&lt;br /&gt;
To see the contrasts of the wingL variable type:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; ContrastwingL&lt;br /&gt;
&lt;br /&gt;
To see the contrasts plotted at the appropriate nodes, when you have saved both expected variances and contrasts to the object ContrastwingL and ContrasttarsusL,  use the function nodelabels:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot (mytree)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrastwingL [,1], 3), adj = c(0, -0.5), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrasttarsusL [,1], 3), adj = c(0, 1), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
So what is this code actually doing?  it is plotting the first column ([,1]) of the object ContrastwingL to 3 decimal places (round(ContrastwingL [,1], 3). You will notice that the instructions for the 2 sets of contrasts are slightly different, this is to stop the 2 values being printed upon one another! &lt;br /&gt;
&lt;br /&gt;
To see the contrasts plotted at the appropriate nodes, when you have only saved the contrasts to the object ContrastwingL and ContrasttarsusL,  use the function nodelabels:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot (mytree)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrastwingL, 3), adj = c(0, -0.5), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
   &amp;gt; nodelabels(round(ContrasttarsusL, 3), adj = c(0, 1), frame=&amp;quot;n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Correlated Trait Evolution'''&lt;br /&gt;
&lt;br /&gt;
To run a linear regression on the wing and tarsus contrasts when we have not extracted the variances:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; RegressTarsusWing &amp;lt;- lm(ContrastwingL~ContrasttarsusL -1)&lt;br /&gt;
&lt;br /&gt;
The -1 specifies that the regression is through the origin (the intercept is set to zero) as recommended by Garland et al., 1992.&lt;br /&gt;
 &lt;br /&gt;
If you have extracted the expected variances there will be more than one column in the objects ContrastwingL and ContrasttarsusL so you need to specify that the contrasts are in the first column:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; RegressTarsusWing &amp;lt;- lm(ContrastwingL [,1]~ContrasttarsusL [,1] -1)&lt;br /&gt;
&lt;br /&gt;
To see the regression statistics:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; summary.lm(RegressTarsusWing)&lt;br /&gt;
&lt;br /&gt;
To plot the contrasts to visualize the regression - which is always wise to check that they meet the assumption of linear relationship between the 2 variables:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; plot(ContrastwingL [,1], ContrasttarsusL [,1])&lt;br /&gt;
&lt;br /&gt;
To add the regression line to the plot you add the regression coefficients from the linear regression.&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; abline(RegressTarsusWing)&lt;br /&gt;
&lt;br /&gt;
You can change lots of things about the plot such as the line thickness, colour etc. to see more information type:&lt;br /&gt;
&lt;br /&gt;
   &amp;gt; help(plot)&lt;br /&gt;
&lt;br /&gt;
'''References'''&lt;br /&gt;
&lt;br /&gt;
Felsenstein, J. (1985) Phylogenies and the comparative method. ''Am. Nat.'' 125, 1-15.&lt;br /&gt;
&lt;br /&gt;
Garland, Jr. T., Harvey, P.H. &amp;amp; Ives, A. R. (1992) Procedures for the analysis of comparative data using phylogenetically independent contrasts. ''Syst. Biol'' 41, 18-32.&lt;br /&gt;
&lt;br /&gt;
Purvis, A. &amp;amp; Rambaut, A. (1995) Comparative Analysis by Independent Contrasts (CAIC): an Apple Macintosh application for analysing comparative data. ''Bioinformatics'' 11(3), 247-251.&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForContinuousData&amp;diff=194</id>
		<title>HowTo/InferringModelsForContinuousData</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForContinuousData&amp;diff=194"/>
		<updated>2008-02-06T19:11:40Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inferring Models for Continuous Characters in R ==&lt;br /&gt;
&lt;br /&gt;
Most investigations into the evolution of continuous characters start with the Brownian Motion (BM) model.  This model is analytically very tractable, and is the basis for a variety of comparative method approaches (e.g., independent contrasts, most instances of phylogenetic GLS).  A variety of extensions to BM have been developed; here we focus on the BM model and one alternative: an Ornstein-Uhlenbeck (OU) model with a single optimum. &lt;br /&gt;
&lt;br /&gt;
== Fitting Evolutionary Models ==&lt;br /&gt;
&lt;br /&gt;
Start by reading in the Geospiza data and extracting the the wingL varable into a variable called 'wL'&lt;br /&gt;
&lt;br /&gt;
   data(geospiza)&lt;br /&gt;
   wL&amp;lt;- geospiza$geospiza.data[,1] &lt;br /&gt;
   names(wL)&amp;lt;- row.names(geospiza$geospiza.data)&lt;br /&gt;
&lt;br /&gt;
Get the Geospiza tree, call it 'tr.'  Then drop the olivacea species and save the new tree as 'tr2.'&lt;br /&gt;
&lt;br /&gt;
  tr&amp;lt;- geospiza$geospiza.tree&lt;br /&gt;
  tr2&amp;lt;- drop.tip(tr, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Now, we are ready to fit the BM using geiger's fitContinuous function.&lt;br /&gt;
&lt;br /&gt;
   BMfit &amp;lt;- fitContinuous(tr2, wL, model=&amp;quot;BM&amp;quot;)&lt;br /&gt;
   BMfit&lt;br /&gt;
&lt;br /&gt;
Note that the reported rate parameter ('beta') is 0.0705, with a log-likelihood of 8.243, and a AICc of -11.153.&lt;br /&gt;
&lt;br /&gt;
We can also fit an Orstein-Uhlenbeck model with one optimum to these data.  According to this model, there exists an optimal phenotypic value, to which evolutionary trajectories are attracted.  This approach has been used to model adaption on macroevolutionary time scales.  &lt;br /&gt;
&lt;br /&gt;
  OUfit &amp;lt;- fitContinuous(tr2, wL, model=&amp;quot;OU&amp;quot;)&lt;br /&gt;
  OUfit&lt;br /&gt;
&lt;br /&gt;
The solution for this OU model gives a rather high alpha parameter, which measures the strength of the attraction to the optimum.  This estimate should be close to alpha = 15.79, which corresponds to a phylogenetic half-life of log(2)/alpha = 0.043 units. By plotting the tree and adding an axis, &lt;br /&gt;
&lt;br /&gt;
  plot(tr2)&lt;br /&gt;
  axisPhylo()&lt;br /&gt;
&lt;br /&gt;
you can see that this is a rather short duration relative to the temporal span of the tree.  This is indicative of evolutionary trajectories that are rapidly drawn to the phenotypic optimum.&lt;br /&gt;
&lt;br /&gt;
== Comparing the Fit of Evolutionary Models ==&lt;br /&gt;
&lt;br /&gt;
Because the two fitted models have different numbers of parameters (two for BM, three for OU), their log-likelihoods cannot be compared directly.  One useful way to compare the performance of these models is though their Akaike Information Criterion, which balances goodness of fit (log-likelihood) against model complexity as measured by the number of parameters.  For relatively small data sets, it is generally recommended to use a bias-corrected version of the AIC, often called AICc.  Lower values for AICc indicate more support, and so the BM model, with an AICc score of -11.15, is more strongly supported than the OU model (AICc = -10.68).  However, the difference in scores is not great, and so neither model conclusively outperforms the other.&lt;br /&gt;
&lt;br /&gt;
== A Note about Multiple Implementations of these Methods ==&lt;br /&gt;
&lt;br /&gt;
Currently, there are multiple implementations of several of these models across different packages.  The results are not always the same across methods, however, because either the purpose of the analysis is slightly different across packages, or the implementations use different computational strategies.  The models that currently have multiple implementations as of this writing (13 December 2007) are (i) Brownian motion and (ii) Ornstein-Uhlenbeck with one optimum.&lt;br /&gt;
&lt;br /&gt;
'''Brownian motion'''&lt;br /&gt;
&lt;br /&gt;
Currently, there are three packages that implement inference of the BM model: ape in function ace(), geiger in function fitContinuous(), and ouch in function brown.fit().  The function ace() will return a log-likelihood and a parameter estimate for the BM model, but these are conditional upon the reconstructed trait values of the nodes.  This is consistent with the main purpose of ace(), but these results are not comparable with other model fits (which are not usually conditioned in this way).  Thus, unless your main focus is on ancestral reconstructions, you should probably be using the functions in either geiger or ouch to fit the BM model.&lt;br /&gt;
&lt;br /&gt;
The functions in geiger and ouch share the approach of not conditioning the model fits on particular values at ancestral nodes.  Although their computational strategies differ somewhat, they seem to produce log-likelihoods and rate estimates that are very nearly the same (note that rate parameter in ouch, &amp;quot;sigma&amp;quot;, is the square root of the rate parameter in geiger, &amp;quot;beta&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''Ornstein-Uhlenbeck'''&lt;br /&gt;
&lt;br /&gt;
Both geiger and ouch can fit OU models with a single optimum (only ouch can currently fit OU models with more than one optimum).  Again, the approaches differ in algorithmic approach.  The log-likelihoods produced seem to be very similar, but the parameter estimates may not be.  Differences in the parameter estimates reflect that this can be a very difficult model to fit, as there is often a very large ridge over which the log-likelihood changes very little.  The differences can be small enough so that optimization routines can differ as to where they stop along this ridge.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForContinuousData&amp;diff=193</id>
		<title>HowTo/InferringModelsForContinuousData</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForContinuousData&amp;diff=193"/>
		<updated>2008-02-06T19:11:11Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/ContinuousData moved to HowTo/ContinuousData&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inferring Models for Continuous Characters in R ==&lt;br /&gt;
&lt;br /&gt;
Most investigations into the evolution of continuous characters start with the Brownian Motion (BM) model.  This model is analytically very tractable, and is the basis for a variety of comparative method approaches (e.g., independent contrasts, most instances of phylogenetic GLS).  A variety of extensions to BM have been developed; here we focus on the BM model and one alternative: an Ornstein-Uhlenbeck (OU) model with a single optimum. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Fitting Evolutionary Models ==&lt;br /&gt;
&lt;br /&gt;
Start by reading in the Geospiza data and extracting the the wingL varable into a variable called 'wL'&lt;br /&gt;
&lt;br /&gt;
   data(geospiza)&lt;br /&gt;
   wL&amp;lt;- geospiza$geospiza.data[,1] &lt;br /&gt;
   names(wL)&amp;lt;- row.names(geospiza$geospiza.data)&lt;br /&gt;
&lt;br /&gt;
Get the Geospiza tree, call it 'tr.'  Then drop the olivacea species and save the new tree as 'tr2.'&lt;br /&gt;
&lt;br /&gt;
  tr&amp;lt;- geospiza$geospiza.tree&lt;br /&gt;
  tr2&amp;lt;- drop.tip(tr, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Now, we are ready to fit the BM using geiger's fitContinuous function.&lt;br /&gt;
&lt;br /&gt;
   BMfit &amp;lt;- fitContinuous(tr2, wL, model=&amp;quot;BM&amp;quot;)&lt;br /&gt;
   BMfit&lt;br /&gt;
&lt;br /&gt;
Note that the reported rate parameter ('beta') is 0.0705, with a log-likelihood of 8.243, and a AICc of -11.153.&lt;br /&gt;
&lt;br /&gt;
We can also fit an Orstein-Uhlenbeck model with one optimum to these data.  According to this model, there exists an optimal phenotypic value, to which evolutionary trajectories are attracted.  This approach has been used to model adaption on macroevolutionary time scales.  &lt;br /&gt;
&lt;br /&gt;
  OUfit &amp;lt;- fitContinuous(tr2, wL, model=&amp;quot;OU&amp;quot;)&lt;br /&gt;
  OUfit&lt;br /&gt;
&lt;br /&gt;
The solution for this OU model gives a rather high alpha parameter, which measures the strength of the attraction to the optimum.  This estimate should be close to alpha = 15.79, which corresponds to a phylogenetic half-life of log(2)/alpha = 0.043 units. By plotting the tree and adding an axis, &lt;br /&gt;
&lt;br /&gt;
  plot(tr2)&lt;br /&gt;
  axisPhylo()&lt;br /&gt;
&lt;br /&gt;
you can see that this is a rather short duration relative to the temporal span of the tree.  This is indicative of evolutionary trajectories that are rapidly drawn to the phenotypic optimum.&lt;br /&gt;
&lt;br /&gt;
== Comparing the Fit of Evolutionary Models ==&lt;br /&gt;
&lt;br /&gt;
Because the two fitted models have different numbers of parameters (two for BM, three for OU), their log-likelihoods cannot be compared directly.  One useful way to compare the performance of these models is though their Akaike Information Criterion, which balances goodness of fit (log-likelihood) against model complexity as measured by the number of parameters.  For relatively small data sets, it is generally recommended to use a bias-corrected version of the AIC, often called AICc.  Lower values for AICc indicate more support, and so the BM model, with an AICc score of -11.15, is more strongly supported than the OU model (AICc = -10.68).  However, the difference in scores is not great, and so neither model conclusively outperforms the other.&lt;br /&gt;
&lt;br /&gt;
== A Note about Multiple Implementations of these Methods ==&lt;br /&gt;
&lt;br /&gt;
Currently, there are multiple implementations of several of these models across different packages.  The results are not always the same across methods, however, because either the purpose of the analysis is slightly different across packages, or the implementations use different computational strategies.  The models that currently have multiple implementations as of this writing (13 December 2007) are (i) Brownian motion and (ii) Ornstein-Uhlenbeck with one optimum.&lt;br /&gt;
&lt;br /&gt;
'''Brownian motion'''&lt;br /&gt;
&lt;br /&gt;
Currently, there are three packages that implement inference of the BM model: ape in function ace(), geiger in function fitContinuous(), and ouch in function brown.fit().  The function ace() will return a log-likelihood and a parameter estimate for the BM model, but these are conditional upon the reconstructed trait values of the nodes.  This is consistent with the main purpose of ace(), but these results are not comparable with other model fits (which are not usually conditioned in this way).  Thus, unless your main focus is on ancestral reconstructions, you should probably be using the functions in either geiger or ouch to fit the BM model.&lt;br /&gt;
&lt;br /&gt;
The functions in geiger and ouch share the approach of not conditioning the model fits on particular values at ancestral nodes.  Although their computational strategies differ somewhat, they seem to produce log-likelihoods and rate estimates that are very nearly the same (note that rate parameter in ouch, &amp;quot;sigma&amp;quot;, is the square root of the rate parameter in geiger, &amp;quot;beta&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''Ornstein-Uhlenbeck'''&lt;br /&gt;
&lt;br /&gt;
Both geiger and ouch can fit OU models with a single optimum (only ouch can currently fit OU models with more than one optimum).  Again, the approaches differ in algorithmic approach.  The log-likelihoods produced seem to be very similar, but the parameter estimates may not be.  Differences in the parameter estimates reflect that this can be a very difficult model to fit, as there is often a very large ridge over which the log-likelihood changes very little.  The differences can be small enough so that optimization routines can differ as to where they stop along this ridge.&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/CorrelatedDiscrete&amp;diff=203</id>
		<title>HowTo/CorrelatedDiscrete</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/CorrelatedDiscrete&amp;diff=203"/>
		<updated>2008-02-06T19:10:54Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/CorrelatedDiscrete moved to HowTo/CorrelatedDiscrete&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Not developed yet in R!&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForDiscreteData&amp;diff=593</id>
		<title>HowTo/InferringModelsForDiscreteData</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForDiscreteData&amp;diff=593"/>
		<updated>2008-02-06T19:10:35Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Modeling Discrete Character Evolution in R'''&lt;br /&gt;
&lt;br /&gt;
The evolution of a discrete character along a branch of a phylogeny can be modeled as a Markovian process, where the probability of moving the current state to a different state is governed by a rate matrix.  We can learn about discrete character evolution by calculating and comparing the likelihoods under models which impose different requirements on this matrix.  For example, we might compare a Jukes-Cantor model (where the probability of going from state 0 to state 1 is equal to the probability of going in the reverse direction) to an asymetrical model where the two rates are allowed to differ.  If we found the latter model was a significantly better fit, we might conclude that the trait in question evolves in a directional fashion.&lt;br /&gt;
&lt;br /&gt;
Estimating transition rates and calculating the likelihood of different models for discrete character evolution can be accomplished with the packages geiger (the fitDiscrete function) and ape (the ace function).&lt;br /&gt;
&lt;br /&gt;
'''Estimating a Jukes-Cantor model with the geiger package''' (load the package before you begin)&lt;br /&gt;
&lt;br /&gt;
We will use the ''Geospiza'' dataset for this example and we assume that you have already loaded your tree into the workspace as a phylo object (see [[R_Hackathon/InputtingTrees|Inputting Trees]]).  &lt;br /&gt;
&lt;br /&gt;
So first let's create a vector with character states for &amp;quot;Geospiza&amp;quot;.   The dataset has 14 species.  We can see a list of the species with the following commands:&lt;br /&gt;
&lt;br /&gt;
      data(geospiza)&lt;br /&gt;
      attach(geospiza)&lt;br /&gt;
      geospiza.tree$tip.label&lt;br /&gt;
&lt;br /&gt;
The data command loads the data set, and the attach command allows us to access objects within the data set, such as the tree and the morphological data.  The last command will print out the tip.labels for the taxa in the geospiza.tree, so you should now see a list of 14 taxa.&lt;br /&gt;
&lt;br /&gt;
Now we can assign states for our discrete character to these 14 species with the commands:&lt;br /&gt;
     &lt;br /&gt;
      char1&amp;lt;-c(1,1,1,1,1,0,1,0,0,1,0,1,1,1)&lt;br /&gt;
      names(char1)&amp;lt;-geospiza.tree$tip.label&lt;br /&gt;
      char1&lt;br /&gt;
&lt;br /&gt;
The first line binds the 14 character states into a single vector called x.  Then we assign the names (tip labels) from the tree to these 14 values.  So now when you type the last command, char1, R will show you the content of that object, a vector of the values with the names of species associated with the values.&lt;br /&gt;
&lt;br /&gt;
More commonly you will not be typing the character states into the command line but extracting them from a table.  To do this, the process would be similar.&lt;br /&gt;
&lt;br /&gt;
    MyData=read.table(&amp;quot;MyData.txt&amp;quot;,row.names=1)&lt;br /&gt;
    char1&amp;lt;-MyData[,1]&lt;br /&gt;
    names(char1)&amp;lt;-row.names(MyData)&lt;br /&gt;
&lt;br /&gt;
The first line reads in the table, indicating that the first column contains the row.names (here, your taxa with names matching the tip.labels on your tree).  The next line designates the first column ([,1]) after the row names as character 1.  Then you can associate the taxon names to the character states.&lt;br /&gt;
&lt;br /&gt;
Now you can fit a Jukes-Cantor model to this data and the tree by typing:&lt;br /&gt;
&lt;br /&gt;
     ER&amp;lt;-fitDiscrete(geospiza.tree, char1)&lt;br /&gt;
     ER&lt;br /&gt;
&lt;br /&gt;
Geiger will return to you the log likelihood (lnL) for this model (-9.61) and the estimated transition rate, q (-17.06).&lt;br /&gt;
&lt;br /&gt;
'''Estimating a model with assymetrical transition rates in geiger'''&lt;br /&gt;
&lt;br /&gt;
Now let's apply a model where the forward (0-&amp;gt;1) rate is allowed to differ from the reverse rate (1-&amp;gt;0).  Type:&lt;br /&gt;
&lt;br /&gt;
     ARD&amp;lt;-fitDiscrete(geospiza.tree,char1,model=&amp;quot;ARD&amp;quot;)&lt;br /&gt;
     ARD&lt;br /&gt;
&lt;br /&gt;
ARD stand for all rates different.  Now the function returns a likelihood of -7.97 and an estimated rate matrix:&lt;br /&gt;
&lt;br /&gt;
     $Trait1$q&lt;br /&gt;
                [,1]      [,2]&lt;br /&gt;
     [1,] -17.908356 17.908356&lt;br /&gt;
     [2,]   5.995629 -5.995629&lt;br /&gt;
&lt;br /&gt;
So we see that the estimated q for 0-&amp;gt;1 is 17.9 and for 1-&amp;gt;0 is 6.  &lt;br /&gt;
&lt;br /&gt;
'''Comparing models with the likelihood ratio test'''&lt;br /&gt;
&lt;br /&gt;
We can use a chi-squared test to compare the likelihoods of these two models by typing:&lt;br /&gt;
&lt;br /&gt;
     1-pchisq(2*(ARD$Trait1$lnl-ER$Trait1$lnl),1)&lt;br /&gt;
&lt;br /&gt;
We find that the p-value (with 1 degree of freedom) is 0.07, so the assymetrical model is not significantly better than the symmetrical (Jukes-Cantor) model.&lt;br /&gt;
&lt;br /&gt;
Geiger includes other model options, such as transforming the tree with Pagel's lambda.  &lt;br /&gt;
&lt;br /&gt;
     LAMBDA&amp;lt;-fitDiscrete(geospiza.tree, char1, treeTransform=&amp;quot;lambda&amp;quot;)&lt;br /&gt;
     LAMBDA&lt;br /&gt;
&lt;br /&gt;
Geiger estimates lambda as 1.06x10-6.  We can again use the likelihood ratio test to compare this model with the Jukes-Cantor model.&lt;br /&gt;
&lt;br /&gt;
     1-pchisq(2*(LAMBDA$Trait1$lnl-ER$Trait1$lnl),1)&lt;br /&gt;
&lt;br /&gt;
The p-value is 0.295, so adding lambda to the model does not significantly improve its fit.&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForDiscreteData&amp;diff=592</id>
		<title>HowTo/InferringModelsForDiscreteData</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForDiscreteData&amp;diff=592"/>
		<updated>2008-02-06T19:10:09Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/TransitionProbability moved to HowTo/TransitionProbability&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Modeling Discrete Character Evolution in R'''&lt;br /&gt;
&lt;br /&gt;
The evolution of a discrete character along a branch of a phylogeny can be modeled as a Markovian process, where the probability of moving the current state to a different state is governed by a rate matrix.  We can learn about discrete character evolution by calculating and comparing the likelihoods under models which impose different requirements on this matrix.  For example, we might compare a Jukes-Cantor model (where the probability of going from state 0 to state 1 is equal to the probability of going in the reverse direction) to an asymetrical model where the two rates are allowed to differ.  If we found the latter model was a significantly better fit, we might conclude that the trait in question evolves in a directional fashion.&lt;br /&gt;
&lt;br /&gt;
Estimating transition rates and calculating the likelihood of different models for discrete character evolution can be accomplished with the packages geiger (the fitDiscrete function) and ape (the ace function).&lt;br /&gt;
&lt;br /&gt;
'''Estimating a Jukes-Cantor model with the geiger package''' (load the package before you begin)&lt;br /&gt;
&lt;br /&gt;
We will use the ''Geospiza'' dataset for this example and we assume that you have already loaded your tree into the workspace as a phylo object (see [[R_Hackathon/InputtingTrees|Inputting Trees]]).  &lt;br /&gt;
&lt;br /&gt;
So first let's create a vector with character states for &amp;quot;Geospiza&amp;quot;.   The dataset has 14 species.  We can see a list of the species with the following commands:&lt;br /&gt;
&lt;br /&gt;
      data(geospiza)&lt;br /&gt;
      attach(geospiza)&lt;br /&gt;
      geospiza.tree$tip.label&lt;br /&gt;
&lt;br /&gt;
The data command loads the data set, and the attach command allows us to access objects within the data set, such as the tree and the morphological data.  The last command will print out the tip.labels for the taxa in the geospiza.tree, so you should now see a list of 14 taxa.&lt;br /&gt;
&lt;br /&gt;
Now we can assign states for our discrete character to these 14 species with the commands:&lt;br /&gt;
     &lt;br /&gt;
      char1&amp;lt;-c(1,1,1,1,1,0,1,0,0,1,0,1,1,1)&lt;br /&gt;
      names(char1)&amp;lt;-geospiza.tree$tip.label&lt;br /&gt;
      char1&lt;br /&gt;
&lt;br /&gt;
The first line binds the 14 character states into a single vector called x.  Then we assign the names (tip labels) from the tree to these 14 values.  So now when you type the last command, char1, R will show you the content of that object, a vector of the values with the names of species associated with the values.&lt;br /&gt;
&lt;br /&gt;
More commonly you will not be typing the character states into the command line but extracting them from a table.  To do this, the process would be similar.&lt;br /&gt;
&lt;br /&gt;
    MyData=read.table(&amp;quot;MyData.txt&amp;quot;,row.names=1)&lt;br /&gt;
    char1&amp;lt;-MyData[,1]&lt;br /&gt;
    names(char1)&amp;lt;-row.names(MyData)&lt;br /&gt;
&lt;br /&gt;
The first line reads in the table, indicating that the first column contains the row.names (here, your taxa with names matching the tip.labels on your tree).  The next line designates the first column ([,1]) after the row names as character 1.  Then you can associate the taxon names to the character states.&lt;br /&gt;
&lt;br /&gt;
Now you can fit a Jukes-Cantor model to this data and the tree by typing:&lt;br /&gt;
&lt;br /&gt;
     ER&amp;lt;-fitDiscrete(geospiza.tree, char1)&lt;br /&gt;
     ER&lt;br /&gt;
&lt;br /&gt;
Geiger will return to you the log likelihood (lnL) for this model (-9.61) and the estimated transition rate, q (-17.06).&lt;br /&gt;
&lt;br /&gt;
'''Estimating a model with assymetrical transition rates in geiger'''&lt;br /&gt;
&lt;br /&gt;
Now let's apply a model where the forward (0-&amp;gt;1) rate is allowed to differ from the reverse rate (1-&amp;gt;0).  Type:&lt;br /&gt;
&lt;br /&gt;
     ARD&amp;lt;-fitDiscrete(geospiza.tree,char1,model=&amp;quot;ARD&amp;quot;)&lt;br /&gt;
     ARD&lt;br /&gt;
&lt;br /&gt;
ARD stand for all rates different.  Now the function returns a likelihood of -7.97 and an estimated rate matrix:&lt;br /&gt;
&lt;br /&gt;
     $Trait1$q&lt;br /&gt;
                [,1]      [,2]&lt;br /&gt;
     [1,] -17.908356 17.908356&lt;br /&gt;
     [2,]   5.995629 -5.995629&lt;br /&gt;
&lt;br /&gt;
So we see that the estimated q for 0-&amp;gt;1 is 17.9 and for 1-&amp;gt;0 is 6.  &lt;br /&gt;
&lt;br /&gt;
'''Comparing models with the likelihood ratio test'''&lt;br /&gt;
&lt;br /&gt;
We can use a chi-squared test to compare the likelihoods of these two models by typing:&lt;br /&gt;
&lt;br /&gt;
     1-pchisq(2*(ARD$Trait1$lnl-ER$Trait1$lnl),1)&lt;br /&gt;
&lt;br /&gt;
We find that the p-value (with 1 degree of freedom) is 0.07, so the assymetrical model is not significantly better than the symmetrical (Jukes-Cantor) model.&lt;br /&gt;
&lt;br /&gt;
Geiger includes other model options, such as transforming the tree with Pagel's lambda.  &lt;br /&gt;
&lt;br /&gt;
     LAMBDA&amp;lt;-fitDiscrete(geospiza.tree, char1, treeTransform=&amp;quot;lambda&amp;quot;)&lt;br /&gt;
     LAMBDA&lt;br /&gt;
&lt;br /&gt;
Geiger estimates lambda as 1.06x10-6.  We can again use the likelihood ratio test to compare this model with the Jukes-Cantor model.&lt;br /&gt;
&lt;br /&gt;
     1-pchisq(2*(LAMBDA$Trait1$lnl-ER$Trait1$lnl),1)&lt;br /&gt;
&lt;br /&gt;
The p-value is 0.295, so adding lambda to the model does not significantly improve its fit.&lt;br /&gt;
&lt;br /&gt;
[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForDiscreteData&amp;diff=591</id>
		<title>HowTo/InferringModelsForDiscreteData</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/InferringModelsForDiscreteData&amp;diff=591"/>
		<updated>2008-02-06T19:10:00Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Modeling Discrete Character Evolution in R'''&lt;br /&gt;
&lt;br /&gt;
The evolution of a discrete character along a branch of a phylogeny can be modeled as a Markovian process, where the probability of moving the current state to a different state is governed by a rate matrix.  We can learn about discrete character evolution by calculating and comparing the likelihoods under models which impose different requirements on this matrix.  For example, we might compare a Jukes-Cantor model (where the probability of going from state 0 to state 1 is equal to the probability of going in the reverse direction) to an asymetrical model where the two rates are allowed to differ.  If we found the latter model was a significantly better fit, we might conclude that the trait in question evolves in a directional fashion.&lt;br /&gt;
&lt;br /&gt;
Estimating transition rates and calculating the likelihood of different models for discrete character evolution can be accomplished with the packages geiger (the fitDiscrete function) and ape (the ace function).&lt;br /&gt;
&lt;br /&gt;
'''Estimating a Jukes-Cantor model with the geiger package''' (load the package before you begin)&lt;br /&gt;
&lt;br /&gt;
We will use the ''Geospiza'' dataset for this example and we assume that you have already loaded your tree into the workspace as a phylo object (see [[R_Hackathon/InputtingTrees|Inputting Trees]]).  &lt;br /&gt;
&lt;br /&gt;
So first let's create a vector with character states for &amp;quot;Geospiza&amp;quot;.   The dataset has 14 species.  We can see a list of the species with the following commands:&lt;br /&gt;
&lt;br /&gt;
      data(geospiza)&lt;br /&gt;
      attach(geospiza)&lt;br /&gt;
      geospiza.tree$tip.label&lt;br /&gt;
&lt;br /&gt;
The data command loads the data set, and the attach command allows us to access objects within the data set, such as the tree and the morphological data.  The last command will print out the tip.labels for the taxa in the geospiza.tree, so you should now see a list of 14 taxa.&lt;br /&gt;
&lt;br /&gt;
Now we can assign states for our discrete character to these 14 species with the commands:&lt;br /&gt;
     &lt;br /&gt;
      char1&amp;lt;-c(1,1,1,1,1,0,1,0,0,1,0,1,1,1)&lt;br /&gt;
      names(char1)&amp;lt;-geospiza.tree$tip.label&lt;br /&gt;
      char1&lt;br /&gt;
&lt;br /&gt;
The first line binds the 14 character states into a single vector called x.  Then we assign the names (tip labels) from the tree to these 14 values.  So now when you type the last command, char1, R will show you the content of that object, a vector of the values with the names of species associated with the values.&lt;br /&gt;
&lt;br /&gt;
More commonly you will not be typing the character states into the command line but extracting them from a table.  To do this, the process would be similar.&lt;br /&gt;
&lt;br /&gt;
    MyData=read.table(&amp;quot;MyData.txt&amp;quot;,row.names=1)&lt;br /&gt;
    char1&amp;lt;-MyData[,1]&lt;br /&gt;
    names(char1)&amp;lt;-row.names(MyData)&lt;br /&gt;
&lt;br /&gt;
The first line reads in the table, indicating that the first column contains the row.names (here, your taxa with names matching the tip.labels on your tree).  The next line designates the first column ([,1]) after the row names as character 1.  Then you can associate the taxon names to the character states.&lt;br /&gt;
&lt;br /&gt;
Now you can fit a Jukes-Cantor model to this data and the tree by typing:&lt;br /&gt;
&lt;br /&gt;
     ER&amp;lt;-fitDiscrete(geospiza.tree, char1)&lt;br /&gt;
     ER&lt;br /&gt;
&lt;br /&gt;
Geiger will return to you the log likelihood (lnL) for this model (-9.61) and the estimated transition rate, q (-17.06).&lt;br /&gt;
&lt;br /&gt;
'''Estimating a model with assymetrical transition rates in geiger'''&lt;br /&gt;
&lt;br /&gt;
Now let's apply a model where the forward (0-&amp;gt;1) rate is allowed to differ from the reverse rate (1-&amp;gt;0).  Type:&lt;br /&gt;
&lt;br /&gt;
     ARD&amp;lt;-fitDiscrete(geospiza.tree,char1,model=&amp;quot;ARD&amp;quot;)&lt;br /&gt;
     ARD&lt;br /&gt;
&lt;br /&gt;
ARD stand for all rates different.  Now the function returns a likelihood of -7.97 and an estimated rate matrix:&lt;br /&gt;
&lt;br /&gt;
     $Trait1$q&lt;br /&gt;
                [,1]      [,2]&lt;br /&gt;
     [1,] -17.908356 17.908356&lt;br /&gt;
     [2,]   5.995629 -5.995629&lt;br /&gt;
&lt;br /&gt;
So we see that the estimated q for 0-&amp;gt;1 is 17.9 and for 1-&amp;gt;0 is 6.  &lt;br /&gt;
&lt;br /&gt;
'''Comparing models with the likelihood ratio test'''&lt;br /&gt;
&lt;br /&gt;
We can use a chi-squared test to compare the likelihoods of these two models by typing:&lt;br /&gt;
&lt;br /&gt;
     1-pchisq(2*(ARD$Trait1$lnl-ER$Trait1$lnl),1)&lt;br /&gt;
&lt;br /&gt;
We find that the p-value (with 1 degree of freedom) is 0.07, so the assymetrical model is not significantly better than the symmetrical (Jukes-Cantor) model.&lt;br /&gt;
&lt;br /&gt;
Geiger includes other model options, such as transforming the tree with Pagel's lambda.  &lt;br /&gt;
&lt;br /&gt;
     LAMBDA&amp;lt;-fitDiscrete(geospiza.tree, char1, treeTransform=&amp;quot;lambda&amp;quot;)&lt;br /&gt;
     LAMBDA&lt;br /&gt;
&lt;br /&gt;
Geiger estimates lambda as 1.06x10-6.  We can again use the likelihood ratio test to compare this model with the Jukes-Cantor model.&lt;br /&gt;
&lt;br /&gt;
     1-pchisq(2*(LAMBDA$Trait1$lnl-ER$Trait1$lnl),1)&lt;br /&gt;
&lt;br /&gt;
The p-value is 0.295, so adding lambda to the model does not significantly improve its fit.&lt;br /&gt;
&lt;br /&gt;
[Category:HowTo]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/DataTreeManipulation&amp;diff=247</id>
		<title>HowTo/DataTreeManipulation</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/DataTreeManipulation&amp;diff=247"/>
		<updated>2008-02-06T19:08:38Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: R Hackathon/DataTreeManipulation moved to HowTo/DataTreeManipulation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The commands referenced below are all part of special phylogenetic packages in R, not the basic R install. Be sure that you have [[R_Hackathon 1/GettingStarted|installed and loaded the packages]] ape and geiger, which contain the commands referenced below before continuing. For example:&lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
   library(geiger)&lt;br /&gt;
&lt;br /&gt;
This loads the packages ape and geiger and their required packages, gee, nlme, lattice  MASS, mvtnorm, msm and ouch into your R session. &lt;br /&gt;
&lt;br /&gt;
To execute some of the worked examples below yourself, save the sample Geospiza phylogeny and dataset ([[Media:geospiza.rda|geospiza.rda]]) to your working directory and load them into memory using these commands&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
   geodata &amp;lt;- read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== How do I designate a specific taxon to be the root of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The general syntax is&lt;br /&gt;
 &lt;br /&gt;
   rootedphylogeny &amp;lt;- root(phylogeny, outgroup)&lt;br /&gt;
&lt;br /&gt;
The Geospiza tree is already rooted at taxon &amp;quot;olivacea&amp;quot;. This command will reroot the tree at taxon &amp;quot;fusca&amp;quot; and save the rerooted tree as a new phylo object &amp;quot;rerootedgeotree&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   rerootedgeotree &amp;lt;- root(geotree, &amp;quot;fusca&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
You can also just modify the existing phylo object.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- root(geotree, &amp;quot;fusca&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note that rerooting produces a basal trichotomy . . . essentially this command roots the tree at the node subtending taxon fusca, not the taxon itself.&lt;br /&gt;
&lt;br /&gt;
The root command will also root the tree at a group of taxa so long as that group is monophyletic.  Otherwise, an error is returned. &lt;br /&gt;
&lt;br /&gt;
== How can I resolve polytomies in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
The multi2di command will break polytomies in random order. &lt;br /&gt;
&lt;br /&gt;
   dichotomousphylogeny &amp;lt;- multi2di(phylogeny, random = TRUE)&lt;br /&gt;
&lt;br /&gt;
If you want to collapse these zero length branches into 'true multichotomies' ou can also choose to break polytomies in the order that taxa appear in the list of tip names.&lt;br /&gt;
&lt;br /&gt;
   dichotomousphylogeny &amp;lt;- multi2di(phylogeny, random = FALSE)&lt;br /&gt;
&lt;br /&gt;
NOTE: that if you have zero length branches in your tree, ape will recognize the tree as binary if you type:&lt;br /&gt;
&lt;br /&gt;
   is.tree.binary(phylogeny)&lt;br /&gt;
&lt;br /&gt;
If you want your zero length branches into a 'true multichotomy' follow the info in the section below.&lt;br /&gt;
&lt;br /&gt;
== How can I collapse very short branches into polytomies? ==&lt;br /&gt;
&lt;br /&gt;
Use the di2multi command. The basic syntax is&lt;br /&gt;
&lt;br /&gt;
   collapsedphylogeny &amp;lt;- di2multi(phylogeny, tolerancevalue)&lt;br /&gt;
&lt;br /&gt;
Branches shorter than the tolerance value will be collapsed into polytomies.  If unspecified, the tolerance value defaults to 10E-8.  For example:&lt;br /&gt;
&lt;br /&gt;
   collapsedgeotree &amp;lt;- di2multi(geotree, 0.03)&lt;br /&gt;
&lt;br /&gt;
This should produce two polytomies in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
== How can I see the length of the branches in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
The vector of branch lengths for a phylo object (say, the object &amp;quot;phylogeny&amp;quot;) is contained in phylogeny$edge.length.  For the Geospiza dataset, you can view this vector by typing:&lt;br /&gt;
&lt;br /&gt;
   geotree$edge.length&lt;br /&gt;
&lt;br /&gt;
== How can I change the lengths of the branches in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the compute.brlen function. This is the basic syntax &lt;br /&gt;
&lt;br /&gt;
   phylogeny &amp;lt;- compute.brlen(phylogeny, method, power)&lt;br /&gt;
&lt;br /&gt;
Method can equal Grafen (the default), a vector, or a user defined function (for example, a function that generates random branch lengths). If a vector shorter than the number of branches is given as the value of the argument method, that vector is iterated over the branches in sequence. If power is provided, it exponentiates the branch lengths by the specified power.  &lt;br /&gt;
&lt;br /&gt;
The following syntax will ultrametricize the Geospiza phylogeny using Grafen's method (ADD CITATION FOR GRAFEN)&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, method=&amp;quot;Grafen&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
While this syntax will set all branch lengths equal to one&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, 1)&lt;br /&gt;
&lt;br /&gt;
And this will alternate branch lengths of one and two throughout the phylogeny (if, for some reason, you wanted to do that . . . ).&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, c(1, 2))&lt;br /&gt;
&lt;br /&gt;
== How can I see the list of taxa represented in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
These are stored in phylogeny$tip.label. For example, typing&lt;br /&gt;
&lt;br /&gt;
   geotree$tip.label&lt;br /&gt;
&lt;br /&gt;
will show you a list of all the taxa in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How can I verify that the taxa listed in my data table match those at the tips of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Geiger contains the useful function name.check that does exactly that. First, make sure that you have geiger loaded.&lt;br /&gt;
&lt;br /&gt;
   library(geiger)&lt;br /&gt;
&lt;br /&gt;
The basic syntax for name.check is&lt;br /&gt;
&lt;br /&gt;
   name.check(phylogeny, data)&lt;br /&gt;
&lt;br /&gt;
So for the Geospiza dataset, we'd type&lt;br /&gt;
&lt;br /&gt;
   name.check(geotree, geodata)&lt;br /&gt;
&lt;br /&gt;
This will return the following data&lt;br /&gt;
&lt;br /&gt;
   $Tree.not.data&lt;br /&gt;
   [1] &amp;quot;olivacea&amp;quot;&lt;br /&gt;
&lt;br /&gt;
   $Data.not.tree&lt;br /&gt;
   character(0)&lt;br /&gt;
&lt;br /&gt;
Which tells us that the taxon &amp;quot;olivacea&amp;quot; is missing from the character dataset.  We can drop olivacea from the phylogeny like this.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- drop.tip(geotree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Running name.check now should produce the output &amp;quot;OK&amp;quot;, indicating that the taxa in the tree and character dataset match.&lt;br /&gt;
&lt;br /&gt;
== Is there a shorthand way to refer to a specific list of taxa (for example, all members of a particular clade)? == &lt;br /&gt;
&lt;br /&gt;
One approach is to concatenate all the taxon names into a named vector, which can then be used as an input argument in other functions. For example, using the Geospiza dataset.&lt;br /&gt;
&lt;br /&gt;
   cladeA = c(&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;, &amp;quot;parvulus&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note that you need to enclose the taxon names in quotes, otherwise R will look for objects in memory named pauper, psittacula and parvulus.&lt;br /&gt;
&lt;br /&gt;
The package geiger offers the function node.leaves, which facilitates subclade designation if you know the basal node of a clade. The basic syntax is:&lt;br /&gt;
&lt;br /&gt;
   node.leaves(phylogeny, node)&lt;br /&gt;
&lt;br /&gt;
so, we could also designate cladeA above by typing&lt;br /&gt;
&lt;br /&gt;
   cladeA &amp;lt;- node.leaves(geotree, 26)&lt;br /&gt;
&lt;br /&gt;
because node 26 subtends the clade composed of those three species. One can determine the number of the desired node with the mrca command, which yields the node number of the most recent common ancestor of a pair of taxa.&lt;br /&gt;
&lt;br /&gt;
   mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
You can do the whole thing in one step like this:&lt;br /&gt;
&lt;br /&gt;
   cladeA &amp;lt;- node.leaves(geotree, mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE:  node.leaves will be public in the release of the new version of geiger&lt;br /&gt;
&lt;br /&gt;
== How can I remove taxa from my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the drop.tip command.  The basic syntax is:&lt;br /&gt;
&lt;br /&gt;
   drop.tip(phylogeny, tip)&lt;br /&gt;
&lt;br /&gt;
Where tip is a single taxon or a vector of taxon name.&lt;br /&gt;
&lt;br /&gt;
The example below will remove taxa &amp;quot;pauper&amp;quot;, &amp;quot;psitticula&amp;quot; and &amp;quot;parvulus&amp;quot; (previously designated as &amp;quot;CladeA&amp;quot;) from the Geospiza phylogeny and save the resulting phylogeny in &amp;quot;culledtree&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   culledtree &amp;lt;- drop.tip(geotree, cladeA)&lt;br /&gt;
&lt;br /&gt;
== How can I see a plot of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
A quick plot for the Geospiza tree is generated by&lt;br /&gt;
&lt;br /&gt;
   plot.phylo(geotree)&lt;br /&gt;
&lt;br /&gt;
Plot.phylo is actually a very powerful command with many options, for example, it can label internal nodes, modify line widths, modify the plot style (cladogram, fan, radial), etc.  A full list of the switches and syntax can be obtained by typing:&lt;br /&gt;
&lt;br /&gt;
   help(plot.phylo)&lt;br /&gt;
&lt;br /&gt;
== How can I identify all the branches belonging to a particular subclade? ==&lt;br /&gt;
&lt;br /&gt;
The general syntax is: &lt;br /&gt;
&lt;br /&gt;
   branchlist &amp;lt;- which.edge(phylogeny, group)&lt;br /&gt;
&lt;br /&gt;
In the case of the Geospiza example, the branches that unite the species &amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;, and &amp;quot;parvulus&amp;quot; (CladeA defined above) are given by:&lt;br /&gt;
&lt;br /&gt;
   branchlist &amp;lt;- which.edge(geotree, cladeA)&lt;br /&gt;
&lt;br /&gt;
This returns a list of integers, which identify the rows in the edge matrix of the Geospiza phylogeny that belong to the specified clade, which we stored as &amp;quot;geotree&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
You can see what the edge matrix looks like by typing:&lt;br /&gt;
&lt;br /&gt;
   geotree$edge&lt;br /&gt;
&lt;br /&gt;
By doing so, we can see that the edge matrix is an N by 2 list of the N branches in the phylogeny. Each node in the phylogeny is assigned a number, with each branch being defined by the numbers of the nodes bracketing it. &lt;br /&gt;
&lt;br /&gt;
You can extract just the portion of the edge matrix containing the branches in cladeA like this:&lt;br /&gt;
&lt;br /&gt;
   Abranches&amp;lt;-geotree$edge[branchlist, ]&lt;br /&gt;
&lt;br /&gt;
Remember that &amp;quot;branchlist&amp;quot; in this worked example is a vector of integers returned by which.edge.&lt;br /&gt;
&lt;br /&gt;
== How can I identify the node representing the most recent common ancestor of a pair of taxa? ==&lt;br /&gt;
&lt;br /&gt;
Use the mrca command. The basic syntax is&lt;br /&gt;
&lt;br /&gt;
   mrca(phylogeny)[&amp;quot;taxon1&amp;quot;, &amp;quot;taxon2&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
In the Geospiza example, this will return the number of the node in geotree that represents the most recent common ancestor of taxa &amp;quot;pauper&amp;quot; and &amp;quot;parvulus&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;parvulus&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
You should get the answer &amp;quot;26&amp;quot;. You can verify this by first setting the labels for all the nodes to integers representing the order in which they appear in the phylogeny, and then replotting the tree with the switch show.node.label=TRUE&lt;br /&gt;
&lt;br /&gt;
   geotree$node.label&amp;lt;-((length(geotree$tip)+1):((length(geotree$tip)*2)-1))&lt;br /&gt;
   plot(geotree, show.tip.label=TRUE, show.node.label=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the patristic distance between two taxa? ==&lt;br /&gt;
&lt;br /&gt;
Use the cophenetic command.  For example:&lt;br /&gt;
&lt;br /&gt;
   cophenetic(geotree)[&amp;quot;pallida&amp;quot;, &amp;quot;conirostris&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
will calculate the patristic distance between the taxa &amp;quot;pallida&amp;quot; and &amp;quot;conirostris&amp;quot; in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
   cophenetic(geotree)&lt;br /&gt;
&lt;br /&gt;
yields a matrix of all distances between taxa.&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the patristic distance between two internal nodes or an internal node and a tip? ==&lt;br /&gt;
&lt;br /&gt;
Use the dist.nodes command. For example:&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)&lt;br /&gt;
&lt;br /&gt;
yields a matrix of all distances between all nodes (internal and external), and&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)[15, 20]&lt;br /&gt;
&lt;br /&gt;
gives the distance between internal node 15 and internal node 20. &lt;br /&gt;
&lt;br /&gt;
If you want the distance between a node and a tip, you need to know the number of the tip in question. You can see the numbering of the tips by typing.&lt;br /&gt;
&lt;br /&gt;
   geotree$tip&lt;br /&gt;
&lt;br /&gt;
For example, taxon &amp;quot;fulginosa&amp;quot; is tip 1 in the Geospiza dataset, so&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)[1, 15]&lt;br /&gt;
&lt;br /&gt;
yields the distance between &amp;quot;fulginosa&amp;quot; and the internal node labeled 15.&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the distance from an internal node to the tips of an ultrametric phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the branching.times command.&lt;br /&gt;
&lt;br /&gt;
   branching.times(geotree)&lt;br /&gt;
&lt;br /&gt;
This returns a numeric vector of the branching times (distances from the nodes to the tips) for all nodes. The names of the vector are drawn from phylogeny$node.label if node labels have been specified, otherwise they are numbered in the order in which they appear in the edge matrix of the phylogeny.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Credit: Most of the information on this page is paraphrased from the book Analysis of Phylogenetics and Evolution with R (Paradis, 2006).&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:R Help]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/DataTreeManipulation&amp;diff=246</id>
		<title>HowTo/DataTreeManipulation</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/DataTreeManipulation&amp;diff=246"/>
		<updated>2008-02-06T19:08:26Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The commands referenced below are all part of special phylogenetic packages in R, not the basic R install. Be sure that you have [[R_Hackathon 1/GettingStarted|installed and loaded the packages]] ape and geiger, which contain the commands referenced below before continuing. For example:&lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
   library(geiger)&lt;br /&gt;
&lt;br /&gt;
This loads the packages ape and geiger and their required packages, gee, nlme, lattice  MASS, mvtnorm, msm and ouch into your R session. &lt;br /&gt;
&lt;br /&gt;
To execute some of the worked examples below yourself, save the sample Geospiza phylogeny and dataset ([[Media:geospiza.rda|geospiza.rda]]) to your working directory and load them into memory using these commands&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
   geodata &amp;lt;- read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== How do I designate a specific taxon to be the root of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The general syntax is&lt;br /&gt;
 &lt;br /&gt;
   rootedphylogeny &amp;lt;- root(phylogeny, outgroup)&lt;br /&gt;
&lt;br /&gt;
The Geospiza tree is already rooted at taxon &amp;quot;olivacea&amp;quot;. This command will reroot the tree at taxon &amp;quot;fusca&amp;quot; and save the rerooted tree as a new phylo object &amp;quot;rerootedgeotree&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   rerootedgeotree &amp;lt;- root(geotree, &amp;quot;fusca&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
You can also just modify the existing phylo object.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- root(geotree, &amp;quot;fusca&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note that rerooting produces a basal trichotomy . . . essentially this command roots the tree at the node subtending taxon fusca, not the taxon itself.&lt;br /&gt;
&lt;br /&gt;
The root command will also root the tree at a group of taxa so long as that group is monophyletic.  Otherwise, an error is returned. &lt;br /&gt;
&lt;br /&gt;
== How can I resolve polytomies in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
The multi2di command will break polytomies in random order. &lt;br /&gt;
&lt;br /&gt;
   dichotomousphylogeny &amp;lt;- multi2di(phylogeny, random = TRUE)&lt;br /&gt;
&lt;br /&gt;
If you want to collapse these zero length branches into 'true multichotomies' ou can also choose to break polytomies in the order that taxa appear in the list of tip names.&lt;br /&gt;
&lt;br /&gt;
   dichotomousphylogeny &amp;lt;- multi2di(phylogeny, random = FALSE)&lt;br /&gt;
&lt;br /&gt;
NOTE: that if you have zero length branches in your tree, ape will recognize the tree as binary if you type:&lt;br /&gt;
&lt;br /&gt;
   is.tree.binary(phylogeny)&lt;br /&gt;
&lt;br /&gt;
If you want your zero length branches into a 'true multichotomy' follow the info in the section below.&lt;br /&gt;
&lt;br /&gt;
== How can I collapse very short branches into polytomies? ==&lt;br /&gt;
&lt;br /&gt;
Use the di2multi command. The basic syntax is&lt;br /&gt;
&lt;br /&gt;
   collapsedphylogeny &amp;lt;- di2multi(phylogeny, tolerancevalue)&lt;br /&gt;
&lt;br /&gt;
Branches shorter than the tolerance value will be collapsed into polytomies.  If unspecified, the tolerance value defaults to 10E-8.  For example:&lt;br /&gt;
&lt;br /&gt;
   collapsedgeotree &amp;lt;- di2multi(geotree, 0.03)&lt;br /&gt;
&lt;br /&gt;
This should produce two polytomies in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
== How can I see the length of the branches in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
The vector of branch lengths for a phylo object (say, the object &amp;quot;phylogeny&amp;quot;) is contained in phylogeny$edge.length.  For the Geospiza dataset, you can view this vector by typing:&lt;br /&gt;
&lt;br /&gt;
   geotree$edge.length&lt;br /&gt;
&lt;br /&gt;
== How can I change the lengths of the branches in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the compute.brlen function. This is the basic syntax &lt;br /&gt;
&lt;br /&gt;
   phylogeny &amp;lt;- compute.brlen(phylogeny, method, power)&lt;br /&gt;
&lt;br /&gt;
Method can equal Grafen (the default), a vector, or a user defined function (for example, a function that generates random branch lengths). If a vector shorter than the number of branches is given as the value of the argument method, that vector is iterated over the branches in sequence. If power is provided, it exponentiates the branch lengths by the specified power.  &lt;br /&gt;
&lt;br /&gt;
The following syntax will ultrametricize the Geospiza phylogeny using Grafen's method (ADD CITATION FOR GRAFEN)&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, method=&amp;quot;Grafen&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
While this syntax will set all branch lengths equal to one&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, 1)&lt;br /&gt;
&lt;br /&gt;
And this will alternate branch lengths of one and two throughout the phylogeny (if, for some reason, you wanted to do that . . . ).&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, c(1, 2))&lt;br /&gt;
&lt;br /&gt;
== How can I see the list of taxa represented in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
These are stored in phylogeny$tip.label. For example, typing&lt;br /&gt;
&lt;br /&gt;
   geotree$tip.label&lt;br /&gt;
&lt;br /&gt;
will show you a list of all the taxa in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How can I verify that the taxa listed in my data table match those at the tips of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Geiger contains the useful function name.check that does exactly that. First, make sure that you have geiger loaded.&lt;br /&gt;
&lt;br /&gt;
   library(geiger)&lt;br /&gt;
&lt;br /&gt;
The basic syntax for name.check is&lt;br /&gt;
&lt;br /&gt;
   name.check(phylogeny, data)&lt;br /&gt;
&lt;br /&gt;
So for the Geospiza dataset, we'd type&lt;br /&gt;
&lt;br /&gt;
   name.check(geotree, geodata)&lt;br /&gt;
&lt;br /&gt;
This will return the following data&lt;br /&gt;
&lt;br /&gt;
   $Tree.not.data&lt;br /&gt;
   [1] &amp;quot;olivacea&amp;quot;&lt;br /&gt;
&lt;br /&gt;
   $Data.not.tree&lt;br /&gt;
   character(0)&lt;br /&gt;
&lt;br /&gt;
Which tells us that the taxon &amp;quot;olivacea&amp;quot; is missing from the character dataset.  We can drop olivacea from the phylogeny like this.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- drop.tip(geotree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Running name.check now should produce the output &amp;quot;OK&amp;quot;, indicating that the taxa in the tree and character dataset match.&lt;br /&gt;
&lt;br /&gt;
== Is there a shorthand way to refer to a specific list of taxa (for example, all members of a particular clade)? == &lt;br /&gt;
&lt;br /&gt;
One approach is to concatenate all the taxon names into a named vector, which can then be used as an input argument in other functions. For example, using the Geospiza dataset.&lt;br /&gt;
&lt;br /&gt;
   cladeA = c(&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;, &amp;quot;parvulus&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note that you need to enclose the taxon names in quotes, otherwise R will look for objects in memory named pauper, psittacula and parvulus.&lt;br /&gt;
&lt;br /&gt;
The package geiger offers the function node.leaves, which facilitates subclade designation if you know the basal node of a clade. The basic syntax is:&lt;br /&gt;
&lt;br /&gt;
   node.leaves(phylogeny, node)&lt;br /&gt;
&lt;br /&gt;
so, we could also designate cladeA above by typing&lt;br /&gt;
&lt;br /&gt;
   cladeA &amp;lt;- node.leaves(geotree, 26)&lt;br /&gt;
&lt;br /&gt;
because node 26 subtends the clade composed of those three species. One can determine the number of the desired node with the mrca command, which yields the node number of the most recent common ancestor of a pair of taxa.&lt;br /&gt;
&lt;br /&gt;
   mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
You can do the whole thing in one step like this:&lt;br /&gt;
&lt;br /&gt;
   cladeA &amp;lt;- node.leaves(geotree, mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE:  node.leaves will be public in the release of the new version of geiger&lt;br /&gt;
&lt;br /&gt;
== How can I remove taxa from my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the drop.tip command.  The basic syntax is:&lt;br /&gt;
&lt;br /&gt;
   drop.tip(phylogeny, tip)&lt;br /&gt;
&lt;br /&gt;
Where tip is a single taxon or a vector of taxon name.&lt;br /&gt;
&lt;br /&gt;
The example below will remove taxa &amp;quot;pauper&amp;quot;, &amp;quot;psitticula&amp;quot; and &amp;quot;parvulus&amp;quot; (previously designated as &amp;quot;CladeA&amp;quot;) from the Geospiza phylogeny and save the resulting phylogeny in &amp;quot;culledtree&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   culledtree &amp;lt;- drop.tip(geotree, cladeA)&lt;br /&gt;
&lt;br /&gt;
== How can I see a plot of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
A quick plot for the Geospiza tree is generated by&lt;br /&gt;
&lt;br /&gt;
   plot.phylo(geotree)&lt;br /&gt;
&lt;br /&gt;
Plot.phylo is actually a very powerful command with many options, for example, it can label internal nodes, modify line widths, modify the plot style (cladogram, fan, radial), etc.  A full list of the switches and syntax can be obtained by typing:&lt;br /&gt;
&lt;br /&gt;
   help(plot.phylo)&lt;br /&gt;
&lt;br /&gt;
== How can I identify all the branches belonging to a particular subclade? ==&lt;br /&gt;
&lt;br /&gt;
The general syntax is: &lt;br /&gt;
&lt;br /&gt;
   branchlist &amp;lt;- which.edge(phylogeny, group)&lt;br /&gt;
&lt;br /&gt;
In the case of the Geospiza example, the branches that unite the species &amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;, and &amp;quot;parvulus&amp;quot; (CladeA defined above) are given by:&lt;br /&gt;
&lt;br /&gt;
   branchlist &amp;lt;- which.edge(geotree, cladeA)&lt;br /&gt;
&lt;br /&gt;
This returns a list of integers, which identify the rows in the edge matrix of the Geospiza phylogeny that belong to the specified clade, which we stored as &amp;quot;geotree&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
You can see what the edge matrix looks like by typing:&lt;br /&gt;
&lt;br /&gt;
   geotree$edge&lt;br /&gt;
&lt;br /&gt;
By doing so, we can see that the edge matrix is an N by 2 list of the N branches in the phylogeny. Each node in the phylogeny is assigned a number, with each branch being defined by the numbers of the nodes bracketing it. &lt;br /&gt;
&lt;br /&gt;
You can extract just the portion of the edge matrix containing the branches in cladeA like this:&lt;br /&gt;
&lt;br /&gt;
   Abranches&amp;lt;-geotree$edge[branchlist, ]&lt;br /&gt;
&lt;br /&gt;
Remember that &amp;quot;branchlist&amp;quot; in this worked example is a vector of integers returned by which.edge.&lt;br /&gt;
&lt;br /&gt;
== How can I identify the node representing the most recent common ancestor of a pair of taxa? ==&lt;br /&gt;
&lt;br /&gt;
Use the mrca command. The basic syntax is&lt;br /&gt;
&lt;br /&gt;
   mrca(phylogeny)[&amp;quot;taxon1&amp;quot;, &amp;quot;taxon2&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
In the Geospiza example, this will return the number of the node in geotree that represents the most recent common ancestor of taxa &amp;quot;pauper&amp;quot; and &amp;quot;parvulus&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;parvulus&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
You should get the answer &amp;quot;26&amp;quot;. You can verify this by first setting the labels for all the nodes to integers representing the order in which they appear in the phylogeny, and then replotting the tree with the switch show.node.label=TRUE&lt;br /&gt;
&lt;br /&gt;
   geotree$node.label&amp;lt;-((length(geotree$tip)+1):((length(geotree$tip)*2)-1))&lt;br /&gt;
   plot(geotree, show.tip.label=TRUE, show.node.label=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the patristic distance between two taxa? ==&lt;br /&gt;
&lt;br /&gt;
Use the cophenetic command.  For example:&lt;br /&gt;
&lt;br /&gt;
   cophenetic(geotree)[&amp;quot;pallida&amp;quot;, &amp;quot;conirostris&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
will calculate the patristic distance between the taxa &amp;quot;pallida&amp;quot; and &amp;quot;conirostris&amp;quot; in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
   cophenetic(geotree)&lt;br /&gt;
&lt;br /&gt;
yields a matrix of all distances between taxa.&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the patristic distance between two internal nodes or an internal node and a tip? ==&lt;br /&gt;
&lt;br /&gt;
Use the dist.nodes command. For example:&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)&lt;br /&gt;
&lt;br /&gt;
yields a matrix of all distances between all nodes (internal and external), and&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)[15, 20]&lt;br /&gt;
&lt;br /&gt;
gives the distance between internal node 15 and internal node 20. &lt;br /&gt;
&lt;br /&gt;
If you want the distance between a node and a tip, you need to know the number of the tip in question. You can see the numbering of the tips by typing.&lt;br /&gt;
&lt;br /&gt;
   geotree$tip&lt;br /&gt;
&lt;br /&gt;
For example, taxon &amp;quot;fulginosa&amp;quot; is tip 1 in the Geospiza dataset, so&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)[1, 15]&lt;br /&gt;
&lt;br /&gt;
yields the distance between &amp;quot;fulginosa&amp;quot; and the internal node labeled 15.&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the distance from an internal node to the tips of an ultrametric phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the branching.times command.&lt;br /&gt;
&lt;br /&gt;
   branching.times(geotree)&lt;br /&gt;
&lt;br /&gt;
This returns a numeric vector of the branching times (distances from the nodes to the tips) for all nodes. The names of the vector are drawn from phylogeny$node.label if node labels have been specified, otherwise they are numbered in the order in which they appear in the edge matrix of the phylogeny.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Credit: Most of the information on this page is paraphrased from the book Analysis of Phylogenetics and Evolution with R (Paradis, 2006).&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:R Help]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/DataTreeManipulation&amp;diff=245</id>
		<title>HowTo/DataTreeManipulation</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/DataTreeManipulation&amp;diff=245"/>
		<updated>2008-02-06T19:06:29Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The commands referenced below are all part of special phylogenetic packages in R, not the basic R install. Be sure that you have [[R_Hackathon 1/GettingStarted|installed and loaded the packages]] ape and geiger, which contain the commands referenced below before continuing. For example:&lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
   library(geiger)&lt;br /&gt;
&lt;br /&gt;
This loads the packages ape and geiger and their required packages, gee, nlme, lattice  MASS, mvtnorm, msm and ouch into your R session. &lt;br /&gt;
&lt;br /&gt;
To execute some of the worked examples below yourself, save the sample Geospiza phylogeny and dataset (ADD HYPERLINKS HERE) to your working directory and load them into memory using these commands&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- read.nexus(&amp;quot;geospiza.nex&amp;quot;)&lt;br /&gt;
   geodata &amp;lt;- read.table(&amp;quot;geospiza.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
== How do I designate a specific taxon to be the root of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The general syntax is&lt;br /&gt;
 &lt;br /&gt;
   rootedphylogeny &amp;lt;- root(phylogeny, outgroup)&lt;br /&gt;
&lt;br /&gt;
The Geospiza tree is already rooted at taxon &amp;quot;olivacea&amp;quot;. This command will reroot the tree at taxon &amp;quot;fusca&amp;quot; and save the rerooted tree as a new phylo object &amp;quot;rerootedgeotree&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   rerootedgeotree &amp;lt;- root(geotree, &amp;quot;fusca&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
You can also just modify the existing phylo object.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- root(geotree, &amp;quot;fusca&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note that rerooting produces a basal trichotomy . . . essentially this command roots the tree at the node subtending taxon fusca, not the taxon itself.&lt;br /&gt;
&lt;br /&gt;
The root command will also root the tree at a group of taxa so long as that group is monophyletic.  Otherwise, an error is returned. &lt;br /&gt;
&lt;br /&gt;
== How can I resolve polytomies in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
The multi2di command will break polytomies in random order. &lt;br /&gt;
&lt;br /&gt;
   dichotomousphylogeny &amp;lt;- multi2di(phylogeny, random = TRUE)&lt;br /&gt;
&lt;br /&gt;
If you want to collapse these zero length branches into 'true multichotomies' ou can also choose to break polytomies in the order that taxa appear in the list of tip names.&lt;br /&gt;
&lt;br /&gt;
   dichotomousphylogeny &amp;lt;- multi2di(phylogeny, random = FALSE)&lt;br /&gt;
&lt;br /&gt;
NOTE: that if you have zero length branches in your tree, ape will recognize the tree as binary if you type:&lt;br /&gt;
&lt;br /&gt;
   is.tree.binary(phylogeny)&lt;br /&gt;
&lt;br /&gt;
If you want your zero length branches into a 'true multichotomy' follow the info in the section below.&lt;br /&gt;
&lt;br /&gt;
== How can I collapse very short branches into polytomies? ==&lt;br /&gt;
&lt;br /&gt;
Use the di2multi command. The basic syntax is&lt;br /&gt;
&lt;br /&gt;
   collapsedphylogeny &amp;lt;- di2multi(phylogeny, tolerancevalue)&lt;br /&gt;
&lt;br /&gt;
Branches shorter than the tolerance value will be collapsed into polytomies.  If unspecified, the tolerance value defaults to 10E-8.  For example:&lt;br /&gt;
&lt;br /&gt;
   collapsedgeotree &amp;lt;- di2multi(geotree, 0.03)&lt;br /&gt;
&lt;br /&gt;
This should produce two polytomies in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
== How can I see the length of the branches in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
The vector of branch lengths for a phylo object (say, the object &amp;quot;phylogeny&amp;quot;) is contained in phylogeny$edge.length.  For the Geospiza dataset, you can view this vector by typing:&lt;br /&gt;
&lt;br /&gt;
   geotree$edge.length&lt;br /&gt;
&lt;br /&gt;
== How can I change the lengths of the branches in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the compute.brlen function. This is the basic syntax &lt;br /&gt;
&lt;br /&gt;
   phylogeny &amp;lt;- compute.brlen(phylogeny, method, power)&lt;br /&gt;
&lt;br /&gt;
Method can equal Grafen (the default), a vector, or a user defined function (for example, a function that generates random branch lengths). If a vector shorter than the number of branches is given as the value of the argument method, that vector is iterated over the branches in sequence. If power is provided, it exponentiates the branch lengths by the specified power.  &lt;br /&gt;
&lt;br /&gt;
The following syntax will ultrametricize the Geospiza phylogeny using Grafen's method (ADD CITATION FOR GRAFEN)&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, method=&amp;quot;Grafen&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
While this syntax will set all branch lengths equal to one&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, 1)&lt;br /&gt;
&lt;br /&gt;
And this will alternate branch lengths of one and two throughout the phylogeny (if, for some reason, you wanted to do that . . . ).&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- compute.brlen(geotree, c(1, 2))&lt;br /&gt;
&lt;br /&gt;
== How can I see the list of taxa represented in my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
These are stored in phylogeny$tip.label. For example, typing&lt;br /&gt;
&lt;br /&gt;
   geotree$tip.label&lt;br /&gt;
&lt;br /&gt;
will show you a list of all the taxa in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How can I verify that the taxa listed in my data table match those at the tips of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Geiger contains the useful function name.check that does exactly that. First, make sure that you have geiger loaded.&lt;br /&gt;
&lt;br /&gt;
   library(geiger)&lt;br /&gt;
&lt;br /&gt;
The basic syntax for name.check is&lt;br /&gt;
&lt;br /&gt;
   name.check(phylogeny, data)&lt;br /&gt;
&lt;br /&gt;
So for the Geospiza dataset, we'd type&lt;br /&gt;
&lt;br /&gt;
   name.check(geotree, geodata)&lt;br /&gt;
&lt;br /&gt;
This will return the following data&lt;br /&gt;
&lt;br /&gt;
   $Tree.not.data&lt;br /&gt;
   [1] &amp;quot;olivacea&amp;quot;&lt;br /&gt;
&lt;br /&gt;
   $Data.not.tree&lt;br /&gt;
   character(0)&lt;br /&gt;
&lt;br /&gt;
Which tells us that the taxon &amp;quot;olivacea&amp;quot; is missing from the character dataset.  We can drop olivacea from the phylogeny like this.&lt;br /&gt;
&lt;br /&gt;
   geotree &amp;lt;- drop.tip(geotree, &amp;quot;olivacea&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Running name.check now should produce the output &amp;quot;OK&amp;quot;, indicating that the taxa in the tree and character dataset match.&lt;br /&gt;
&lt;br /&gt;
== Is there a shorthand way to refer to a specific list of taxa (for example, all members of a particular clade)? == &lt;br /&gt;
&lt;br /&gt;
One approach is to concatenate all the taxon names into a named vector, which can then be used as an input argument in other functions. For example, using the Geospiza dataset.&lt;br /&gt;
&lt;br /&gt;
   cladeA = c(&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;, &amp;quot;parvulus&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Note that you need to enclose the taxon names in quotes, otherwise R will look for objects in memory named pauper, psittacula and parvulus.&lt;br /&gt;
&lt;br /&gt;
The package geiger offers the function node.leaves, which facilitates subclade designation if you know the basal node of a clade. The basic syntax is:&lt;br /&gt;
&lt;br /&gt;
   node.leaves(phylogeny, node)&lt;br /&gt;
&lt;br /&gt;
so, we could also designate cladeA above by typing&lt;br /&gt;
&lt;br /&gt;
   cladeA &amp;lt;- node.leaves(geotree, 26)&lt;br /&gt;
&lt;br /&gt;
because node 26 subtends the clade composed of those three species. One can determine the number of the desired node with the mrca command, which yields the node number of the most recent common ancestor of a pair of taxa.&lt;br /&gt;
&lt;br /&gt;
   mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
You can do the whole thing in one step like this:&lt;br /&gt;
&lt;br /&gt;
   cladeA &amp;lt;- node.leaves(geotree, mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NOTE:  node.leaves will be public in the release of the new version of geiger&lt;br /&gt;
&lt;br /&gt;
== How can I remove taxa from my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the drop.tip command.  The basic syntax is:&lt;br /&gt;
&lt;br /&gt;
   drop.tip(phylogeny, tip)&lt;br /&gt;
&lt;br /&gt;
Where tip is a single taxon or a vector of taxon name.&lt;br /&gt;
&lt;br /&gt;
The example below will remove taxa &amp;quot;pauper&amp;quot;, &amp;quot;psitticula&amp;quot; and &amp;quot;parvulus&amp;quot; (previously designated as &amp;quot;CladeA&amp;quot;) from the Geospiza phylogeny and save the resulting phylogeny in &amp;quot;culledtree&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   culledtree &amp;lt;- drop.tip(geotree, cladeA)&lt;br /&gt;
&lt;br /&gt;
== How can I see a plot of my phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
A quick plot for the Geospiza tree is generated by&lt;br /&gt;
&lt;br /&gt;
   plot.phylo(geotree)&lt;br /&gt;
&lt;br /&gt;
Plot.phylo is actually a very powerful command with many options, for example, it can label internal nodes, modify line widths, modify the plot style (cladogram, fan, radial), etc.  A full list of the switches and syntax can be obtained by typing:&lt;br /&gt;
&lt;br /&gt;
   help(plot.phylo)&lt;br /&gt;
&lt;br /&gt;
== How can I identify all the branches belonging to a particular subclade? ==&lt;br /&gt;
&lt;br /&gt;
The general syntax is: &lt;br /&gt;
&lt;br /&gt;
   branchlist &amp;lt;- which.edge(phylogeny, group)&lt;br /&gt;
&lt;br /&gt;
In the case of the Geospiza example, the branches that unite the species &amp;quot;pauper&amp;quot;, &amp;quot;psittacula&amp;quot;, and &amp;quot;parvulus&amp;quot; (CladeA defined above) are given by:&lt;br /&gt;
&lt;br /&gt;
   branchlist &amp;lt;- which.edge(geotree, cladeA)&lt;br /&gt;
&lt;br /&gt;
This returns a list of integers, which identify the rows in the edge matrix of the Geospiza phylogeny that belong to the specified clade, which we stored as &amp;quot;geotree&amp;quot;.  &lt;br /&gt;
&lt;br /&gt;
You can see what the edge matrix looks like by typing:&lt;br /&gt;
&lt;br /&gt;
   geotree$edge&lt;br /&gt;
&lt;br /&gt;
By doing so, we can see that the edge matrix is an N by 2 list of the N branches in the phylogeny. Each node in the phylogeny is assigned a number, with each branch being defined by the numbers of the nodes bracketing it. &lt;br /&gt;
&lt;br /&gt;
You can extract just the portion of the edge matrix containing the branches in cladeA like this:&lt;br /&gt;
&lt;br /&gt;
   Abranches&amp;lt;-geotree$edge[branchlist, ]&lt;br /&gt;
&lt;br /&gt;
Remember that &amp;quot;branchlist&amp;quot; in this worked example is a vector of integers returned by which.edge.&lt;br /&gt;
&lt;br /&gt;
== How can I identify the node representing the most recent common ancestor of a pair of taxa? ==&lt;br /&gt;
&lt;br /&gt;
Use the mrca command. The basic syntax is&lt;br /&gt;
&lt;br /&gt;
   mrca(phylogeny)[&amp;quot;taxon1&amp;quot;, &amp;quot;taxon2&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
In the Geospiza example, this will return the number of the node in geotree that represents the most recent common ancestor of taxa &amp;quot;pauper&amp;quot; and &amp;quot;parvulus&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   mrca(geotree)[&amp;quot;pauper&amp;quot;, &amp;quot;parvulus&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
You should get the answer &amp;quot;26&amp;quot;. You can verify this by first setting the labels for all the nodes to integers representing the order in which they appear in the phylogeny, and then replotting the tree with the switch show.node.label=TRUE&lt;br /&gt;
&lt;br /&gt;
   geotree$node.label&amp;lt;-((length(geotree$tip)+1):((length(geotree$tip)*2)-1))&lt;br /&gt;
   plot(geotree, show.tip.label=TRUE, show.node.label=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the patristic distance between two taxa? ==&lt;br /&gt;
&lt;br /&gt;
Use the cophenetic command.  For example:&lt;br /&gt;
&lt;br /&gt;
   cophenetic(geotree)[&amp;quot;pallida&amp;quot;, &amp;quot;conirostris&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
will calculate the patristic distance between the taxa &amp;quot;pallida&amp;quot; and &amp;quot;conirostris&amp;quot; in the Geospiza phylogeny.&lt;br /&gt;
&lt;br /&gt;
   cophenetic(geotree)&lt;br /&gt;
&lt;br /&gt;
yields a matrix of all distances between taxa.&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the patristic distance between two internal nodes or an internal node and a tip? ==&lt;br /&gt;
&lt;br /&gt;
Use the dist.nodes command. For example:&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)&lt;br /&gt;
&lt;br /&gt;
yields a matrix of all distances between all nodes (internal and external), and&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)[15, 20]&lt;br /&gt;
&lt;br /&gt;
gives the distance between internal node 15 and internal node 20. &lt;br /&gt;
&lt;br /&gt;
If you want the distance between a node and a tip, you need to know the number of the tip in question. You can see the numbering of the tips by typing.&lt;br /&gt;
&lt;br /&gt;
   geotree$tip&lt;br /&gt;
&lt;br /&gt;
For example, taxon &amp;quot;fulginosa&amp;quot; is tip 1 in the Geospiza dataset, so&lt;br /&gt;
&lt;br /&gt;
   dist.nodes(geotree)[1, 15]&lt;br /&gt;
&lt;br /&gt;
yields the distance between &amp;quot;fulginosa&amp;quot; and the internal node labeled 15.&lt;br /&gt;
&lt;br /&gt;
== How do I calculate the distance from an internal node to the tips of an ultrametric phylogeny? ==&lt;br /&gt;
&lt;br /&gt;
Use the branching.times command.&lt;br /&gt;
&lt;br /&gt;
   branching.times(geotree)&lt;br /&gt;
&lt;br /&gt;
This returns a numeric vector of the branching times (distances from the nodes to the tips) for all nodes. The names of the vector are drawn from phylogeny$node.label if node labels have been specified, otherwise they are numbered in the order in which they appear in the edge matrix of the phylogeny.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Credit: Most of the information on this page is paraphrased from the book Analysis of Phylogenetics and Evolution with R (Paradis, 2006).&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:R Help]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/InputtingData&amp;diff=437</id>
		<title>HowTo/InputtingData</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/InputtingData&amp;diff=437"/>
		<updated>2008-02-06T19:04:42Z</updated>

		<summary type="html">&lt;p&gt;Hilmar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The commands referenced below are all part of special phylogenetic packages in R, not the basic R install. Be sure that you have installed and loaded the packages containing the commands referenced below before continuing. For example:&lt;br /&gt;
&lt;br /&gt;
   library(ape)&lt;br /&gt;
&lt;br /&gt;
This loads the package ape and its required packages gee, nlme and lattice into your R session. &lt;br /&gt;
&lt;br /&gt;
'''How do I input data corresponding to the tips of my phylogeny into R?'''&lt;br /&gt;
&lt;br /&gt;
First, assemble your data into a tab delimited text file (this can be done, for example, in a simple text editor or as a &amp;quot;save as&amp;quot; option in MS Excel).  By default, the rows of the datafile correspond to the taxa at the tips of your phylogeny. The first column should represent the names of your taxa exactly as they appear in your phylogeny (see previous section). The second and any subsequent columns of the datafile should correspond to the variables in your dataset.  The first row of the datafile should contain the names of the variables in your dataset, noting that this row will have one fewer entry than the other rows.  In other words, do not supply a title for the column containing the taxon names.&lt;br /&gt;
&lt;br /&gt;
Once the text file is properly formatted, the read.table command will import it as an object in R. For example, this will create the data table &amp;quot;MyData&amp;quot; from the file &amp;quot;MyDatafile.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
   MyData &amp;lt;- read.table (&amp;quot;MyDatafile.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The procedure above should work on any white-space (space, tab or line-end) delimited text file. There are several other options for inputing data using read.table and its derivatives. For example, read.csv will read a comma-delimited text file.  Use the following command for more information on the nuances of read.table.&lt;br /&gt;
&lt;br /&gt;
   help(read.table)&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;br /&gt;
[[Category:R Help]]&lt;br /&gt;
[[Category:Comparative Methods Help]]&lt;/div&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
</feed>