The metafor Package

A Meta-Analysis Package for R

User Tools

Site Tools


tips:models_with_or_without_intercept

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tips:models_with_or_without_intercept [2021/11/10 20:19] Wolfgang Viechtbauertips:models_with_or_without_intercept [2024/06/18 19:29] (current) Wolfgang Viechtbauer
Line 64: Line 64:
 By default, ''alternate'' was made the reference level (since the first letter "a" comes before "r" and "s" in the alphabet), so the corresponding dummy variable for this level has been left out.((Since ''alloc'' is a character variable, the coercion to a factor via the ''factor()'' function isn't strictly necessary (since this would have happened automatically anyway), but it's better to be explicit. In some cases, a numeric variable may in fact be used to represent levels of a categorical variable, in which case use of the ''factor()'' function is crucial.)) Therefore, the model intercept (coefficients $b_0$) is the estimated (average) log risk ratio for alternating allocation. The coefficients for ''factor(alloc)random'' (coefficient $b_1$) and ''factor(alloc)systematic'' (coefficient $b_2$) indicate how much lower/higher the estimated (average) log risk ratio is for random and systematic allocation, respectively, compared to alternating allocation. So these coefficients reflect contrasts between these two levels compared to the reference level. Neither coefficient is significantly different from 0 (as indicated by the corresponding p-values), but this isn't a proper test of the factor as a whole. By default, ''alternate'' was made the reference level (since the first letter "a" comes before "r" and "s" in the alphabet), so the corresponding dummy variable for this level has been left out.((Since ''alloc'' is a character variable, the coercion to a factor via the ''factor()'' function isn't strictly necessary (since this would have happened automatically anyway), but it's better to be explicit. In some cases, a numeric variable may in fact be used to represent levels of a categorical variable, in which case use of the ''factor()'' function is crucial.)) Therefore, the model intercept (coefficients $b_0$) is the estimated (average) log risk ratio for alternating allocation. The coefficients for ''factor(alloc)random'' (coefficient $b_1$) and ''factor(alloc)systematic'' (coefficient $b_2$) indicate how much lower/higher the estimated (average) log risk ratio is for random and systematic allocation, respectively, compared to alternating allocation. So these coefficients reflect contrasts between these two levels compared to the reference level. Neither coefficient is significantly different from 0 (as indicated by the corresponding p-values), but this isn't a proper test of the factor as a whole.
  
-The results given under "Test of Moderators" provides a joint or [[wp>Omnibus_test|omnibus test]] of all model coefficients except for the intercept (''coefficients 2:3''). Careful: The numbering of the coefficients here starts at 1, corresponding to the intercept (''intrcpt''), with coefficients 2 and 3 corresponding to ''factor(alloc)random'' and ''factor(alloc)systematic''. The results indicate that we cannot reject the null hypothesis $H_0: \beta_1 = \beta_2 = 0$. Since we cannot reject the null hypothesis that random and systematic allocation are different from alternating allocation, then this implies that the three-level factor as a whole is not significant.+The results given under "Test of Moderators" provides a joint or [[wp>Omnibus_test|omnibus test]] of all model coefficients except for the intercept (''coefficients 2:3''). Careful: The numbering of the coefficients here starts at 1, corresponding to the intercept (''intrcpt''), with coefficients 2 and 3 corresponding to ''factor(alloc)random'' and ''factor(alloc)systematic''. The results indicate that we cannot reject the null hypothesis $\mbox{H}_0{:}\; \beta_1 = \beta_2 = 0$. Since we cannot reject the null hypothesis that random and systematic allocation are different from alternating allocation, then this implies that the three-level factor as a whole is not significant.
  
 We can also test one or multiple model coefficients ourselves (and contrasts between them, as we will see further below) using the ''anova()'' function. The same omnibus test as above can be obtained with: We can also test one or multiple model coefficients ourselves (and contrasts between them, as we will see further below) using the ''anova()'' function. The same omnibus test as above can be obtained with:
Line 162: Line 162:
 Now we will fit the model, but remove the intercept, which can be done with: Now we will fit the model, but remove the intercept, which can be done with:
 <code rsplus> <code rsplus>
-res <- rma(yi, vi, mods = ~ factor(alloc) - 1, data=dat)+res <- rma(yi, vi, mods = ~ 0 + factor(alloc), data=dat)
 res res
 </code> </code>
 +Alternatively, one could use ''mods = ~ factor(alloc) - 1'' to remove the intercept. In either case, the output is then:
 <code output> <code output>
 Mixed-Effects Model (k = 13; tau^2 estimator: REML) Mixed-Effects Model (k = 13; tau^2 estimator: REML)
Line 217: Line 218:
    estimate     se    zval   pval    estimate     se    zval   pval
 1:  -0.5180 0.4412 -1.1740 0.2404 1:  -0.5180 0.4412 -1.1740 0.2404
-2:  -0.9658 0.2672 -3.6138 0.0003+2:  -0.9658 0.2672 -3.6138 0.0003 ***
 3:  -0.4289 0.3449 -1.2434 0.2137 3:  -0.4289 0.3449 -1.2434 0.2137
  
Line 229: Line 230:
 </code> </code>
 <code output> <code output>
-Hypotheses:                                                          +Hypotheses: 
-1:     -factor(alloc)alternate + factor(alloc)random = 0  +1:     -factor(alloc)alternate + factor(alloc)random = 0 
-2: -factor(alloc)alternate + factor(alloc)systematic = 0  +2: -factor(alloc)alternate + factor(alloc)systematic = 0 
-3:    -factor(alloc)random + factor(alloc)systematic = 0 +3:    -factor(alloc)random + factor(alloc)systematic = 0
  
 Results: Results:
-   estimate     se    zval   pval  +   estimate     se    zval   pval 
-1:  -0.4478 0.5158 -0.8682 0.3853  +1:  -0.4478 0.5158 -0.8682 0.3853 
-2:   0.0890 0.5600  0.1590 0.8737 +2:   0.0890 0.5600  0.1590 0.8737
 3:   0.5369 0.4364  1.2303 0.2186 3:   0.5369 0.4364  1.2303 0.2186
 </code> </code>
Line 289: Line 290:
 Now what happens if we remove the intercept? Now what happens if we remove the intercept?
 <code rsplus> <code rsplus>
-res <- rma(yi, vi, mods = ~ ablat - 1, data=dat)+res <- rma(yi, vi, mods = ~ 0 + ablat, data=dat)
 </code> </code>
 <code output> <code output>
tips/models_with_or_without_intercept.txt · Last modified: 2024/06/18 19:29 by Wolfgang Viechtbauer