0

I recently have been learning how to do mixed models in R (new to both) after being directed to them as a preferred way to analyze my data (originally 2-way repeated measures ANOVA). The study involves EEG recordings of subjects over a period of 6 hours (with a value for each hour) under three different conditions. Each subject participates in each condition.

The model I have looks like this, which I believe is suitable.

lmer(EEG ~ Condition + Hour + (1|Subject) 

Now after reading up I know you can obtain post hoc test using lsmeans like this:

lsmeans(model1, pairwise ~ Condition, adjust=”tukey”) 

However, this output only shows the post hoc test between Condition A-B, A-C, B-C. With stats software (with two way repeated measures ANOVA anyway) I am able to get the difference by hour like below.

Condition A, Hr 1 – Condition B, Hr 1

Condition A, Hr 1 - Condition C, Hr 1

Condition B, Hr 1 - Condition C, Hr 1

Condition A, Hr 2 – Condition B, Hr 2

Condition A, Hr 2 - Condition C, Hr 2

Condition B, Hr 2 - Condition C, Hr 2

....etc.

I was wondering how I would do the same in R with mixed models. Or if there is some preferred alternative that provides the same info by hour as is classically reported. Thank you for your help in advance.

Update:

I am using lmer from the lme4 package and lsmeans from lsmeans package.

Here is a sample structure of my dataframe (there is actually 3 conditions, 6 hours):

Subject Condition Hour EEG
1       A         1    X
1       A         2    X
2       A         1    X
2       A         2    x
1       B         1    x 
1       B         2    x
2       B         1    x
2       B         2    X

I tried (which I previously neglected to mention) lsmeans(model, pairwise ~ Condition | Hour):

But I get 3.5 Hr instead of by hour:

$contrasts
Hour = 3.5:
 contrast   estimate       SE df z.ratio p.value
 A - B     0.8042939 3.848262 NA   0.209  0.9762
 A - C    -5.3425872 3.848262 NA  -1.388  0.3470
 B - C    -6.1468811 3.848262 NA  -1.597  0.2468
Jack
  • 1
  • 2
  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data that can be used for testing. Explicitly list any non-base packages that you are using. – MrFlick Oct 16 '17 at 19:02
  • Use `pairwise ~ Condition | Hr`. It often helps to read the documentation ... – Russ Lenth Oct 16 '17 at 22:12
  • I guess `Hr` is numeric. I see two issues here. 1. If you mean to model `Hr` as numeric, then what’s wrong with comparing `Condition` at the average `Hr`? 2. If You meant `Hr` to be a factor, then your model s wrong. – Russ Lenth Oct 17 '17 at 04:20
  • Ok, maybe 3 issues. 3. Your model does not include an interaction between `Condition` and `Hr`. This implies that the comparisons among conditions will be identical regardless of `Hr`. You can use an `at` spec in the call (see documentation) to give a list of `Hr` values you want. But as I say it won’t make any difference. – Russ Lenth Oct 17 '17 at 04:24

0 Answers0