# Help with setup of a hierarchical linear model (lmer) in R, selection of fixed and random effects

I have calculated a particular parameter y in each subject our of 3 studies (each 15-30 subjects). In study #3, the subjects have been measured twice (with 2 different treatments, M and P), and therefore I calculated this variable twice for those subjects. Subjects of the other two studies didn't get any treatment (therefore Treatment = NA), and the treatment is not important to me.

I want to predict an overall significant difference of this parameter y from zero. Therefore, I was told to use HLM/MLM because this data is hierarchical because of the 2 treatments in study #3.

So my idea is to model something like:

y ~ Study + Subject + Treatment


As far as I understood, I want to look at the intercept of the model, to know if the parameter is statistically significant different from zero. I am not interested in the effect of Treatment, or Study, however.

Which of those parameters of the model should I now treat as fixed or random effect? And do I need to mean-center some variable to be able to interpret the intercept correctly?

Any help in a direction would be highly appreciated.

Thanks so much!

Welcome to the site, roman. I would suggest filtering out the individuals who were not in study #3. Assuming that study is coded 1, 2, or 3, I would first narrow down your data to just those subjects in study 3. You can use dplyr for this:

require(dplyr)
study3 <- original.data %>% filter(study==3)


Now that you have a data frame with only study 3 participants, you can run your model. You should code your treatment variable such that one or the other treatments is 0 and the other is 1. If you coded treatment such that M==0 and P==1, and ran the following model:

require(lme4)
m <- lmer(y ~ 1 + Treatment + (1|Subject), data=study3)
summary(m)


This will give you two fixed effect coefficients, the intercept, which is the mean value of y in Treatment==0 and Treatment, the difference in the mean value of y for Treatment==1 relative to Treatment==0. You will also get a random effect estimate for Subject and the residual. Respectively, these tell you the variance in y that is between Subjects and within Subjects.

It is unclear to me why you want to know the mean of y irrespective of the treatment. However, you could get this by estimating a so-called "empty" model that ignores the effect of treatment:

emptym <- lmer(y ~ 1 + (1|Subject), data=study3)


Here the fixed intercept gives you the mean value of y, while accounting for the correlation in y that is due to repeated measures of subjects. This will be slightly different than the mean you get from mean(study3$y). Edit: Based on roman's desire to include participants from all 3 studies, one suggestion would be to recode treatment to be 0, 1, or 2, corresponding to the NA condition in studies 1 and 2, and the M and P conditions in study 3. library(dplyr) original.data <- original.data %>% replace_na(treatment=0) #change treatment=NA to treatment=0  Make sure that the treatment variable is a factor variable (original.data$treatment <- as.factor(original.data\$treatment). Then you can run your model with treatment and study as fixed effect predictors.

m1 <- lmer(y ~ treatment + study + (1|Subject), data=original.data)


If you get any weird warnings about this, it could be because treatment and study are highly collinear and you may want to just include treatment as your fixed effect covariate.

• My intention was to include subjects of all 3 studies. The subjects of study 3 became treament "M" or "P" (treatment is of no interest, but I want to account for this variance in my model). Subjects of Study 1&2 got no treatment (Treatment = "NA"). The only thing I want to now about is the parameter "y". So my idea was to include "study" (each was conducted independently), "subject" (bc. in study 3 most the subjects have been measured twice, with different treatments), and "treatment", to account for variance explained by this treatments. How could I include all these effects in one model? Feb 2, 2020 at 13:20
• I see. Updated my post to reflect this approach. Feb 2, 2020 at 15:04
• Superb ! Thanks a lot Erik. I dismissed one of the treatments, to account for that collinearity. So for the interpretation: the intercept would now be the "mean" of my parameter for group 1. If I want to have the intercept as a mean of that parameter across studies, I could kind of center the value of the "Study" (i.e. the number of the study), Am I right? Feb 2, 2020 at 19:36
• Glad that worked for you! The intercept is the mean value of the outcome when all fixed effect predictors are at 0. If your predictors do not have a meaningful 0 value, then this mean is nonsensical. In terms of Study, depending on how many studies are in the data, you could code it so that 0 represents the mean across all studies. See pagepiccinini.com/2016/03/18/… Feb 2, 2020 at 20:26
• Thanks a lot, Erik! This tutorial explains the contrasting very well! Feb 3, 2020 at 18:05