Piecewise HLM model using nlme package in R -
i have 2 time periods of interest , 4 observation points(0 months, 4 months, 12 months, 16 months) subjects. first time period of interest between observation 1 , observation 3. second time period of interest between observation 3 , observation 4.
i run hlm account correlation of observations on same subject. have pasted sample data , code , output below.
when compare model output actual means similar in case. however, when use actual data set less similar. imply? can tell me if have coded time appropriately? goal compare effect of treatment during time period 1 effect of treatment during time period 2. thank you!
library(nlme) #run model , 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 treatment , 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 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.
Comments
Post a Comment