[R] beginner's questions about lme, fixed and random effects

rdiaz@inner.es rdiaz at inner.es
Mon Dec 3 16:27:40 CET 2001


Jonathan,

I don't think it makes a lof ot sense to try to use lme for a two-sample
t-test, since there is no random effect there. Maybe a comparison more in line
with what you were trying to do is to compare the results from lme with those
from a split-plot anova. Here is a silly example (where the value of the.data
is the sum of the treatment effects, the subject effects, and "an.error"):


## Silly example
subject.effects <- rep(seq(1:5),rep(2,5))
subjects.ids <- as.factor(rep(c("a","b","c","d","e"),rep(2,5)))
treatment.effects <- rep(c(0,4), 5)
treatment.ids <- as.factor(rep(c("trt1", "trt2"), 5))
an.error <- c(1,2,0,1,3,2,0,1,2,0)
the.data <- subject.effects + treatment.effects + an.error

summary(aov(the.data ~ Error(subjects.ids) + treatment.ids))
summary(lme(the.data ~ treatment.ids, random = ~1|subjects.ids))

## Of course, with this setup, those tests are equivalent to a paired-t:
t.test(the.data[treatment.ids == "trt1"], the.data[treatment.ids == "trt2"],
paired=TRUE)


Ramón

Jonathan Baron <baron at cattell.psych.upenn.edu> dijo:

> I'm trying to understand better the differences between fixed and
> random effects by running very simple examples in the nlme
> package.  My first attempt was to try doing a t-test in lme.
> This is very similar to the Rail example that comes with nlme,
> but it has two groups instead of five.
> 
> So I try
> 
> a1 <- 1:10
> a2 <- 7:16
> t.test(a2,a1)
> 
> getting t(18)=4.43, p=.0003224.  Then I try to do it with lme:
> 
> a12 <- c(a1,a2)
> grp <- factor(rep(1:2,c(10,10)))
> 
> Now, at this point, I think I should be able to do something like
> this:
> lme(a12~grp)
> or
> lme(a12~1|grp)
> but I keep getting an error message, "Invalid formula for
> groups."  So I tried making a groupedData object:
> 
> data1 <- as.data.frame(cbind(a12,grp))
> gd1 <- groupedData(a12~1|grp,data=as.data.frame(cbind(a12,grp)))
> 
> Now I can do
> lme(gd1)
> or
> lme(gd1,random=1|grp)
> or many other things, but nothing seems to yield anything like
> the t test, and I'm not even sure what the fixed effect test
> (with a p of .011 with summary(lme(gd1))) is testing.  (It
> doesn't seem to be about whether the grand mean of a12 is greater
> than zero.)  I've been studying the relevant documentaion,
> including Pinheiro and Bates's book, but I'm still stumped.  I'm
> sure I'm being very dense about something very simple, like,
> "This doesn't make any sense."  But why not?
> 
> All this is leading up to a real application to a much more
> complicated problem, but I think I need to understand the simple
> stuff first.
> 
> Jon Baron
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 



-- 



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list