<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.r-phylo.org/w/index.php?action=history&amp;feed=atom&amp;title=HowTo%2FPGLS</id>
	<title>HowTo/PGLS - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.r-phylo.org/w/index.php?action=history&amp;feed=atom&amp;title=HowTo%2FPGLS"/>
	<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;action=history"/>
	<updated>2026-06-13T05:08:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=493&amp;oldid=prev</id>
		<title>Hilmar: /* Fitting a Brownian Motion model in PGLS */</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=493&amp;oldid=prev"/>
		<updated>2008-02-06T19:21:28Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Fitting a Brownian Motion model in PGLS&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:21, 6 February 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l17&quot;&gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      geospiza.data&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;,row.names=1)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      geospiza.data&amp;lt;-read.table(&amp;quot;geospiza.txt&amp;quot;,row.names=1)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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 [&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https://www.nescent.org/wg_phyloinformatics/&lt;/del&gt;R_Hackathon/Ancestral_State_Reconstruction &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;this page&lt;/del&gt;].  With the dataset in active memory, we can create the dataframe as follows:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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 [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[&lt;/ins&gt;R_Hackathon &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1&lt;/ins&gt;/Ancestral_State_Reconstruction&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|Ancestral State Reconstruction]&lt;/ins&gt;].  With the dataset in active memory, we can create the dataframe as follows:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      wingL&amp;lt;-geospiza.data$wingL&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      wingL&amp;lt;-geospiza.data$wingL&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=492&amp;oldid=prev</id>
		<title>Hilmar at 19:20, 6 February 2008</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=492&amp;oldid=prev"/>
		<updated>2008-02-06T19:20:54Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:20, 6 February 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;'''&lt;/del&gt;Phylogenetic Generalized Least Squares&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;'''&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==&lt;/ins&gt;Phylogenetic Generalized Least Squares&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;'''&lt;/del&gt;Fitting a Brownian Motion model in PGLS&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;'''&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;===&lt;/ins&gt;Fitting a Brownian Motion model in PGLS&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;===&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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) &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;as described on &lt;/del&gt;[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https://www.nescent.org/wg_phyloinformatics/&lt;/del&gt;R_Hackathon/TransitionProbability &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;this page&lt;/del&gt;]. 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;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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) [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[&lt;/ins&gt;R_Hackathon/TransitionProbability&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|as described]&lt;/ins&gt;]. 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;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l32&quot;&gt;Line 32:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 32:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;'''&lt;/del&gt;Fitting an Ornstein-Uhlenbeck Motion model in PGLS&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;'''&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;===&lt;/ins&gt;Fitting an Ornstein-Uhlenbeck Motion model in PGLS&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;===&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l41&quot;&gt;Line 41:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 41:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&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;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:HowTo]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Comparative Methods Help]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Hilmar</name></author>
	</entry>
	<entry>
		<id>https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=491&amp;oldid=prev</id>
		<title>Hilmar: R Hackathon/PGLS moved to HowTo/PGLS</title>
		<link rel="alternate" type="text/html" href="https://www.r-phylo.org/w/index.php?title=HowTo/PGLS&amp;diff=491&amp;oldid=prev"/>
		<updated>2008-02-06T19:18:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;a href=&quot;/w/index.php?title=R_Hackathon/PGLS&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;R Hackathon/PGLS (page does not exist)&quot;&gt;R Hackathon/PGLS&lt;/a&gt; moved to &lt;a href=&quot;/wiki/HowTo/PGLS&quot; title=&quot;HowTo/PGLS&quot;&gt;HowTo/PGLS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&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>
</feed>