# [R-meta] Effect coding in metafor

Viechtbauer Wolfgang (SP) wolfgang.viechtbauer at maastrichtuniversity.nl
Thu Mar 1 18:35:16 CET 2018

```If you think effect coding gives you what you need, then use that. I guess you are thinking of contr.sum. Just set:

constrast(dat\$factor) <- contr.sum

For a factor with two levels, this is the same as

constrast(dat\$factor) <- c(1,-1)

In your original post you said that this 'did not work', but it does for me:

dat <- get(data(dat.bcg))
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
dat\$random <- factor(ifelse(dat\$alloc == "random", 1, 0))
res <- rma(yi, vi, mods = ~ random, data=dat)
res
model.matrix(res)
contrasts(dat\$random) <- contr.sum
res <- rma(yi, vi, mods = ~ random, data=dat)
res
model.matrix(res)

Best,
Wolfgang

>-----Original Message-----
>From: Yogev Kivity [mailto:yogev_k at yahoo.com]
>Sent: Thursday, 01 March, 2018 3:56
>To: r-sig-meta-analysis at r-project.org; Viechtbauer Wolfgang (SP)
>Subject: Re: RE: RE: RE: [R-meta] Effect coding in metafor
>
>Well, I see your point, but the main effect may still be informative,
>especially if the interaction is not a cross-over interaction. I guess I
>am thinking of it from an ANOVA-like perspective - I would first like to
>examine the main effects and interaction, and then proceed with follow-up
>analyses (i.e., simple effects and contrasts).
>
>For example (a 2*2 design), in our meta-analysis we are examining whether
>the capacity to mentalize (to think about the mental states that underlie
>one's and others' behaviors) predicts various outcomes (usually in a
>Pearson's r metric). More specifically, we want to examine implicit and
>explicit measures of mentalizing as well as implicit and explicit
>measures of outcome. We are interested in both the main effects (whether
>implicit measures of mentalizing are better predictors of outcome than
>explicit measures; whether explicit measures of outcome are better
>predicted by mentlizing then implicit measures of outcome) as well as the
>interaction (if the advantage of implicit measurement of mentlizing is
>larger for implicit measures of outcome than for explicit measures of
>outcome). Thus, I was thinking that effect coding might me more
>appropriate than dummy coding for the first step of our analyses.
>
>Best,
>Yogev
>
>--
>Yogev Kivity, Ph.D.
>Postdoctoral Fellow
>Department of Psychology
>The Pennsylvania State University
>Bruce V. Moore Building
>University Park, PA 16802
>Office Phone: (814) 867-2330
>
>On Wednesday, February 28, 2018, 4:33:18 PM EST, Viechtbauer Wolfgang
>(SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:
>
>How is the main effect of relevance when there is an interaction?
>
>But ok, leaving this aside, yes, the coefficient for 'testeraware' in
>model 'res.i1' is indeed the simple effect of the 'tester' factor for
>level 'none' of the 'weeks' factor.
>
>So you want something different. Can you describe in words what this main
>effect you are looking for is supposed to reflect?
>
>Best,
>Wolfgang
>
>>-----Original Message-----
>>From: Yogev Kivity [mailto:yogev_k at yahoo.com]
>>Sent: Wednesday, 28 February, 2018 22:14
>>To: r-sig-meta-analysis at r-project.org; Viechtbauer Wolfgang (SP)
>>Subject: Re: RE: RE: [R-meta] Effect coding in metafor
>
>>
>>Thanks!
>>
>>Sorry - I guess I should have given an example from a model with an
>>interaction.
>>
>>And what if there is an interaction (model 'res.i1') and I am interested
>>in the main effect? would I then need to change the coding?
>>
>>Best,
>>Yogev
>>
>>--
>>Yogev Kivity, Ph.D.
>>Postdoctoral Fellow
>>Department of Psychology
>>The Pennsylvania State University
>>Bruce V. Moore Building
>>University Park, PA 16802
>>Office Phone: (814) 867-2330
>>
>>On Wednesday, February 28, 2018, 3:21:39 PM EST, Viechtbauer Wolfgang
>>(SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:
>>
>>Yes, b3 = -.0511 is the main effect of the 'tester' factor. Since there
>>is no interaction, the effect is the same for all three levels of the
>>'weeks' factor, so it is not just the simple effect for the 'none'
>level,
>>but also for the 'some' and 'high' levels. Look at the line plot again -
>-
>>it does not matter at which level of 'weeks' you look, the b3 = -.0511
>>effect is always the same.
>>
>>Best,
>>Wolfgang
>>
>>>-----Original Message-----
>>>From: Yogev Kivity [mailto:yogev_k at yahoo.com]
>>>Sent: Wednesday, 28 February, 2018 18:08
>>>To: r-sig-meta-analysis at r-project.org; Viechtbauer Wolfgang (SP)
>>>Subject: Re: RE: [R-meta] Effect coding in metafor
>>>
>>>Dear Wolfgang,
>>>
>>>However, I am still a bit confused about how to obtain estimates of a
>>>main effect. In model ‘res.a1’ in the example in the link, would you
>>>interpret the estimate of the ‘testeraware’ coefficient (b3 = -.0511)
>as
>>>a test of the main effect of the ‘tester’ factor? Given that the
>‘weeks’
>>>factor is dummy coded, I thought that ‘testeraware’ represents the
>>simple
>>>effect of ‘tester’ within the ‘none’ level. If the latter is correct,
>>>than I am looking for a way to test for a main effect (in this example,
>>>the effect of ‘tester’ across the levels of ‘weeks’).
>>>
>>>Best,
>>>Yogev
>>>
>>>--
>>>Yogev Kivity, Ph.D.
>>>Postdoctoral Fellow
>>>Department of Psychology
>>>The Pennsylvania State University
>>>Bruce V. Moore Building
>>>University Park, PA 16802
>>>Office Phone: (814) 867-2330
>>>
>>>On Monday, February 26, 2018, 9:08:23 AM EST, Viechtbauer Wolfgang (SP)
>>><wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:
>>>
>>>Dear Yogev,
>>>
>>>Here is an extensive discussion of an example with 2 categorical
>>>moderators and it happens to be the case that it also involves one
>>>dichotomous and one 3 level factor:
>>>
>>>http://www.metafor-
>>>project.org/doku.php/tips:multiple_factors_interactions
>>>
>>>I don't see why you need to change the coding.
>>>
>>>Best,
>>>Wolfgang
>>>
>>>>-----Original Message-----
>>>>From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces at r-
>>>>project.org] On Behalf Of Yogev Kivity
>>>>Sent: Monday, 26 February, 2018 4:38
>>>>To: r-sig-meta-analysis at r-project.org
>>>>Subject: [R-meta] Effect coding in metafor
>>>
>>>>
>>>>Hi all,
>>>>I am running a meta-analysis with 2 categorical moderators, one is
>>>>dichotomous and the other has 3 levels (e.g. x1 and x2). For example:
>>>>rma.mv(yi, V, mods=~factor(x1)*factor(x2), random = ~ 1 |
>>>>StudyID/GroupID/EffectSizeID, data=DataF)
>>>>(the specifics of the design of the meta-analysis seemed irrelevant to
>>>>me, but if I am mistaken, I am happy to provide further details)
>>>>As a first step, I am interested in the main effects of both
>moderators
>>>>as well as the interaction effect. Therefore, to my understanding, I
>>>need
>>>>both moderators to be set as effect coding factors, rather then dummy
>>>>coding factors. However, I could not figure out a way to do it in
>>>>metafor. For example, setting the following contrasts did not work,
>and
>>>>essentially the output remained identical to that of the dummy
>>variables
>>>>(i.e., each estimate expresses the simple effect of the moderator
>>within
>>>>the reference category of the other moderator):
>>>>contrasts(Data\$x1)<-c(-.5,.5)
>>>>
>>>>Obviously, I can get around the problem by creating multiple numeric
>>>>variables with weights that correspond to the desired effect coding,
>>but
>>>>I was wondering whether I am missing something and whether there is a
>>>>more elegant way of doing it.
>>>>Best,Yogev
>>>>--
>>>>
>>>>Yogev Kivity, Ph.D.
>>>>Postdoctoral Fellow
>>>>Department of Psychology
>>>>The Pennsylvania State University
>>>>Bruce V. Moore Building
>>>>University Park, PA 16802
>>>>Office Phone: (814) 867-2330
```