<!-- 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>Intraspecific variability - Phylogenetic Logistic Regression — intra_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="Intraspecific variability - Phylogenetic Logistic Regression — intra_phyglm" />
<meta property="og:description" content="Performs Phylogenetic logistic regression evaluating
intraspecific variability in predictor variables." />
<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>Intraspecific variability - Phylogenetic Logistic Regression</h1>
    <small class="dont-index">Source: <a href='https://github.com/paternogbc/sensiPhy/blob/master/R/intra_phyglm.R'><code>R/intra_phyglm.R</code></a></small>
    <div class="hidden name"><code>intra_phyglm.Rd</code></div>
    </div>

    <div class="ref-description">
    <p>Performs Phylogenetic logistic regression evaluating
intraspecific variability in predictor variables.</p>
    </div>

    <pre class="usage"><span class='fu'>intra_phyglm</span>(
  <span class='no'>formula</span>,
  <span class='no'>data</span>,
  <span class='no'>phy</span>,
  <span class='kw'>Vx</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  <span class='kw'>n.intra</span> <span class='kw'>=</span> <span class='fl'>30</span>,
  <span class='kw'>x.transf</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
  <span class='kw'>distrib</span> <span class='kw'>=</span> <span class='st'>"normal"</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: <code>response~predictor</code>.</p></td>
    </tr>
    <tr>
      <th>data</th>
      <td><p>Data frame containing species traits with species as row names.</p></td>
    </tr>
    <tr>
      <th>phy</th>
      <td><p>A phylogeny (class 'phylo', see ?<code>ape</code>).</p></td>
    </tr>
    <tr>
      <th>Vx</th>
      <td><p>Name of the column containing the standard deviation or the standard error of the predictor 
variable. When information is not available for one taxon, the value can be 0 or <code>NA</code></p></td>
    </tr>
    <tr>
      <th>n.intra</th>
      <td><p>Number of times to repeat the analysis generating a random value for the predictor variable.
If NULL, <code>n.intra</code> = 2</p></td>
    </tr>
    <tr>
      <th>x.transf</th>
      <td><p>Transformation for the predictor variable (e.g. <code>log</code> or <code>sqrt</code>). Please use this 
argument instead of transforming data in the formula directly (see also details below).</p></td>
    </tr>
    <tr>
      <th>distrib</th>
      <td><p>A character string indicating which distribution to use to generate a random value for the
predictor variable. Default is normal distribution: "normal" (function <code><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></code>).
Uniform distribution: "uniform" (<code><a href='https://rdrr.io/r/stats/Uniform.html'>runif</a></code>)
Warning: we recommend to use normal distribution with Vx = standard deviation of the mean.</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>intra_phyglm</code> returns a list with the following
components:</p>
<p><code>formula</code>: The formula</p>
<p><code>data</code>: Original full dataset</p>
<p><code>sensi.estimates</code>: Coefficients, aic and the optimised
value of the phylogenetic parameter (e.g. <code>lambda</code>) for each regression.</p>
<p><code>N.obs</code>: Size of the dataset after matching it with tree tips and removing NA's.</p>
<p><code>stats</code>: Main statistics for model parameters.<code>CI_low</code> and <code>CI_high</code> are the lower 
and upper limits of the 95<!-- % confidence interval. --></p>
<p><code>all.stats</code>: Complete statistics for model parameters. <code>sd_intra</code> is the standard deviation 
due to intraspecific variation. <code>CI_low</code> and <code>CI_high</code> are the lower and upper limits 
of the 95<!-- % confidence interval. --></p>
<p><code>sp.pb</code>: Species that caused problems with data transformation (see details above).</p>
    <h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>

    <p>This function fits a phylogenetic logistic regression model using <code><a href='https://rdrr.io/pkg/phylolm/man/phyloglm.html'>phyloglm</a></code>.
The regression is repeated <code>n.intra</code> times. At each iteration the function generates a random value
for each row in the dataset using the standard deviation or error supplied and assuming a normal or uniform distribution.
To calculate means and se for your raw data, you can use the <code>summarySE</code> function from the 
package <code>Rmisc</code>.</p>
<p>All phylogenetic models from <code>phyloglm</code> can be used, i.e. <code>BM</code>,
<code>OUfixedRoot</code>, <code>OUrandomRoot</code>, <code>lambda</code>, <code>kappa</code>,
<code>delta</code>, <code>EB</code> and <code>trend</code>. See ?<code>phyloglm</code> for details.</p>
<p>Currently, this function can only implement 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="warning"><a class="anchor" href="#warning"></a>Warning</h2>

    
  
<p>When Vx exceeds X negative (or null) values can be generated, this might cause problems
for data transformation (e.g. log-transformation). In these cases, the function will skip the simulation. This problem can
be solved by increasing <code>n.intra</code>, changing the transformation type and/or checking the target species in output$sp.pb.</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>Martinez, P. a., Zurano, J.P., Amado, T.F., Penone, C., Betancur-R, R., 
Bidau, C.J. &amp; Jacobina, U.P. (2015). Chromosomal diversity in tropical reef 
fishes is related to body size and depth range. Molecular Phylogenetics and 
Evolution, 93, 1-4</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='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='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'>phy</span> <span class='kw'>=</span> <span class='fu'>rtree</span>(<span class='fl'>150</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'>phy</span>)
<span class='no'>x_sd</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='fl'>150</span>,<span class='kw'>mean</span> <span class='kw'>=</span> <span class='fl'>0.8</span>,<span class='kw'>sd</span><span class='kw'>=</span><span class='fl'>0.2</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'>phy</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'>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'>x_sd</span>)

<span class='co'># Run phylogenetic logistic regression accounting for intraspecific variation:</span>
<span class='no'>intra_glm</span> <span class='kw'>&lt;-</span> <span class='fu'>intra_phyglm</span>(<span class='no'>y</span>~<span class='no'>x</span>,<span class='kw'>Vx</span> <span class='kw'>=</span> <span class='st'>"x_sd"</span>,<span class='kw'>data</span> <span class='kw'>=</span> <span class='no'>dat</span>,<span class='kw'>phy</span><span class='kw'>=</span><span class='no'>phy</span>,<span class='kw'>distrib</span> <span class='kw'>=</span> <span class='st'>"normal"</span>)</div><div class='output co'>#&gt; <span class='warning'>Warning: distrib=normal: make sure that standard deviation is provided for Vx</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%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |======================================================================| 100%</div><div class='input'>
<span class='co'>#Print summary of sensitivity analysis</span>
<span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span>(<span class='no'>intra_glm</span>)</div><div class='output co'>#&gt;                  mean CI_low CI_high
#&gt; intercept      -1.177 -1.185  -1.169
#&gt; se.intercept    0.246  0.243   0.249
#&gt; pval.intercept  0.000  0.000   0.000
#&gt; estimate        0.208  0.187   0.230
#&gt; se.estimate     0.114  0.112   0.116
#&gt; pval.estimate   0.096  0.065   0.127</div><div class='input'><span class='fu'><a href='https://rdrr.io/r/utils/head.html'>head</a></span>(<span class='no'>intra_glm</span>$<span class='no'>sensi.estimates</span>)</div><div class='output co'>#&gt;   n.intra intercept se.intercept pval.intercept  estimate se.estimate
#&gt; 1       1 -1.160425    0.2435488   1.891807e-06 0.2104912   0.1114169
#&gt; 2       2 -1.169853    0.2438911   1.613641e-06 0.2081202   0.1101013
#&gt; 3       3 -1.200647    0.2433600   8.071791e-07 0.1428759   0.1049871
#&gt; 4       4 -1.214038    0.2500971   1.208339e-06 0.3386051   0.1187809
#&gt; 5       5 -1.163420    0.2639525   1.044812e-05 0.2868938   0.1195247
#&gt; 6       6 -1.201741    0.2385108   4.691501e-07 0.1239343   0.1118772
#&gt;   pval.estimate      aic   optpar
#&gt; 1   0.058862195 153.7267 1.310297
#&gt; 2   0.058723178 153.7237 1.286818
#&gt; 3   0.173548341 155.5238 1.337919
#&gt; 4   0.004362748 148.8378 1.217462
#&gt; 5   0.016382176 150.8696 1.057633
#&gt; 6   0.267961000 156.3245 1.444610</div><div class='input'><span class='co'>#Visual output</span>
<span class='fu'><a href='sensi_plot.html'>sensi_plot</a></span>(<span class='no'>intra_glm</span>)</div><div class='img'><img src='intra_phyglm-1.png' alt='' width='700' height='433' /></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="#warning">Warning</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>Caterina Penone &amp; Pablo Ariel Martinez</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>


