The metafor Package

A Meta-Analysis Package for R

User Tools

Site Tools


tips:multiple_factors_interactions

Differences

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

Link to this comparison view

Next revision
Previous revision
tips:multiple_factors_interactions [2018/12/08 13:22]
127.0.0.1 external edit
tips:multiple_factors_interactions [2021/11/10 20:20] (current)
Wolfgang Viechtbauer
Line 10: Line 10:
 dat <- dat.raudenbush1985 dat <- dat.raudenbush1985
 </code> </code>
-I copy the dataset into 'dat', which is a bit shorter and therefore easier to type further below.+I copy the dataset into ''dat'', which is a bit shorter and therefore easier to type further below.
  
 For illustration purposes, we will categorize the ''weeks'' variable (i.e., the number of weeks of contact prior to the expectancy induction) into three levels (0 weeks = "none", 1-9 weeks = "some", and 10+ weeks = "high"): For illustration purposes, we will categorize the ''weeks'' variable (i.e., the number of weeks of contact prior to the expectancy induction) into three levels (0 weeks = "none", 1-9 weeks = "some", and 10+ weeks = "high"):
Line 109: Line 109:
 We have also not yet tested whether there is a difference between levels ''some'' and ''high'' of this factor. One could change the reference level of the ''weeks'' factor and refit the model to obtain this test. Alternatively, and more elegantly, we can just test the difference between these two coefficients directly. We can do this with: We have also not yet tested whether there is a difference between levels ''some'' and ''high'' of this factor. One could change the reference level of the ''weeks'' factor and refit the model to obtain this test. Alternatively, and more elegantly, we can just test the difference between these two coefficients directly. We can do this with:
 <code rsplus> <code rsplus>
-anova(res.a1, L=c(0,1,-1,0))+anova(res.a1, X=c(0,1,-1,0))
 </code> </code>
 <code output> <code output>
Line 172: Line 172:
 </code> </code>
 <code output> <code output>
-     pred     se   ci.lb  ci.ub   cr.lb  cr.ub+     pred     se   ci.lb  ci.ub   pi.lb  pi.ub
 1  0.4020 0.1300  0.1472 0.6567  0.0839 0.7200 1  0.4020 0.1300  0.1472 0.6567  0.0839 0.7200
 2  0.1127 0.0804 -0.0448 0.2702 -0.1345 0.3599 2  0.1127 0.0804 -0.0448 0.2702 -0.1345 0.3599
Line 182: Line 182:
 </code> </code>
 <code output> <code output>
-     pred     se   ci.lb  ci.ub   cr.lb  cr.ub+     pred     se   ci.lb  ci.ub   pi.lb  pi.ub
 1  0.3509 0.1297  0.0966 0.6051  0.0332 0.6685 1  0.3509 0.1297  0.0966 0.6051  0.0332 0.6685
 2  0.0616 0.0735 -0.0824 0.2056 -0.1772 0.3004 2  0.0616 0.0735 -0.0824 0.2056 -0.1772 0.3004
 3 -0.0913 0.0857 -0.2592 0.0767 -0.3452 0.1627 3 -0.0913 0.0857 -0.2592 0.0767 -0.3452 0.1627
 </code> </code>
-Note that, by default, the intercept is automatically included in the calculation of these predicted values (so only a vector of length 3 or a matrix with 3 columns should be specified via the ''newmods'' argument). The values under ''ci.lb'' and ''ci.ub'' are the bounds of the 95% confidence intervals, while the values under ''cr.lb'' and ''cr.ub'' are the bounds of the 95% credibility/prediction intervals (see ''help(predict.rma)'' for more details).+Note that, by default, the intercept is automatically included in the calculation of these predicted values (so only a vector of length 3 or a matrix with 3 columns should be specified via the ''newmods'' argument). The values under ''ci.lb'' and ''ci.ub'' are the bounds of the 95% confidence intervals, while the values under ''pi.lb'' and ''pi.ub'' are the bounds of the 95% prediction intervals (see ''help(predict.rma)'' for more details).
  
 We can use an alternative model specification, where we leave out the model intercept: We can use an alternative model specification, where we leave out the model intercept:
Line 300: Line 300:
 </code> </code>
 <code output> <code output>
-     pred     se   ci.lb  ci.ub   cr.lb  cr.ub+     pred     se   ci.lb  ci.ub   pi.lb  pi.ub
 1 -0.1074 0.1134 -0.3296 0.1148 -0.4751 0.2602 1 -0.1074 0.1134 -0.3296 0.1148 -0.4751 0.2602
 </code> </code>
Line 339: Line 339:
 Now, the table with the model results directly provides the estimated average effect for each factor level combination. It is now also quite easy to test particular factor level combinations against each other. For example, to test the difference between levels ''some'' and ''high'' of the ''weeks'' factor within the ''blind'' level of the ''tester'' factor, we could use: Now, the table with the model results directly provides the estimated average effect for each factor level combination. It is now also quite easy to test particular factor level combinations against each other. For example, to test the difference between levels ''some'' and ''high'' of the ''weeks'' factor within the ''blind'' level of the ''tester'' factor, we could use:
 <code rsplus> <code rsplus>
-anova(res.i2, L=c(0,1,-1,0,0,0))+anova(res.i2, X=c(0,1,-1,0,0,0))
 </code> </code>
 <code output> <code output>
Line 365: Line 365:
 To test the same contrast within the ''aware'' level of the ''tester'' factor, we would use: To test the same contrast within the ''aware'' level of the ''tester'' factor, we would use:
 <code rsplus> <code rsplus>
-anova(res.i2, L=c(0,0,0,0,1,-1))+anova(res.i2, X=c(0,0,0,0,1,-1))
 </code> </code>
 <code output> <code output>
tips/multiple_factors_interactions.1544275371.txt.gz ยท Last modified: 2018/12/08 13:22 by 127.0.0.1