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.