2
$\begingroup$

I'm fitting a multilevel model that has a random effect nested within a fixed effect:

df <- tibble(
  id = seq(1:500)
) %>%
  mutate(treatment = rbinom(n = 500, size = 1, prob = 8/9)) 

df <- as.data.frame(lapply(df, rep, 6)) %>%
  arrange(id, treatment) %>%
  mutate(scenario = rep(seq(1:6), 500)) %>%
  mutate(magnitude_manipulation = case_when(
    treatment == 1 & scenario == 1 ~ "very_low",
    treatment == 1 & scenario == 2 ~ "mid_low",
    treatment == 1 & scenario == 3 ~ "low",
    treatment == 1 & scenario == 4 ~ "high",
    treatment == 1 & scenario == 5 ~ "mid_high",
    treatment == 1 & scenario == 6 ~ "very_high"
  ),
  magnitude_manipulation = factor(magnitude_manipulation, ordered = TRUE, levels = c("very_low", "mid_low", "low", "high", "mid_high", "very_high")),
  outcome = round(rnorm(3000, 100, 15)))

That is, magnitude_manipulation is nested in treatment - there are no levels of magnitude_manipulation when treatment is equal to 0, but 6 levels when treatment is equal to 1. What would be the appropriate way to model this data with lmer?

This is my best shot so far:

lmer(outcome ~ treatment + (1 | magnitude_manipulation) + (1 | scenario) + (1 | id), data = df)

I also have random effects for scenario and person because these are repeated factors. Any assistance would be greatly appreciated because although this topic has been addressed before, I'm not sure I'm applying it correctly.

$\endgroup$

1 Answer 1

2
$\begingroup$

This doesn't make complete sense to me.

You have created a variable based on levels of one fixed effect and a random effect and then included that as a grouping factor for random intercepts along with the other factors too.

It is not clear what your research question is, but the model that seems most appropriate to me is:

lmer(outcome ~ treatment * scenario + (1 | id), data = df)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.