0

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.

user61578
  • 1
  • 1
  • 2
    Please take the time to post a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data and runnable code. Also describe the output you are getting and why it is "obviously" not correct. – MrFlick Apr 14 '15 at 17:53
  • Are you really using the deprecated `lme` package, not `nlme`? You might try adding parens `random = ~ (TIME1 + TIME1) | Subject`. – Gregor Thomas Apr 14 '15 at 19:10
  • @Gregor I have updated my post to add more information. I will try your suggestion and see if it makes any difference. I am mostly just unsure whether I have coded time properly. Thank you. – user61578 Apr 14 '15 at 19:36
  • With your edits this sounds a lot less like a programming question and a lot more like a statistics question. If you're having trouble interpreting a mixed effects model you should post to stats.stackexchange. On that site, if your question is about how to code time, you'll need to be much more specific and explain the logic of how you did code it. Your 4th row of data is very confusing, I don't know how you have one observation with one response measure at `Time1 = 12` and `Time2 = 4` – Gregor Thomas Apr 14 '15 at 19:48
  • @Gregor They actually sent me here, haha. I have changed my question a bit though so I will try there again. I am confused as well. I want my first time period to end at 12 and my second time period to start at 12 and go for 4 months. I was thinking, for example, someone at time 16 would need 12*time1 effect + 4*time2 effect... Anyway, thank you for your help. I will try stackexchange again. – user61578 Apr 14 '15 at 20:00
  • Wait, so do you actually have a single `TIME` column that you're breaking up into these two columns? You should post a few lines of your raw data. This is still, I think, a stats question because you're asking "what should I do?", not "I know what I want, but how do I do it?". – Gregor Thomas Apr 14 '15 at 20:04
  • @Gregor Yes, there is one time column that I have separated into two because I want to look at them separately. The observation column is basically the raw time column except instead of 1,2,3,4 it would be 0,4,12,16 (months). I agree, now that I have changed my question it may be better suited to stackexchange. If you can give me a quick answer I will be very grateful. If not I will repost there. Thank you again. – user61578 Apr 14 '15 at 20:10
  • I don't have a quick answer yet, but I'll look at the question if you re-post. I will say that changing 1,2,3,4 to 0,4,12,16 is just a linear transformation, so it may help you interpret your coefficient better, but it won't change the fit of the model at all. – Gregor Thomas Apr 14 '15 at 20:59
  • I figured it out. You can just delete this if it isn't useful for anyone else. – user61578 Apr 16 '15 at 18:36

0 Answers0