[R] Random intercept model with time-dependent covariates, results different from SAS
Keith Wong
keithw at med.usyd.edu.au
Sun Jul 4 09:21:36 CEST 2004
Dear list-members
I am new to R and a statistics beginner. I really like the ease with which I can
extract and manipulate data in R, and would like to use it primarily. I've
been learning by checking analyses that have already been run in SAS.
In an experiment with Y being a response variable, and group a 2-level
between-subject factor, and time a 5-level within-subject factor. 2
time-dependent covariates are also measured (continuous variables W and Z). The
subject id variable (ID) is unique to each subject, and is not duplicated
across groups.
I tried to fit a random intercept model in R (after setting options(contrasts =
c(factor = "contr.SAS", ordered = "contr.poly")) as recommended on this list),
and making the time, group and id variables factors:
> g2 = lme(Y ~ time + group + time:group + W + Z, random = ~ 1 | id, data =
datamod)
> anova(g2)
numDF denDF F-value p-value
(Intercept) 1 42 5.54545 0.0233
time 4 42 16.41069 <.0001
group 1 11 0.83186 0.3813
W 1 42 0.07555 0.7848
Z 1 42 45.23577 <.0001
time:group 4 42 3.04313 0.0273
I compared the results using SAS proc mixed:
proc mixed data = datamod;
class id time group;
model Y = time group time*group W Z /s;
random int / sub = id;
run;
And get the following anova table for the fixed effects:
Type 3 Tests of Fixed Effects
Num Den
Effect DF DF F Value Pr > F
time 4 42 2.55 0.0534
group 1 42 0.54 0.4664
time*group 4 42 3.04 0.0273
W 1 42 8.80 0.0050
Z 1 42 32.52 <.0001
I am perplexed to see that the test for the main effect "time" is quite
different. Both models seem to be specified equivalently to me, am I doing
something wrong - particularly with the inclusion of the time-dependent
covariates W and Z? I have looked at the data in both programmes and they are
the same. There are no missing observations.
I a simpler model without the time-dependent covariates, and in this case the
results are similar:
[R]
> g1 = lme(Y ~ time + group + time:group, random = ~ 1 | id, data = datamod)
> anova(g1)
numDF denDF F-value p-value
(Intercept) 1 44 3.387117 0.0725
time 4 44 10.620547 <.0001
group 1 11 0.508092 0.4908
time:group 4 44 3.961726 0.0079
[SAS]
proc mixed data = datamod;
class id time group;
model Y = time group time*group /s;
random int / sub = id;
run;
Type 3 Tests of Fixed Effects
Num Den
Effect DF DF F Value Pr > F
time 4 44 7.75 <.0001
group 1 44 0.51 0.4797
time*group 4 44 3.96 0.0079
Secondly, is there no R equivalent of the "LSMEANS" statement in SAS? Is there a
work-around?
I would very much appreciate assistance.
Thanks. Keith
More information about the R-help
mailing list