<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Interaction between phylogenetic uncertainty and influential clade detection - Phylogenetic Logistic Regression — tree_clade_phyglm • sensiPhy</title>


<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />


<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>

<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/all.min.css" integrity="sha256-nAmazAk6vS34Xqo0BSrTb+abbtFlgsFK7NKSi6o7Y78=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/v4-shims.min.css" integrity="sha256-6qHlizsOWFskGlwVOKuns+D1nB6ssZrHQrNj1wGplHc=" crossorigin="anonymous" />

<!-- clipboard.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script>

<!-- headroom.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/headroom.min.js" integrity="sha256-DJFC1kqIhelURkuza0AvYal5RxMtpzLjFhsnVIeuk+U=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script>

<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>




<meta property="og:title" content="Interaction between phylogenetic uncertainty and influential clade detection - Phylogenetic Logistic Regression — tree_clade_phyglm" />
<meta property="og:description" content="Estimate the impact on model estimates of phylogenetic logistic regression after 
removing clades from the analysis and evaluating uncertainty in trees topology." />
<meta name="twitter:card" content="summary" />




<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>

<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->



  </head>

  <body>
    <div class="container template-reference-topic">
      <header>
      <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">sensiPhy</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.8.5</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="../index.html">
    <span class="fas fa fas fa-home fa-lg"></span>
     
  </a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Articles
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
    <li>
      <a href="../articles/sensiPhy_vignette.html">sensiPhy: R-package for sensitivity analysis in phylogenetic comparative methods.</a>
    </li>
  </ul>
</li>
<li>
  <a href="../news/index.html">Changelog</a>
</li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
  <a href="https://github.com/paternogbc/sensiPhy">
    <span class="fab fa fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
      
    </div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->

      

      </header>

<div class="row">
  <div class="col-md-9 contents">
    <div class="page-header">
    <h1>Interaction between phylogenetic uncertainty and influential clade detection - Phylogenetic Logistic Regression</h1>
    <small class="dont-index">Source: <a href='https://github.com/paternogbc/sensiPhy/blob/master/R/tree_clade_phyglm.R'><code>R/tree_clade_phyglm.R</code></a></small>
    <div class="hidden name"><code>tree_clade_phyglm.Rd</code></div>
    </div>

    <div class="ref-description">
    <p>Estimate the impact on model estimates of phylogenetic logistic regression after 
removing clades from the analysis and evaluating uncertainty in trees topology.</p>
    </div>

    <pre class="usage"><span class='fu'>tree_clade_phyglm</span>(
  <span class='no'>formula</span>,
  <span class='no'>data</span>,
  <span class='no'>phy</span>,
  <span class='no'>clade.col</span>,
  <span class='kw'>n.species</span> <span class='kw'>=</span> <span class='fl'>5</span>,
  <span class='kw'>n.sim</span> <span class='kw'>=</span> <span class='fl'>100</span>,
  <span class='kw'>n.tree</span> <span class='kw'>=</span> <span class='fl'>2</span>,
  <span class='kw'>btol</span> <span class='kw'>=</span> <span class='fl'>50</span>,
  <span class='kw'>track</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>,
  <span class='no'>...</span>
)</pre>

    <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
    <table class="ref-arguments">
    <colgroup><col class="name" /><col class="desc" /></colgroup>
    <tr>
      <th>formula</th>
      <td><p>The model formula</p></td>
    </tr>
    <tr>
      <th>data</th>
      <td><p>Data frame containing species traits with row names matching tips
in <code>phy</code>.</p></td>
    </tr>
    <tr>
      <th>phy</th>
      <td><p>A phylogeny (class 'multiPhylo', see ?<code>ape</code>).</p></td>
    </tr>
    <tr>
      <th>clade.col</th>
      <td><p>The column in the provided data frame which specifies the
clades (a character vector with clade names).</p></td>
    </tr>
    <tr>
      <th>n.species</th>
      <td><p>Minimum number of species in a clade for the clade to be
included in the leave-one-out deletion analysis. Default is <code>5</code>.</p></td>
    </tr>
    <tr>
      <th>n.sim</th>
      <td><p>Number of simulations for the randomization test.</p></td>
    </tr>
    <tr>
      <th>n.tree</th>
      <td><p>Number of times to repeat the analysis with n different trees picked 
randomly in the multiPhylo file.
If NULL, <code>n.tree</code> = 2</p></td>
    </tr>
    <tr>
      <th>btol</th>
      <td><p>Bound on searching space. For details see <code>phyloglm</code></p></td>
    </tr>
    <tr>
      <th>track</th>
      <td><p>Print a report tracking function progress (default = TRUE)</p></td>
    </tr>
    <tr>
      <th>...</th>
      <td><p>Further arguments to be passed to <code>phyloglm</code></p></td>
    </tr>
    </table>

    <h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>

    <p>The function <code>clade_phyglm</code> returns a list with the following
components:</p>
<p><code>formula</code>: The formula</p>
<p><code>full.model.estimates</code>: Coefficients, aic and the optimised
value of the phylogenetic parameter (e.g. <code>lambda</code>) for the full model
without deleted species.</p>
<p><code>sensi.estimates</code>: A data frame with all simulation
estimates. Each row represents a deleted clade for a tree iteration. Columns report the calculated
regression intercept (<code>intercept</code>), difference between simulation
intercept and full model intercept (<code>DIFintercept</code>), the percentage of change
in intercept compared to the full model (<code>intercept.perc</code>) and intercept
p-value (<code>pval.intercept</code>). All these parameters are also reported for the regression
slope (<code>DIFestimate</code> etc.). Additionally, model aic value (<code>AIC</code>) and
the optimised value (<code>optpar</code>) of the phylogenetic parameter 
(e.g. <code>kappa</code> or <code>lambda</code>, depending on the phylogenetic model used) 
are reported.</p>
<p><code>null.dist</code>: A data frame with estimates for the null distributions
for all clades analysed.</p>
<p><code>data</code>: Original full dataset.</p>
<p><code>errors</code>: Clades and/or trees where deletion resulted in errors.</p>
    <h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>

    <p>Currently only logistic regression using the "logistic_MPLE"-method from
<code>phyloglm</code> is implemented.</p>
<p>This function sequentially removes one clade at a time, fits a phylogenetic
logistic regression model using <code><a href='https://rdrr.io/pkg/phylolm/man/phyloglm.html'>phyloglm</a></code> and stores the
results. The impact of of a specific clade on model estimates is calculated by the
comparison between the full model (with all species) and the model without 
the species belonging to a clade. It repeats this operation using n trees, 
randomly picked in a multiPhylo file.</p>
<p>Additionally, to account for the influence of the number of species on each 
clade (clade sample size), this function also estimates a null distribution of slopes
expected for the number of species in a given clade. This is done by fitting
models without the same number of species in the given clade. 
 The number of simulations to be performed is set by 'n.sim'. To test if the 
 clade influence differs from the null expectation for a clade of that size, 
 a randomization test can be performed using 'summary(x)'.</p>

<p><code>clade_phyglm</code> detects influential clades based on
difference in intercept and/or slope when removing a given clade compared
to the full model including all species. This is done for n trees in the multiphylo file.</p>
<p>Currently, this function can only implements simple logistic models (i.e. \(trait~
predictor\)). In the future we will implement more complex models.</p>
<p>Output can be visualised using <code>sensi_plot</code>.</p>
    <h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>

    <p>Paterno, G. B., Penone, C. Werner, G. D. A. 
<a href='http://doi.wiley.com/10.1111/2041-210X.12990'>sensiPhy: 
An r-package for sensitivity analysis in phylogenetic 
comparative methods.</a> Methods in Ecology and Evolution 
2018, 9(6):1461-1467</p>
<p>Ho, L. S. T. and Ane, C. 2014. "A linear-time algorithm for 
Gaussian and non-Gaussian trait evolution models". Systematic Biology 63(3):397-408.</p>
    <h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>

    <div class='dont-index'><p><code><a href='https://rdrr.io/pkg/phylolm/man/phyloglm.html'>phyloglm</a></code>, <code><a href='tree_phyglm.html'>tree_phyglm</a></code>,
 <code><a href='clade_phyglm.html'>clade_phyglm</a></code>, <code><a href='tree_clade_phylm.html'>tree_clade_phylm</a></code>,
<code><a href='sensi_plot.html'>sensi_plot</a></code></p></div>

    <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
    <pre class="examples"><div class='input'><span class='kw'>if</span> (<span class='fl'>FALSE</span>) {
<span class='co'># Simulate Data:</span>
<span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span>(<span class='fl'>6987</span>)
<span class='no'>mphy</span> <span class='kw'>=</span> <span class='fu'>rmtree</span>(<span class='fl'>150</span>, <span class='kw'>N</span> <span class='kw'>=</span> <span class='fl'>30</span>)
<span class='no'>x</span> <span class='kw'>=</span> <span class='fu'>rTrait</span>(<span class='kw'>n</span><span class='kw'>=</span><span class='fl'>1</span>,<span class='kw'>phy</span><span class='kw'>=</span><span class='no'>mphy</span><span class='kw'>[[</span><span class='fl'>1</span>]])
<span class='no'>X</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span>(<span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>1</span>,<span class='fl'>150</span>),<span class='no'>x</span>)
<span class='no'>y</span> <span class='kw'>=</span> <span class='fu'>rbinTrait</span>(<span class='kw'>n</span><span class='kw'>=</span><span class='fl'>1</span>,<span class='kw'>phy</span><span class='kw'>=</span><span class='no'>mphy</span><span class='kw'>[[</span><span class='fl'>1</span>]], <span class='kw'>beta</span><span class='kw'>=</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(-<span class='fl'>1</span>,<span class='fl'>0.5</span>), <span class='kw'>alpha</span><span class='kw'>=</span><span class='fl'>.7</span> ,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)
<span class='no'>cla</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"A"</span>,<span class='st'>"B"</span>,<span class='st'>"C"</span>,<span class='st'>"D"</span>,<span class='st'>"E"</span>), <span class='kw'>each</span> <span class='kw'>=</span> <span class='fl'>30</span>)
<span class='no'>dat</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span>(<span class='no'>y</span>, <span class='no'>x</span>, <span class='no'>cla</span>)
<span class='co'># Run sensitivity analysis:</span>
<span class='no'>tree_clade</span> <span class='kw'>&lt;-</span> <span class='fu'>tree_clade_phyglm</span>(<span class='no'>y</span> ~ <span class='no'>x</span>, <span class='kw'>phy</span> <span class='kw'>=</span> <span class='no'>mphy</span>, <span class='kw'>data</span> <span class='kw'>=</span> <span class='no'>dat</span>,
<span class='kw'>n.tree</span> <span class='kw'>=</span> <span class='fl'>10</span>, <span class='kw'>n.sim</span> <span class='kw'>=</span> <span class='fl'>10</span>, <span class='kw'>clade.col</span> <span class='kw'>=</span> <span class='st'>"cla"</span>)
<span class='co'># To check summary results and most influential clades:</span>
<span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span>(<span class='no'>tree_clade</span>)
<span class='co'># Visual diagnostics for clade removal:</span>
<span class='fu'><a href='sensi_plot.html'>sensi_plot</a></span>(<span class='no'>tree_clade</span>)
<span class='co'># Specify which clade removal to plot:</span>
<span class='fu'><a href='sensi_plot.html'>sensi_plot</a></span>(<span class='no'>tree_clade</span>, <span class='st'>"B"</span>)
<span class='fu'><a href='sensi_plot.html'>sensi_plot</a></span>(<span class='no'>tree_clade</span>, <span class='st'>"C"</span>, <span class='kw'>graphs</span> <span class='kw'>=</span> <span class='fl'>2</span>)
<span class='fu'><a href='sensi_plot.html'>sensi_plot</a></span>(<span class='no'>tree_clade</span>, <span class='st'>"D"</span>, <span class='kw'>graphs</span> <span class='kw'>=</span> <span class='fl'>2</span>)
}
<span class='co'># \dontshow{</span>
<span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span>(<span class='fl'>6987</span>)
<span class='no'>mphy</span> <span class='kw'>=</span> <span class='fu'>rmtree</span>(<span class='fl'>150</span>, <span class='kw'>N</span> <span class='kw'>=</span> <span class='fl'>30</span>)
<span class='no'>x</span> <span class='kw'>=</span> <span class='fu'>rTrait</span>(<span class='kw'>n</span><span class='kw'>=</span><span class='fl'>1</span>,<span class='kw'>phy</span><span class='kw'>=</span><span class='no'>mphy</span><span class='kw'>[[</span><span class='fl'>1</span>]])
<span class='no'>X</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span>(<span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>1</span>,<span class='fl'>150</span>),<span class='no'>x</span>)
<span class='no'>y</span> <span class='kw'>=</span> <span class='fu'>rbinTrait</span>(<span class='kw'>n</span><span class='kw'>=</span><span class='fl'>1</span>,<span class='kw'>phy</span><span class='kw'>=</span><span class='no'>mphy</span><span class='kw'>[[</span><span class='fl'>1</span>]], <span class='kw'>beta</span><span class='kw'>=</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(-<span class='fl'>1</span>,<span class='fl'>0.5</span>), <span class='kw'>alpha</span><span class='kw'>=</span><span class='fl'>.7</span> ,<span class='kw'>X</span><span class='kw'>=</span><span class='no'>X</span>)
<span class='no'>cla</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"A"</span>,<span class='st'>"B"</span>,<span class='st'>"C"</span>,<span class='st'>"D"</span>,<span class='st'>"E"</span>), <span class='kw'>each</span> <span class='kw'>=</span> <span class='fl'>30</span>)
<span class='no'>dat</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span>(<span class='no'>y</span>, <span class='no'>x</span>, <span class='no'>cla</span>)
<span class='co'># Run sensitivity analysis:</span>
<span class='no'>tree_clade</span> <span class='kw'>&lt;-</span> <span class='fu'>tree_clade_phyglm</span>(<span class='no'>y</span> ~ <span class='no'>x</span>, <span class='kw'>phy</span> <span class='kw'>=</span> <span class='no'>mphy</span>, <span class='kw'>data</span> <span class='kw'>=</span> <span class='no'>dat</span>,
                               <span class='kw'>n.tree</span> <span class='kw'>=</span> <span class='fl'>2</span>, <span class='kw'>n.sim</span> <span class='kw'>=</span> <span class='fl'>1</span>, <span class='kw'>clade.col</span> <span class='kw'>=</span> <span class='st'>"cla"</span>)</div><div class='output co'>#&gt; <span class='message'>Used dataset has  150  species that match data and phylogeny</span></div><div class='output co'>#&gt; 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================================================| 100%</div><div class='input'><span class='co'># To check summary results and most influential clades:</span>
<span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span>(<span class='no'>tree_clade</span>)</div><div class='output co'>#&gt; $Estimate
#&gt;   clade.removed N.species  estimate  DIFestimate Change (%)         Pval
#&gt; 4             D        30 0.6734920  0.156708757      30.35 1.144792e-06
#&gt; 3             C        30 0.4189061 -0.097877230      18.90 7.741017e-05
#&gt; 2             B        30 0.4502398 -0.066543453      12.85 1.328916e-05
#&gt; 5             E        30 0.5664308  0.049647543       9.65 4.854874e-06
#&gt; 1             A        30 0.5105626 -0.006220664       1.20 1.591829e-05
#&gt;   m.null.estimate Pval.randomization Significant (%)
#&gt; 4       0.5366828                0.0             100
#&gt; 3       0.4845104                0.0             100
#&gt; 2       0.5469125                0.0             100
#&gt; 5       0.5024571                0.5              50
#&gt; 1       0.5319009                0.5              50
#&gt; 
#&gt; $Intercept
#&gt;   clade.removed N.species  intercept DIFintercept Change (%)         Pval
#&gt; 4             D        30 -0.9033605  -0.13145386      17.05 1.144792e-06
#&gt; 3             C        30 -0.7937692  -0.02186248       5.20 7.741017e-05
#&gt; 2             B        30 -0.4858454   0.28606132      37.00 1.328916e-05
#&gt; 5             E        30 -0.9960052  -0.22409851      29.05 4.854874e-06
#&gt; 1             A        30 -0.7242611   0.04764556       6.15 1.591829e-05
#&gt;   m.null.intercept Pval.randomization Significant (%)
#&gt; 4       -0.7520597                0.0             100
#&gt; 3       -0.6963086                0.0             100
#&gt; 2       -0.8444144                0.0             100
#&gt; 5       -0.7636749                0.5              50
#&gt; 1       -0.7652482                0.5              50
#&gt; </div><div class='input'><span class='co'># Visual diagnostics for clade removal:</span>
<span class='fu'><a href='sensi_plot.html'>sensi_plot</a></span>(<span class='no'>tree_clade</span>)</div><div class='output co'>#&gt; <span class='warning'>Warning: Clade argument was not defined. Plotting results for clade: A</span>
#&gt; <span class='warning'>            Use clade = 'clade name' to plot results for other clades</span></div><div class='output co'>#&gt; <span class='warning'>Warning: `fun.y` is deprecated. Use `fun` instead.</span></div><div class='img'><img src='tree_clade_phyglm-1.png' alt='' width='700' height='433' /></div><div class='input'># }
</div></pre>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
    <h2>Contents</h2>
    <ul class="nav nav-pills nav-stacked">
      <li><a href="#arguments">Arguments</a></li>
      <li><a href="#value">Value</a></li>
      <li><a href="#details">Details</a></li>
      <li><a href="#references">References</a></li>
      <li><a href="#see-also">See also</a></li>
      <li><a href="#examples">Examples</a></li>
    </ul>

    <h2>Author</h2>
    <p>Gustavo Paterno, Caterina Penone &amp; Gijsbert D.A. Werner</p>
  </div>
</div>


      <footer>
      <div class="copyright">
  <p>Developed by Gustavo Paterno, Gijsbert Werner, Caterina Penone.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.4.1.</p>
</div>

      </footer>
   </div>

  


  </body>
</html>


