Dear Ben and others,

Thanks for your advice (and pointing out my mistakes). I made the fatal
error of writing my question in a bit of a hurry and grabbed the wrong
residual formula (no excuse I know). Also, thanks for pointing out that my
group level variation is zero as I hadn't included any group level variation
in my simulated data. I knew this was the case, but couldn't figure out how
to generate this for my toy example.

To be honest, I am having trouble validating this kind of GLMM as plots of
the residuals are not really that informative. I like the idea of plotting
the average of the binned residuals as suggested in the excellent (if a bit
tome-like) book by Gelman and Hill, but unfortunately I dont really have
enough observations for this to be informative either. Does anyone else have
any suggestions/opinions/strategies?

Thanks also for the advice regarding the fitted values, however I must admit
that I didn't quite follow it (entirely down to my own inadequacies). I have
had a trawl throught the archives and have noticed that the subject of
predicted values (and se) from GLMMs has come up quite a lot but with no
real resolution. I know this is asking alot from people who already kindly
invest time on this list, but would anyone be willing to put together a
worked example on this (perhaps along the lines of the  type of model
suggested in this thread). I know I (and possibly others?) would find this
really helpful and would perhaps save time in the future as people could be
directed to it.

Anyway, just a thought (possibly a bad one).
Martin

On 16 March 2010 00:59, Ben Bolker <bolker@ufl.edu> wrote:

> martin highfield <mhighfield106@...> writes:
>
> >
> > Dear all
> >
> > I am trying to validate a GLMM using plots of residuals versus fitted
> values
> > and other explanatory variables. However, I am unsure what type of
> residuals
> > (or fitted values) are returned when using the residuals function on a
> lmer
> > object. My data and model are similar to the example given below  where I
> > have a binary response variable (y) , a continous explanatory (day) ,a
> two
> > level nominal explanatory variable (treat) and a random effect of group (
> 5
> > groups).
> >
> > set.seed(100)
> > y <- rbinom(n=100, size=1, prob=0.5)
> > day <- sample(1:10, 100, replace=T)
> > group <- rep(paste("group", 1:5, sep=""), times=20)
> > treat <- sample(c("T1", "T2"), 100, replace=T)
> >
> > dataf <- data.frame(y,day,treat, group)
> > library(lme4)
> > mod.lmer <- lmer(y~day+treat+(1|group), family=binomial, data=dataf)
> > summary(mod.lmer)
> >
> > I can extract the residuals and fitted values using the residuals and
> fitted
> > extractor functions and plot them.
> >
> > res <- residuals(mod.lmer)
> > fit <- fitted(mod.lmer)
> >
> > plot(fit,res)
> > abline(h=0)
> > plot(res~dataf$treat)
> > plot(res~dataf$day)
> >
> > However, what do these residuals represent? Are they simply the observed
> > minus the fitted values, Pearsons residuals (y_i - mu_i /sqrt(mu_i)),
> > deviance residuals etc?
>
>   You can convince yourself that they're the Pearson residuals
> (which are NOT what you've quoted here -- you've quoted the Pearson
> residuals for the Poisson case [and I think you're missing parentheses?])
>
> head(res)
> head(y-fit)  ## not the same as res
> est.sd <- sqrt(fit*(1-fit))
> head((y-fit)/est.sd)   ## the same as res
>
>
> > Also, I would like to extract both the residuals
> > conditional on the random effect and also the residuals based on both the
> > fixed and random effects but am unsure how to do this. Any
> > advice/clarification would be gratefully appreciated.
>
>   fitted() gives you the unconditional (fixed+random) estimates.
>
>  Don't have time to work it out now, but you can construct your
> own fixed- and random-effect predictions by constructing the appropriate
> model matrices and multiplying by the random effects (ranef())
> and fixed effect parameter (fixef()) vectors ...
>
>  By the way, since you didn't add any group-level variation
> to your example above, all the random effects are zero ...
>
> _______________________________________________
> R-sig-mixed-models@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

	[[alternative HTML version deleted]]


