I have longitudinal data with level 1 and level 2 variables in R my dataframe (df)
:
ID Year Gender Race MathScore DepressionScore MemoryScore
1 1999 M C 80 15 80
1 2000 M C 81 25 60
1 2001 M C 70 50 75
2 1999 F C 65 15 99
2 2000 F C 70 31 98
2 2001 F C 71 30 99
3 1999 F AA 92 10 90
3 2000 F AA 89 10 91
3 2001 F AA 85 26 80
I've tried these:
summary(fix <- lme(MathScore ~ Gender+Race+DepressionScore+MemoryScore,
random= Year|ID, data=df, na.action="na.omit")
summary(fix2 <- lme(MathScore ~ 1+Gender+Race+DepressionScore+MemoryScore,
random=~1|Year, data=df, na.action=na.omit))
I don't understand how to make DepressionScore
and MemoryScore
vary within Year
while keeping Gender
and Race
constant, particularly in fix2
. Also, I don't know if fix2
is capturing the Year
and ID
variation that is happening in my data. Is there a way to restructure it?