Skip to content
Prev 2440 / 5636 Next

[R-meta] "Categorical" moderator varying within and between studies

Hi James,

I keep coming back to our informative discussion in this thread. So a quick
follow-up. Last time, we did the following to obtain the contextual effect
for males. Given this model (i.e., mg_b_w), can we obtain the contextual
effect for females OR we need to fit a new model, this time with males as
the reference group?

Thank you, Simon

library(dplyr)
library(fastDummies)
library(lme4)

hsb <- read.csv("
https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv")

hsb2 <- hsb %>%
  mutate(gender = ifelse(female==0,"M","F")) %>%         # create 'gender'
from variable ?female?
  dummy_columns(select_columns = "gender") %>%           # create dummies
for 'gender? (creates 2 but we need 1)
  group_by(sch.id) %>%                                   # group by cluster
id 'sch.id'
  mutate(across(starts_with("gender_"), list(wthn = ~ . - mean(.), btw = ~
mean(.))))

mg_b_w <- lmer(math ~ gender_M_wthn + gender_M_btw + (1|sch.id), data =
hsb2)

fixef(mg_b_w)[["gender_M_btw"]] - fixef(mg_b_w)[["gender_M_wthn"]]  # gives
1.92 as the contextual effect for males
On Thu, Oct 29, 2020 at 2:09 PM James Pustejovsky <jepusto at gmail.com> wrote:

            

  
  
Message-ID: <CACgv6yW+L95PsMByJyqF0qxhR75XZtPFcP6Ship9i=yw_D8iPA-6137@mail.gmail.com>
In-Reply-To: <CAFUVuJxdXLPnO43kMasCLEvNvuRZiC2EgO8-dzhJAGXVFsQLLg@mail.gmail.com>