My data consists of 20 subjects in a control group and 20 in an experimental group. The DV of interest is a change score of peak power measured on each participant. There is also a dummy variable xVarExp
that includes a 1 for subjects in the experimental group only. I am interested in individual responses and the variance of these numbers is the statistic summarising this. I am also interested in the means of each group; Exptal and Control.
My data is structured as follows:
structure(list(Subject = structure(1:40, .Label = c("Alex", "Ariel",
"Ashley", "Bernie", "Casey", "Chris", "Corey", "Courtney", "Devon",
"Drew", "Dylan", "Frances", "Gene", "Jaimie", "Jean", "Jesse",
"Jo", "Jody ", "Jordan", "Kelly", "Kerry", "Kim", "Kylie", "Lauren",
"Lee", "Leslie", "Lindsay", "Morgan", "Pat", "Reilly", "Robin",
"Sage", "Sam", "Sidney", "Terry", "Tristan", "Vic", "Wil", "Wynn",
"Zane"), class = "factor"), Group = structure(c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("Control", "Exptal"), class = "factor"),
xVarExp = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1), DV = c(3.3, -0.8, 2.7, 2.8, 0.6, 5.2,
1, 3.4, 1.3, -2.4, 8.5, 3.5, -1.9, 4.3, 1.2, -1.9, -0.6,
1.3, -2.6, -1, -3.7, 1.9, 4.6, 2.9, 7.2, -1.7, 4.2, 3.9,
-3.2, 9.9, 2.7, -1.7, 7.9, 8.1, 3.8, 2.8, 4.6, 0.8, 2.5,
4.1)), .Names = c("Subject", "Group", "xVarExp", "DV"), row.names = c(NA,
-40L), class = "data.frame")
The statistician is a SAS user and has used the code below to obtain sensible answers:
title "Analyzing change scores";
proc mixed data=import plots(only)=StudentPanel(conditional) alpha=0.1 nobound;
class Subject Group;
model DV=Group/residual outp=pred ;
random xVarExp/subject=Subject;
lsmeans Group/diff=control("Control") cl alpha=0.1;
run;
I am beginning to use R and lme4, whereby I believe the code is:
Model1 <- lmer(DV ~ Group + (1|Subject/xVarExp),
data = RawData)
However, I receive the following: Error: number of levels of each grouping factor must be < number of observations
I managed to get the modelling working, using the syntax below, in nlme which matches the output of SAS:
Model2 <- lme(DV ~ Group,
random = ~ 1|xVarExp/Subject, data = RawData)
My questions are: 1) Why does the model work in nlme but not lme4? and 2) How can I match the SAS syntax to get the model going in lme4?
Thank you!