<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content="Likelihood ratio and extra sum-of-squares tests with multiple lm or nls models nested within one common model. This function is most useful when the nested functions are all at the same level; otherwise use anova() or lrtest() which are more flexible."><title>Likelihood ratio and extra sum-of-squares tests. — extraTests • FSA</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Likelihood ratio and extra sum-of-squares tests. — extraTests"><meta property="og:description" content="Likelihood ratio and extra sum-of-squares tests with multiple lm or nls models nested within one common model. This function is most useful when the nested functions are all at the same level; otherwise use anova() or lrtest() which are more flexible."><meta property="og:image" content="https://fishr-core-team.github.io/FSA/logo.png"><!-- 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>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>
    

    <nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
    
    <a class="navbar-brand me-2" href="../index.html">FSA</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Released version">0.9.5</small>

    
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item">
  <a class="nav-link" href="../reference/index.html">Reference</a>
</li>
      </ul><form class="form-inline my-2 my-lg-0" role="search">
        <input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>

      <ul class="navbar-nav"><li class="nav-item">
  <a class="nav-link" href="../news/index.html">
    <span class="fa fa-newspaper"></span>
     
  </a>
</li>
<li class="nav-item">
  <a class="nav-link" href="../index.html">
    <span class="fa fa-home fa"></span>
     
  </a>
</li>
<li class="nav-item">
  <a class="external-link nav-link" href="https://github.com/fishR-Core-Team/FSA">
    <span class="fa fa-github fa"></span>
     
  </a>
</li>
      </ul></div>

    
  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">
      <img src="../logo.png" class="logo" alt=""><h1>Likelihood ratio and extra sum-of-squares tests.</h1>
      <small class="dont-index">Source: <a href="https://github.com/fishR-Core-Team/FSA/blob/HEAD/R/extraTests.R" class="external-link"><code>R/extraTests.R</code></a></small>
      <div class="d-none name"><code>extraTests.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Likelihood ratio and extra sum-of-squares tests with multiple <code>lm</code> or <code>nls</code> models nested within one common model. This function is most useful when the nested functions are all at the same level; otherwise use <code><a href="https://rdrr.io/r/stats/anova.html" class="external-link">anova()</a></code> or <code>lrtest()</code> which are more flexible.</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">lrt</span><span class="op">(</span><span class="va">sim</span>, <span class="va">...</span>, <span class="va">com</span>, sim.names <span class="op">=</span> <span class="va">sim.name</span>, sim.name <span class="op">=</span> <span class="cn">NULL</span>, com.name <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">extraSS</span><span class="op">(</span><span class="va">sim</span>, <span class="va">...</span>, <span class="va">com</span>, sim.names <span class="op">=</span> <span class="va">sim.name</span>, sim.name <span class="op">=</span> <span class="cn">NULL</span>, com.name <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># S3 method for extraTest</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">x</span>, <span class="va">...</span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
    <dl><dt>sim</dt>
<dd><p>The results of one <code>lm</code> or <code>nls</code> model, for example, that is a nested subset of the model in <code>com=</code>.</p></dd>


<dt>...</dt>
<dd><p>More model results that are nested subsets of the model in <code>com=</code>.</p></dd>


<dt>com</dt>
<dd><p>The results of one <code>lm</code> or <code>nls</code> model, for example, that the models in <code>sim=</code> and <code>...</code> are a subset of.</p></dd>


<dt>sim.name, sim.names</dt>
<dd><p>A string vector of “names” for simple model in <code>sim=</code> and <code>...</code>. <code>sim.names</code> is preferred but <code>sim.name</code> is allowed to allow for a common typing mistake.</p></dd>


<dt>com.name</dt>
<dd><p>A single “name” string for the complex model in <code>com=</code>.</p></dd>


<dt>x</dt>
<dd><p>An object from <code>lrt()</code> or <code>extraSS()</code>.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    

<p>The main function returns a matrix with as many rows as model comparisons and columns of the following types:</p>
<p></p>
<ul><li><p><code>DfO</code> The error degrees-of-freedom from the subset (more simple) model.</p></li>
<li><p><code>RSSO</code>, <code>logLikO</code> The residual sum-of-squares (from <code>extraSS</code>) or log-likelihood (from <code>lrt</code>) from the subset (more simple) model.</p></li>
<li><p><code>DfA</code> The error degrees-of-freedom from the <code>com=</code> model.</p></li>
<li><p><code>RSSA</code>, <code>logLikA</code> The residual sum-of-squares (from <code>extraSS</code>) or log-likelihood (from <code>lrt</code>) from the <code>com=</code> model.</p></li>
<li><p><code>Df</code> The difference in error degrees-of-freedom between the two models.</p></li>
<li><p><code>SS</code>, <code>logLik</code> The difference in residual sum-of-squares (from <code>extraSS</code>) or log-likelihood (from <code>lrt</code>) between the two models.</p></li>
<li><p><code>F</code>, <code>Chisq</code> The corresponding F- (from <code>extraSS</code>) or Chi-square (from <code>lrt</code>) test statistic.</p></li>
<li><p><code>Pr(&gt;F)</code>, <code>Pr(&gt;Chisq)</code> The corresponding p-value.</p></li>
</ul></div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    <p><code><a href="https://rdrr.io/r/stats/anova.html" class="external-link">anova</a></code> and <code><a href="https://rdrr.io/pkg/lmtest/man/lrtest.html" class="external-link">lrtest</a></code> (from <span class="pkg">lmtest</span>) provide simple methods for conducting extra sum-of-squares or likelihood ratio tests when one model is nested within another model or when there are several layers of simple models all sequentially nested within each other. However, to compare several models that are nested at the same level with one common more complex model, then <code><a href="https://rdrr.io/r/stats/anova.html" class="external-link">anova()</a></code> and <code>lrtest()</code> must be repeated for each comparison. This repetition can be eliminated with <code><a href="https://rdrr.io/r/base/lapply.html" class="external-link">lapply()</a></code> but then the output is voluminous. This function is designed to remove the repetitiveness and to provide output that is compact and easy to read.</p>
    </div>
    <div class="section level2">
    <h2 id="note">Note<a class="anchor" aria-label="anchor" href="#note"></a></h2>
    <p>This function is experimental at this point. It seems to work fine for <code>lm</code> and <code>nls</code> models. An error will be thrown by <code>extraSS</code> for other model classes, but <code>lrt</code> will not (but it has not been thoroughly tests for other models).</p>
    </div>
    <div class="section level2">
    <h2 id="author">Author<a class="anchor" aria-label="anchor" href="#author"></a></h2>
    <p>Derek H. Ogle, <a href="mailto:DerekOgle51@gmail.com">DerekOgle51@gmail.com</a></p>
    </div>

    <div class="section level2">
    <h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co">## Example data</span></span></span>
<span class="r-in"><span><span class="va">df</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>x<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">4</span>,<span class="fl">5</span>,<span class="fl">6</span>,<span class="fl">7</span>,<span class="fl">8</span>,<span class="fl">9</span>,<span class="fl">10</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                 y<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">4</span>,<span class="fl">6</span>,<span class="fl">5</span>,<span class="fl">7</span>,<span class="fl">9</span>,<span class="fl">8</span>,<span class="fl">7</span>,<span class="fl">12</span>,<span class="fl">16</span>,<span class="fl">22</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                 z<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/factor.html" class="external-link">as.factor</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html" class="external-link">rep</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"A"</span>,<span class="st">"B"</span><span class="op">)</span>,each<span class="op">=</span><span class="fl">5</span><span class="op">)</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                 w<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/factor.html" class="external-link">as.factor</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/rep.html" class="external-link">rep</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"A"</span>,<span class="st">"B"</span><span class="op">)</span>,times<span class="op">=</span><span class="fl">5</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">df</span><span class="op">$</span><span class="va">x2</span> <span class="op">&lt;-</span> <span class="va">df</span><span class="op">$</span><span class="va">x</span><span class="op">^</span><span class="fl">2</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## Linear (lm()) models</span></span></span>
<span class="r-in"><span><span class="co">#  ... regression</span></span></span>
<span class="r-in"><span><span class="va">fit.0</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="fl">1</span>,data<span class="op">=</span><span class="va">df</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">fit.1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">x</span>,data<span class="op">=</span><span class="va">df</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">fit.2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">x2</span><span class="op">+</span><span class="va">x</span>,data<span class="op">=</span><span class="va">df</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu">extraSS</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ 1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ x</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ x2 + x </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO    RSSO DfA    RSSA Df      SS      F    Pr(&gt;F)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 282.400   7  27.617  2 254.783 32.290 0.0002925 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8  67.988   7  27.617  1  40.371 10.233 0.0150891 *  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span><span class="fu">lrt</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span><span class="op">)</span></span></span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> Loading required namespace: lmtest</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ 1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ x</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ x2 + x </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO  logLikO DfA  logLikA Df   logLik   Chisq Pr(&gt;Chisq)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 -30.8931   7 -19.2686  2 -11.6245 23.2491  8.944e-06 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8 -23.7731   7 -19.2686  1  -4.5045  9.0091   0.002686 ** </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># ... show labels for models</span></span></span>
<span class="r-in"><span><span class="fu">extraSS</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span>,</span></span>
<span class="r-in"><span>    sim.names<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Null Model"</span>,<span class="st">"Linear"</span><span class="op">)</span>,com.name<span class="op">=</span><span class="st">"Quadratic"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: Null Model</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: Linear</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: Quadratic </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO    RSSO DfA    RSSA Df      SS      F    Pr(&gt;F)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 282.400   7  27.617  2 254.783 32.290 0.0002925 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8  67.988   7  27.617  1  40.371 10.233 0.0150891 *  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span><span class="fu">lrt</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span>,</span></span>
<span class="r-in"><span>    sim.names<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Null Model"</span>,<span class="st">"Linear"</span><span class="op">)</span>,com.name<span class="op">=</span><span class="st">"Quadratic"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: Null Model</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: Linear</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: Quadratic </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO  logLikO DfA  logLikA Df   logLik   Chisq Pr(&gt;Chisq)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 -30.8931   7 -19.2686  2 -11.6245 23.2491  8.944e-06 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8 -23.7731   7 -19.2686  1  -4.5045  9.0091   0.002686 ** </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">#  ... dummy variable regression</span></span></span>
<span class="r-in"><span><span class="va">fit.2b</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">x</span><span class="op">*</span><span class="va">z</span>,data<span class="op">=</span><span class="va">df</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu">extraSS</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2b</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ 1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ x</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ x * z </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO    RSSO DfA    RSSA Df      SS       F    Pr(&gt;F)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 282.400   6  17.800  3 264.600 29.7303 0.0005347 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8  67.988   6  17.800  2  50.188  8.4586 0.0179459 *  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span><span class="fu">lrt</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2b</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ 1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ x</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ x * z </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO  logLikO DfA  logLikA Df   logLik  Chisq Pr(&gt;Chisq)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 -30.8931   6 -17.0725  3 -13.8206 27.641  4.319e-06 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8 -23.7731   6 -17.0725  2  -6.7007 13.401    0.00123 ** </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">#  ... ANOVAs</span></span></span>
<span class="r-in"><span><span class="va">fit.1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">w</span>,data<span class="op">=</span><span class="va">df</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">fit.2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">w</span><span class="op">*</span><span class="va">z</span>,data<span class="op">=</span><span class="va">df</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu">extraSS</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ 1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ w</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ w * z </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO  RSSO DfA  RSSA Df    SS      F Pr(&gt;F)</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 282.4   6 159.0  3 123.4 1.5522 0.2955</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8 262.8   6 159.0  2 103.8 1.9585 0.2215</span>
<span class="r-in"><span><span class="fu">lrt</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ 1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ w</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ w * z </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO  logLikO DfA  logLikA Df   logLik  Chisq Pr(&gt;Chisq)  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 -30.8931   6 -28.0210  3  -2.8721 5.7442    0.12474  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8 -30.5334   6 -28.0210  2  -2.5124 5.0249    0.08107 .</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## Non-linear (nls()) models</span></span></span>
<span class="r-in"><span><span class="va">fit.0</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/nls.html" class="external-link">nls</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">c</span>,data<span class="op">=</span><span class="va">df</span>,start<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>c<span class="op">=</span><span class="fl">10</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">fit.1</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/nls.html" class="external-link">nls</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">a</span><span class="op">*</span><span class="va">x</span><span class="op">+</span><span class="va">c</span>,data<span class="op">=</span><span class="va">df</span>,start<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>a<span class="op">=</span><span class="fl">1</span>,c<span class="op">=</span><span class="fl">1</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">fit.2</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/nls.html" class="external-link">nls</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">b</span><span class="op">*</span><span class="va">x2</span><span class="op">+</span><span class="va">a</span><span class="op">*</span><span class="va">x</span><span class="op">+</span><span class="va">c</span>,data<span class="op">=</span><span class="va">df</span>,start<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>a<span class="op">=</span><span class="op">-</span><span class="fl">1</span>,b<span class="op">=</span><span class="fl">0.3</span>,c<span class="op">=</span><span class="fl">10</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="fu">extraSS</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ c</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ a * x + c</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ b * x2 + a * x + c </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO    RSSO DfA    RSSA Df      SS      F    Pr(&gt;F)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 282.400   7  27.617  2 254.783 32.290 0.0002925 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8  67.988   7  27.617  1  40.371 10.233 0.0150891 *  </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span><span class="fu">lrt</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>,com<span class="op">=</span><span class="va">fit.2</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 1: y ~ c</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model 2: y ~ a * x + c</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Model A: y ~ b * x2 + a * x + c </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     DfO  logLikO DfA  logLikA Df   logLik   Chisq Pr(&gt;Chisq)    </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1vA   9 -30.8931   7 -19.2686  2 -11.6245 23.2491  8.944e-06 ***</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2vA   8 -23.7731   7 -19.2686  1  -4.5045  9.0091   0.002686 ** </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ---</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## General least-squares (gls()) models</span></span></span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="cn">FALSE</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span>  <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="va"><a href="https://svn.r-project.org/R-packages/trunk/nlme/" class="external-link">nlme</a></span><span class="op">)</span></span></span>
<span class="r-in"><span>  <span class="va">fit.0</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/nlme/man/gls.html" class="external-link">gls</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="fl">1</span>,data<span class="op">=</span><span class="va">df</span>,method<span class="op">=</span><span class="st">"ML"</span><span class="op">)</span></span></span>
<span class="r-in"><span>  <span class="va">fit.1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/nlme/man/gls.html" class="external-link">gls</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">x</span>,data<span class="op">=</span><span class="va">df</span>,method<span class="op">=</span><span class="st">"ML"</span><span class="op">)</span></span></span>
<span class="r-in"><span>  <span class="va">fit.2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/nlme/man/gls.html" class="external-link">gls</a></span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">x2</span><span class="op">+</span><span class="va">x</span>,data<span class="op">=</span><span class="va">df</span>,method<span class="op">=</span><span class="st">"ML"</span><span class="op">)</span></span></span>
<span class="r-in"><span>  <span class="fu">lrt</span><span class="op">(</span><span class="va">fit.0</span>,<span class="va">fit.1</span>, com<span class="op">=</span><span class="va">fit.2</span><span class="op">)</span></span></span>
<span class="r-in"><span>  <span class="co">## will return an error ... does not work with gls() models</span></span></span>
<span class="r-in"><span>  <span class="co"># extraSS(fit.0,fit.1, com=fit.2)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p></p><p>Developed by <a href="http://derekogle.com" class="external-link">Derek H. Ogle</a>, Jason C. Doll, A. Powell Wheeler, Alexis Dinno.</p>
</div>

<div class="pkgdown-footer-right">
  <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>

    </footer></div>

  

  

  </body></html>

