I'm trying to transition to R
from using SPSS
. In the past, I've setup my data in the wide format for my repeated measures ANOVAs in SPSS
. How do I need to setup my data to run nlme()
? The data is balanced. It has within-subjects variables of trial type(3 levels) each measured on 8 times, and a between-subjects factor with 2 levels. 2 separate analyses will be run; one with response time as the DV and another with accuracy as the DV. I know the data has to be in a long format but I'm not sure how the columns should be arranged. Should 1 column be the subject id, another the trial type, another the time, and then 1 for the DV? Does this matter? Any points in the right direction would be greatly appreciated. Thanks.
Solved – How to setup up repeated measures data for analysis with nlme()
datasetlme4-nlmemixed modelrrepeated measures
Best Answer
Yes, you need to set up your data so that each grouping factor, dependendent variable and covariate corresponds to a column and every row contains one observation (i.e. long format): Everything that you enter into the model formulas for the random and fixed parts has to be a column in your data set.
You can use
reshape
to get your data from wide to long format and back.If you are transitioning to R and do a lot of mixed models, try to get a copy of Pinheiro/Bates "Mixed-Effects Models in S and S-PLUS", it's a comprehensive reference from the guys who wrote
nlme
with a lot of worked examples.