I have a dataset with the following variables, which are measured between subjects (i.e. 1 measurement per individual):
ID
: subject identifierage
: subject ageactivity
: overall activity level of that individual
Each individual completes 2 computer tasks (one easy, one hard) and reaction time (RT) was measured for each. So I have the following variables measured within subjects (repeated measures):
difficulty
: task difficultyRT
: reaction time on the task
My data looks something like this:
df <- data.frame("ID" = c(1,1,2,2,3,3,4,4),
"age" = c(20,20,25,25,19,19,21,21),
"activity" = c(55,55,72,72,83,83,67,67),
"difficulty" = c(0,1,0,1,0,1,0,1),
"RT" = c(110,250,90,100,99,132,122,134))
df$difficulty <- factor(df$difficulty)
ID age activity difficulty RT
1 1 20 55 0 110
2 1 20 55 1 250
3 2 25 72 0 90
4 2 25 72 1 100
5 3 19 83 0 99
6 3 19 83 1 132
7 4 21 67 0 122
8 4 21 67 1 134
I'm expecting to see an interaction such that the slope between activity
and RT
will be different for each level of difficulty
factor (while controlling for age
). I have tried the following model in R:
lm(RT ~ activity*difficulty + age, data=df)
My concern here is the repeated nature of some of my variables. As you can see from my sample data there are twice as many rows as there should be. The values for my between subject variables are doubled and each participant was measured twice, which will affect my degrees of freedom, and thus my p values.
Is this a valid concern when testing regression interactions involving within subject variables?
Is there a more appropriate way to test this and what would it look like in R?