[R-meta] metafor: Interaction between a factor and a continous variable

Viechtbauer, Wolfgang (SP) wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Thu Jan 7 10:53:41 CET 2021

Dear Ute,

Please see my responses below.


>-----Original Message-----
>From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces using r-project.org]
>On Behalf Of Kraus, Ute, Dr.
>Sent: Tuesday, 05 January, 2021 10:56
>To: r-sig-meta-analysis using r-project.org
>Subject: [R-meta] metafor: Interaction between a factor and a continous
>Dear everybody!
>This is my very first post and I would appreciate it very much if somebody
>has time enough and could help me.
>I am currently working on a meta-analysis on sex differences in the
>association between air pollutants and cardiovascular mortality. I
>calculated a mixed effects model including an interaction of a factor (sex)
>and a continuous variable (publication year). However, I find it difficult
>to interpret the estimates, and I get stuck when I want to graph the
>Here are the code and the results. The continuous variable “publication
>year” is called “moderator” in my program.

Just as a sidenote: It is better to post code/output as text and not as an inline image.

>Question 1: Are my following interpretations correct?
>The Test of moderators shows that main effects and interaction term has no
>significant effect (p-value 0.3482), explaining no heterogeneity between
>studies (R2=0%).
>The interaction between sex and publication year is not significant


>Meaning of model results:
>Intercept → estimate for men, when moderator (=publication year) = 0


>Moderator → estimate for moderator (=publication year); with each 1 year
>that an article is published later, the average estimate for the association
>between air pollution and cardiovascular mortality increases by 0.0001 (not

Correct, but to be precise, the coefficient is the one for men.

>Factor(sex)women → estimate indicates the effect of women compared to men;
>women have a 0.2127 lower average mortality risk related to air pollutants
>than men (not significant)

Assuming that this is what 'beta' reflects, this is also correct.

>Moderator:factor(sex)women → estimate indicate by how much the risk in women
>increases with each increase of one year of publication compared to men
>(0.0001 greater increase than men; not significant).


>Question 2: How can I present the results graphically?
>I would need an intercept and a slope for each sex group showing the change
>in the average mortality risk by a 1-year increase in publication year. I
>would calculate it from the model results:
>Intercept men: -0.1013 (estimate intrcpt)
>Slope men: 0.0001 (estimate moderator)
>Intercept women: -0.1013 – 0.2127 (estimate intrcpt + estimate
>Slope women: 0.0001+0.0001 (estimate moderator + estimate

This is all correct.

>However, I am not really convinced that this is correct. And I think there
>is a more elegant and easier way, isn’t there? 

You can use predict() and anova() to also obtain these results:

predict(df, newmods = c(0,0,0))
predict(df, newmods = c(0,1,0))
predict(df, newmods = c(1,0,0), intercept=FALSE)
predict(df, newmods = c(1,0,1), intercept=FALSE)

anova(df, L=c(1,0,0,0))
anova(df, L=c(1,0,1,0))
anova(df, L=c(0,1,0,0))
anova(df, L=c(0,1,0,1))

Sidenote: This shows a bit of an inconsistency in how predict() and anova() works in metafor. For the former, the intercept is included in the linear combination by default (if the model actually has an intercept term) and its inclusion/exclusion is not controlled via the 'newmods' argument but by the 'intercept' argument, while in anova() one needs to specify a linear combination that also pertains to the intercept term.

>I think it does not make
>sense to calculate a model without intercept (mods=~moderator:factor(sex)-
>1), which would give me the slopes, I guess, but then I have just a slope
>but no intercept.

There is also a way to specify the model such that it gives the intercept and slope for both groups directly. Use:

mods = ~ factor(sex) + factor(sex):moderator - 1

>Thank you very much for your help in advance!
>Helmholtz Zentrum München
>Helmholtz Zentrum München
>Deutsches Forschungszentrum für Gesundheit und Umwelt (GmbH)
>Ingolstädter Landstr. 1
>85764 Neuherberg
>Aufsichtsratsvorsitzende: MinDir.in Prof. Dr. Veronika von Messling
>Geschäftsführung: Prof. Dr. med. Dr. h.c. Matthias Tschöp, Kerstin Günther
>Registergericht: Amtsgericht München HRB 6466
>USt-IdNr: DE 129521671

More information about the R-sig-meta-analysis mailing list