<!-- 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>Tests for significant differences among all pairs of intercepts in a dummy variable regression. — compIntercepts • 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" />

<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/spacelab/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />


<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script>

<!-- bootstrap-toc -->
<link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.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" />

<!-- 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>

<!-- 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>

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




<meta property="og:title" content="Tests for significant differences among all pairs of intercepts in a dummy variable regression. — compIntercepts" />
<meta property="og:description" content="Tests for significant differences among all pairs of intercepts in a dummy variable regression where the dummy variables all stem from one factor." />
<meta property="og:image" content="http://derekogle.com/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 data-spy="scroll" data-target="#toc">
    <div class="container template-reference-topic">
      <header>
      <div class="navbar navbar-inverse 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">FSA</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.8.32.9000</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="../reference/index.html">Reference</a>
</li>
<li>
  <a href="../news/index.html">News</a>
</li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
  <a href="../index.html">
    <span class="fas fa-home fa-2x"></span>
     
  </a>
</li>
<li>
  <a href="https://github.com/droglenc/FSA">
    <span class="fas fa-github fa-2x"></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>Tests for significant differences among all pairs of intercepts in a dummy variable regression.</h1>
    <small class="dont-index">Source: <a href='https://github.com/droglenc/FSA/blob/master/R/comparisonsDVR.R'><code>R/comparisonsDVR.R</code></a></small>
    <div class="hidden name"><code>compIntercepts.Rd</code></div>
    </div>

    <div class="ref-description">
    <p>Tests for significant differences among all pairs of intercepts in a dummy variable regression where the dummy variables all stem from one factor.</p>
    </div>

    <pre class="usage"><span class='fu'>compIntercepts</span><span class='op'>(</span>
  <span class='va'>mdl</span>,
  common.cov <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/mean.html'>mean</a></span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span>,
  conf.level <span class='op'>=</span> <span class='fl'>0.95</span>,
  digits <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span><span class='op'>(</span><span class='st'>"digits"</span><span class='op'>)</span>,
  <span class='va'>...</span>
<span class='op'>)</span>

<span class='co'># S3 method for compIntercepts</span>
<span class='fu'><a href='https://rdrr.io/r/base/print.html'>print</a></span><span class='op'>(</span><span class='va'>x</span>, <span class='va'>...</span><span class='op'>)</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>mdl</th>
      <td><p>A <code>lm</code> object.</p></td>
    </tr>
    <tr>
      <th>common.cov</th>
      <td><p>A value to be used as the common value of the covariate in the adjustment process. See details.</p></td>
    </tr>
    <tr>
      <th>conf.level</th>
      <td><p>A single number that represents the level of confidence to use for constructing confidence intervals.</p></td>
    </tr>
    <tr>
      <th>digits</th>
      <td><p>A numeric that controls the number of digits to print.</p></td>
    </tr>
    <tr>
      <th>...</th>
      <td><p>Other arguments to be passed to the <code>TukeyHSD</code> or <code>print</code> functions.</p></td>
    </tr>
    <tr>
      <th>x</th>
      <td><p>A <code>compIntercepts</code> object (i.e., returned from <code>compIntercepts</code>).</p></td>
    </tr>
    </table>

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

    <p>A list with the following four components:</p><table class='table'>
<tr><td><code>comparison</code></td><td>The comparison results as returned from <code><a href='https://rdrr.io/r/stats/TukeyHSD.html'>TukeyHSD</a></code>.</td></tr>
<tr><td><code>common.cov</code></td><td>The value of the common covariate sent in <code>common.cov</code>.</td></tr>
<tr><td><code>adjvals</code></td><td>A vector of values of the response variable adjusted to the <code>common.cov</code> value of the covariate. This vector can be appended to the original data frame to construct summary statistics for the adjusted values (e.g., mean adjusted value for each group).</td></tr>
<tr><td><code>means</code></td><td>A vector of mean adjusted values at the value of the common covariate.</td></tr>
<tr><td><code>digits</code></td><td>The value sent in <code>digits</code>.</td></tr>
<tr><td><code>rnm</code></td><td>The name of the response (LHS) variable.</td></tr>
<tr><td><code>cnm</code></td><td>The name of the covariate variable.</td></tr>
</table>


<p>The <code>print</code> function prints the comparison and adjusted means in a nice format.</p>
    <h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>

    <p>In a dummy variable regression without the interaction(s) between the covariate (x) and the dummy variable(s) (i.e., parallel lines) the coefficient for the dummy variables tests for a difference in intercepts between the level of the dummy variable and the reference level. Thus, all dummy variables from a particular linear model fit only compare intercepts with the reference level. Other intercept comparisons may be found by changing the reference level, which requires refitting the model.</p>
<p>Alternatively, Tukey's HSD method of multiple comparisons may be used, but this requires adjusting the original observations as if the original observations were all collected at the exact same value of the covariate (x). Because of this required adjustment, the  <code><a href='https://rdrr.io/r/stats/TukeyHSD.html'>TukeyHSD</a></code> function is inappropriate for testing for difference in intercepts in a dummy variable regression.</p>
<p>This function provides a statistical comparison of all pairs of intercepts by first adjusting the observed data to a common value of the covariate (<code>common.cov</code>), computing a one-way ANOVA to determine if the mean adjusted values differ by level of the group factor in the original dummy variable regression, and then submitting the one-way ANOVA results to the <code><a href='https://rdrr.io/r/stats/TukeyHSD.html'>TukeyHSD</a></code> function to determine for which levels the mean adjusted values differ. The levels for which the mean adjusted values differ are also the levels for which the intercepts differ.</p>
<p>The default is to compute the adjusted values at the mean value of the covariate (i.e., <code>common.cov=mean(x)</code>. However, if interest is in the intercepts (i.e., at X=0) then <code>common.cov=0</code> should be used instead.</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/r/stats/TukeyHSD.html'>TukeyHSD</a></code> and <code>compSlopes</code> from <span class="pkg">FSA</span>.</p></div>
    <h2 class="hasAnchor" id="author"><a class="anchor" href="#author"></a>Author</h2>

    <p>Derek H. Ogle, <a href='mailto:derek@derekogle.com'>derek@derekogle.com</a></p>

    <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
    <pre class="examples"><div class='input'><span class='co'>## Reduce Mirex data to years where slopes don't differ to illustrate this</span>
<span class='co'>##   function ... see compSlopes() for analysis of full data set. </span>
<span class='va'>Mirex</span> <span class='op'>&lt;-</span> <span class='va'>Mirex</span><span class='op'>[</span><span class='va'>Mirex</span><span class='op'>$</span><span class='va'>year</span><span class='op'>!=</span><span class='st'>"1996"</span> <span class='op'>&amp;</span> <span class='va'>Mirex</span><span class='op'>$</span><span class='va'>year</span><span class='op'>!=</span><span class='st'>"1999"</span>,<span class='op'>]</span>
<span class='va'>Mirex</span><span class='op'>$</span><span class='va'>year</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>Mirex</span><span class='op'>$</span><span class='va'>year</span><span class='op'>)</span>
<span class='co'>## Fit DVR, see that slopes don't differ, </span>
<span class='co'>##   compare intercepts, visualize results</span>
<span class='va'>lm1</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/lm.html'>lm</a></span><span class='op'>(</span><span class='va'>mirex</span><span class='op'>~</span><span class='va'>weight</span><span class='op'>*</span><span class='va'>year</span>,data<span class='op'>=</span><span class='va'>Mirex</span><span class='op'>)</span>
<span class='fu'><a href='https://rdrr.io/r/stats/anova.html'>anova</a></span><span class='op'>(</span><span class='va'>lm1</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Analysis of Variance Table
#&gt; 
#&gt; Response: mirex
#&gt;             Df  Sum Sq Mean Sq  F value    Pr(&gt;F)    
#&gt; weight       1 0.43886 0.43886 103.7272 7.431e-16 ***
#&gt; year         3 0.07602 0.02534   5.9895  0.001016 ** 
#&gt; weight:year  3 0.00089 0.00030   0.0704  0.975568    
#&gt; Residuals   76 0.32155 0.00423                       
#&gt; ---
#&gt; Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</div><div class='input'><span class='fu'>compIntercepts</span><span class='op'>(</span><span class='va'>lm1</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='warning'>Warning: Removed an interaction term from 'mdl' (i.e., assumed</span>
#&gt; <span class='warning'> parallel lines) to test intercepts.</span></div><div class='output co'>#&gt; <span class='message'>Tukey HSD on means adjusted assuming parallel lines</span></div><div class='output co'>#&gt;   comparison        diff     95% LCI      95% UCI        p.adj
#&gt; 1  1982-1977 -0.05416588 -0.10225344 -0.006078329 0.0209412606
#&gt; 2  1986-1977 -0.06545122 -0.11353877 -0.017363664 0.0033259143
#&gt; 3  1992-1977 -0.09021635 -0.14911133 -0.031321360 0.0007448995
#&gt; 4  1986-1982 -0.01128533 -0.05937289  0.036802220 0.9267699991
#&gt; 5  1992-1982 -0.03605046 -0.09494545  0.022844523 0.3810617955
#&gt; 6  1992-1986 -0.02476513 -0.08366011  0.034129857 0.6885397505</div><div class='output co'>#&gt; <span class='message'></span>
#&gt; <span class='message'>Mean mirex when weight=4.258452</span></div><div class='output co'>#&gt;      1977      1982      1986      1992 
#&gt; 0.2506358 0.1964699 0.1851846 0.1604194 </div><div class='input'><span class='co'>## Fit model without interaction to avoid warning, but</span>
<span class='co'>##   note that the compIntercepts() results are the same</span>
<span class='va'>lm2</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/lm.html'>lm</a></span><span class='op'>(</span><span class='va'>mirex</span><span class='op'>~</span><span class='va'>weight</span><span class='op'>+</span><span class='va'>year</span>,data<span class='op'>=</span><span class='va'>Mirex</span><span class='op'>)</span>
<span class='fu'>compIntercepts</span><span class='op'>(</span><span class='va'>lm2</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Tukey HSD on means adjusted assuming parallel lines</span></div><div class='output co'>#&gt;   comparison        diff     95% LCI      95% UCI        p.adj
#&gt; 1  1982-1977 -0.05416588 -0.10225344 -0.006078329 0.0209412606
#&gt; 2  1986-1977 -0.06545122 -0.11353877 -0.017363664 0.0033259143
#&gt; 3  1992-1977 -0.09021635 -0.14911133 -0.031321360 0.0007448995
#&gt; 4  1986-1982 -0.01128533 -0.05937289  0.036802220 0.9267699991
#&gt; 5  1992-1982 -0.03605046 -0.09494545  0.022844523 0.3810617955
#&gt; 6  1992-1986 -0.02476513 -0.08366011  0.034129857 0.6885397505</div><div class='output co'>#&gt; <span class='message'></span>
#&gt; <span class='message'>Mean mirex when weight=4.258452</span></div><div class='output co'>#&gt;      1977      1982      1986      1992 
#&gt; 0.2506358 0.1964699 0.1851846 0.1604194 </div><div class='input'><span class='fu'><a href='fitPlot.html'>fitPlot</a></span><span class='op'>(</span><span class='va'>lm1</span>,legend<span class='op'>=</span><span class='st'>"topleft"</span><span class='op'>)</span>
</div><div class='img'><img src='compIntercepts-1.png' alt='' width='700' height='433' /></div><div class='input'>
</div></pre>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
    <nav id="toc" data-toggle="toc" class="sticky-top">
      <h2 data-toc-skip>Contents</h2>
    </nav>
  </div>
</div>


      <footer>
      <div class="copyright">
  <p>Developed by Derek Ogle, Jason Doll, Powell Wheeler, Alexis Dinno.</p>
</div>

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

      </footer>
   </div>

  


  </body>
</html>


