Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If R were to create a dummy variable for every level in the factor, the resulting set of variables would be linearly dependent (assuming there is also an intercept term). Therefore, one factor level is chosen as the baseline and has no dummy generated for it.</p> <p>To illustrate this, let's consider a toy example:</p> <pre><code>&gt; data &lt;- data.frame(y=c(2, 3, 5, 7, 11, 25), f=as.factor(c('a', 'a', 'b', 'b', 'c', 'c'))) &gt; summary(lm(y ~ f, data)) Call: lm(formula = y ~ f, data = data) Residuals: 1 2 3 4 5 6 -0.5 0.5 -1.0 1.0 -7.0 7.0 Coefficients: Estimate Std. Error t value Pr(&gt;|t|) (Intercept) 2.500 4.093 0.611 0.5845 fb 3.500 5.788 0.605 0.5880 fc 15.500 5.788 2.678 0.0752 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 5.788 on 3 degrees of freedom Multiple R-squared: 0.7245, Adjusted R-squared: 0.5409 F-statistic: 3.945 on 2 and 3 DF, p-value: 0.1446 </code></pre> <p>As you can see, there are three coefficients (the same as the number of levels in the factor). Here, <code>a</code> has been chosen as the baseline, so <code>(Intercept)</code> refers to the subset of data where <code>f</code> is <code>a</code>. The coefficients for <code>b</code> and <code>c</code> (<code>fb</code> and <code>fc</code>) are the <em>differences</em> between the baseline intercept and the intercepts for the two other factor levels. Thus the intercept for <code>b</code> is <code>6</code> (<code>2.500+3.500</code>) and the intercept for <code>c</code> is <code>19</code> (<code>2.500+15.500</code>).</p> <p>If you don't like the automatic choice, you could pick another level as the baseline: <a href="https://stackoverflow.com/questions/3872070/how-to-force-r-to-use-a-specified-factor-level-as-reference-in-a-regression">How to force R to use a specified factor level as reference in a regression?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload