[R-sig-ME] [Lme4-authors] Applying 'predict' to glmer model object?

lme4 maintainer bbolker at gmail.com
Sun Jan 26 17:44:49 CET 2014


On 14-01-26 08:10 AM, Jay Ulfelder wrote:
> Hi, folks:
> 
> Thanks so much for putting together a great package.
> 


 [I'm cc'ing back to r-sig-mixed-models because I think that's a more
appropriate place ...]

> I'm trying to estimate a logistic regression model with random
> intercepts for countries from country-year TSCS data and then use that
> model to generate out-of-sample predictions. I'm having no trouble with
> the first step but can't seem to do the second. Here's what I'm seeing in R:
> 

  A reproducible example <http://tinyurl.com/reproducible-000> would be
nice -- so would the results of sessionInfo() -- but we'll see what we
can do.

>> glmer.f <- formula(cou.a.d.1 ~ colbrit + colfrnc + colespn + postcw +
> ageln + xxxcimrln + 
> +   cou.tries5d + world.ln + region.ln + slowgrowth + polcat2 + polcat3
> + polcat7 + durableln + 
> +   elcelethc + nld.any.1 + civconc + ( 1 | country) )
> 
>> glmer.mod <- glmer(glmer.f, family = binomial, data = train, na.action
> = na.exclude)
> 
>> test$glmer.p <- predict(glmer.mod, newdata = test, type = "response",
> na.action = na.exclude)
> Error in UseMethod("predict") : 
>   no applicable method for 'predict' applied to an object of class "mer"
> 
> Can you please tell me what I'm missing?

  It's hard to know exactly.  It seems as though you might be using an
older version of lme4 (for which the predict() method isn't implemented,
because older (pre-1.0) versions of lme4 produce objects of class 'mer';
newer versions produce 'merMod' objects.

  Ben Bolker



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