# How do I estimate a repeated measures ANCOVA in R and SPSS?

I'm currently running a perception experiment:

• DV: error (this in degrees- how much an observer was away from the real answer)
• IV: the time bin (5 levels) in which the unique stimulus appeared
• IV2: True/False- whether the unique stimulus occurred before or after stimulus2.
• Covariate: Distance from the fixation point this stimulus appeared (continuous)

So, I have decided to use repeated measures ANCOVA since, all the observers were exposed to all 5 levels of the IV multiple times.

Currently I have written:

data.aov <-aov(error~(timebin*after*distance) +
Error(subject/timebin*after*distance), d)
summary(data.aov)


Is this the correct way to specify my repeated measures ANCOVA in R?

Also, I wanted to run this analysis in SPSS to check that I get the same results. However, SPSS doesn't like the format of my data. For repeated measures analysis, the 5 bins should be in 5 different columns, but in my data file, they are all together under the same heading timebins.

How can I run the repeated measures ANCOVA in SPSS if my data are in long format?

Thanks everyone for great answers!

@Marcus, just one thing- regarding regression. If I were to use regression, would I be looking at trends? I am actually more interested in comparing bin 1 and bin 5. This is why I was going to use a t-test, but now it seems like I am using within-subjects anova.

Also, I've had a look at distance and (as you said) might not be a covariate, since it was randomised for every condition!

Then the codes should look like this?

data.aov <-aov(error~(timebin*after) + Error(subject/timebin*after), d)
summary(data.aov)


But what is the difference between using * and using + ? Should I use * to get an interaction effect?

-
@Q2: You can change your data to wide format easily using R. Look for package reshape2 or look here. –  Roland Aug 31 '12 at 9:22
Or similarly if you read your data in the same format into SPSS you can utilize the CASESTOVARS command to reshape the data into wide format. Also I believe the same models can be fit with the MIXED command, which requires the data in long format. –  Andy W Aug 31 '12 at 12:57
Is there some reason to prefer binning your time variable? You would use fewer degrees of freedom and consequently get more power if you treated it as a continuous variable using regression. Also, I think, conceptually, your distance is not a covariate per se. It would make more sense in a regression context where you can ask, what is the effect of distance and how does it interact with error? –  Marcus Morrisey Aug 31 '12 at 14:09
add comment