[R-sig-ME] augPred in lmer

Douglas Bates bates at stat.wisc.edu
Tue Mar 20 01:24:19 CET 2007


Thanks for sending the example, Kyle.

On 3/19/07, Roberts, J. Kyle <jkrobert at bcm.tmc.edu> wrote:
> Below is a discussion that was on R-help that Doug moved here.  Here's my code that Doug requested:
> set.seed(100)
>
> myRands2 <- lapply((lapply(rep(10, 30), rnorm, n=30, mean=50)), sort)
>
> myIV2 <- lapply((lapply(seq(1, 10, length = 30), rnorm, n = 30, mean = 50)), sort)
>
> depend2 <-data.frame(index=rep(1:length(myRands2), each=30), dv = unlist(myRands2), iv = unlist(myIV2))
>
>
>
> dep2.lme2<-lmer(dv ~ iv + (iv|index), depend2)
>
>
>
> ### Here's the part I want, but can't produce.  lme would produce this in S-Plus as 30 separate fitted lines (for 30 groups)
>
> ### based on the "dv" and "iv"
>
> plot(augPred(dep2.lme))

One possible way to get a similar plot is to use the with()
construction on the fitted model.  I enclose some code to plot the
per-subject fits along with the mixed-model fits for the sleepstudy
data.

The technique being used is to extract the per-group coefficients and
within the panel function determine which group is being plotted and
hence what coefficients should be used in the plot.

This could definitely be done more cleanly.  The problem I have when
trying to design functions like this is to be able to define the
method for cases with non-nested random effects.


>
>
>
> Thanks for the help,
>
> Kyle
>
>
> > Hi Kyle,
> >
> > not yet!  At least not as far as I know.
>
> Not as far as I know either.
>
> > On Thu, Mar 08, 2007 at 03:08:19PM -0600, Roberts, J. Kyle wrote:
> > > I read the posts about augPred with lme, but does anyone know if there is a correlate for augPred for lmer?  Specifically, I want to be able to use it to plot projections for all groups in an lmer class object using plot(augPred(lmer.object)).
>
> Can you give us a bit more detail on the model that you have fit?  It
> may be possible to get the plot that you want without having to build
> all the infrastructure that Jose and I built in lme.  Deepayan has
> quietly added so many wonderful capabilities to lattice relative to
> earlier versions of trellis that a more direct approach often works.
>
> Also, I think we should move the discussion to the R-sig-mixed-models
> mailing list, which I am cc:ing on this reply.
>
>
> ***************************************
> J. Kyle Roberts, Ph.D.
> Baylor College of Medicine
> Center for Educational Outreach
> One Baylor Plaza, MS:  BCM411
> Houston, TX   77030-3411
> 713-798-6672 - 713-798-8201 Fax
> jkrobert at bcm.edu
> ***************************************
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
-------------- next part --------------
fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
with(fm1, {
    cc <- coef(.)$Subject
    xyplot(Reaction ~ Days | Subject, 
                 index.cond = function(x, y) coef(lm(y ~ x))[1],
                 panel = function(x, y, groups, subscripts, ...) {
                     panel.grid(h = -1, v = -1)
                     panel.points(x, y, ...)
                     subj <- as.character(Subject[subscripts][1])
                     panel.abline(cc[subj,1], cc[subj, 2])
                     panel.lmline(x, y, ...)
                 })
})


More information about the R-sig-mixed-models mailing list