I have two time periods of interest and four observation points(0 months, 4 months, 12 months, 16 months) for my subjects. The first time period of interest is between observation 1 and observation 3. The second time period of interest is between observation 3 and observation 4.
I would like to run an HLM to account for the correlation of observations on the same subject. I have pasted some sample data and also my code and output are below.
When I compare the model output to actual means they are very similar in this case. However, when I use my actual data set they are less similar. What does this imply? Can you tell me if I have coded time appropriately? My goal is to compare the effect of treatment during time period 1 to the effect of treatment during time period 2. Thank You!
library(nlme)
#Run Model and Get Output
model=lme(Response~Time1*Treatment+Time2*Treatment,
random=~Time1+Time2|Subject,data=test,control=list(opt="optim"))
round(summary(model)$tTable,dig=3)
# Output
Value Std.Error DF t-value p-value
(Intercept) 172.357 2.390 41 72.110 0.000
Time1 0.464 0.062 41 7.496 0.000
Treatment -10.786 3.499 13 -3.083 0.009
Time2 -0.795 0.130 41 -6.113 0.000
Time1:Treatment -0.089 0.091 41 -0.985 0.331
Treatment:Time2 0.563 0.190 41 2.956 0.005
# Means by Treatment and Time vs. Model
mean(test$Response[test$Treatment==1 & test$Observation==1])
[1] 161.1429
#model
172.357-10.786
[1] 161.571
mean(test$Response[test$Treatment==0 & test$Observation==1])
[1] 171.75
#model
[1] 172.357
Sample Data Used for this Output:
Subject Treatment Observation Time Time2 Response
1 0 1 0 0 170
1 0 2 4 0 175
1 0 3 12 0 177
1 0 4 12 4 173
2 1 1 0 0 160
2 1 2 4 0 162
2 1 3 12 0 165
2 1 4 12 4 165
3 0 1 0 0 172
3 0 2 4 0 177
3 0 3 12 0 180
3 0 4 12 4 175
4 1 1 0 0 162
4 1 2 4 0 166
4 1 3 12 0 168
4 1 4 12 4 167
5 1 1 0 0 163
5 1 2 4 0 167
5 1 3 12 0 169
5 1 4 12 4 167
6 0 1 0 0 179
6 0 2 4 0 182
6 0 3 12 0 184
6 0 4 12 4 180
7 0 1 0 0 155
7 0 2 4 0 158
7 0 3 12 0 160
7 0 4 12 4 157
8 1 1 0 0 152
8 1 2 4 0 155
8 1 3 12 0 157
8 1 4 12 4 157
9 0 1 0 0 170
9 0 2 4 0 174
9 0 3 12 0 179
9 0 4 12 4 177
10 1 1 0 0 162
10 1 2 4 0 164
10 1 3 12 0 165
10 1 4 12 4 165
11 1 1 0 0 164
11 1 2 4 0 165
11 1 3 12 0 168
11 1 4 12 4 167
12 0 1 0 0 174
12 0 2 4 0 175
12 0 3 12 0 176
12 0 4 12 4 175
13 0 1 0 0 184
13 0 2 4 0 185
13 0 3 12 0 186
13 0 4 12 4 184
14 1 1 0 0 165
14 1 2 4 0 167
14 1 3 12 0 169
14 1 4 12 4 168
15 0 1 0 0 170
15 0 2 4 0 175
15 0 3 12 0 179
15 0 4 12 4 177
Thanks.