when to use numeric_res and question about ezPlot2

179 views
Skip to first unread message

Karl Kosciuch

unread,
Mar 18, 2013, 11:00:13 AM3/18/13
to ez...@googlegroups.com
Hi folks -
I was excited to find the ez package, which calculates predicted probabilities from generalized linear mixed models, and it even has a graphics function.  However, I'm having some issues with making a basic figure from a glmm.  I simply want to plot the regression line for the predicted probabilities and show a 95% CI around the predicted probabilities. I am using a logistic regression with avoidance behavior as the binomial response variable, height as the predictor, and year as a random effect (there are 3 years).   I've looked at the package documentation to try to solve the error, and could not find any guidance.  I read a response from Mike that said "ezPredict wants to obtain predictions for every combination of every level of every predictor in the model, which can blow up when you have a continuous predictor in the mix with lots of levels. To constrain things, set the value of the "numeric_res" argument to something like 10".  Given I have a range of heights (150 to 1500m in 50m increments) and 3 years, would you advise constraining?


mod3<-lmer(avoid ~ height + (1|year), data = rsaabove, family="binomial")
print(mod3)
predprob = ezPredict(fit = mod3)
ezPlot2(preds = predprob, CI = 0.95, do_lines=TRUE, ribbon=TRUE)


Don't know how to automatically pick scale for object of type AsIs. Defaulting to continuous
Error: Aesthetics must either be length one, or the same length as the dataProblems:I(as.numeric())
In addition: Warning message:
In ezPlot2(preds = predprob, CI = 0.95, do_lines = TRUE, ribbon = TRUE) :
  Coercing LHS to a list

Mike Lawrence

unread,
Mar 18, 2013, 11:24:13 AM3/18/13
to ez...@googlegroups.com
Since you only have 28 levels of height, you shouldn't have any
problems letting ezPredict obtain predictions for each level. The
numeric_res argument is more useful with you have hundreds/thousands
of levels and/or when you have multiple such continuous variables
interacting in the model. While you have another numeric variable in
your model, year, since you have specified it as a random effect I
believe that it is not actually treated as a number but a category;
regardless, ezPredict doesn't bother with random effects anyway, just
the fixed effects side of the model (i.e. after variance associated
with random effects has been removed). (by the way, are you really
sure you want to be treating a variable like year as a random effect?)

The error you copied at the bottom of your message is a new one to me;
do you still get it if you omit both the "CI=0.95" and the
"do_lines=TRUE" arguments?

Also, instead of simply fitting a linear effect to height, might I
suggest exploring a generalized additive model, which would have the
power to pick up on non-linear effects as well? ezMixed will do this
automatically, but the mgcv:gam code would be:

gammod = gam(
formula = avoid ~ s(height,bs='ts',k=28) + s(year,bs='re')
, family = binomial
, data = rsaabove
)

And you can use ezPredict/ezPlot2 to visualize the resulting model.

Cheers,

Mike

--
Mike Lawrence
Graduate Student
Department of Psychology & Neuroscience
Dalhousie University

~ Certainty is (possibly) folly ~
> --
> You received this message because you are subscribed to the Google Groups
> "ez4r" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ez4r+uns...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Karl Kosciuch

unread,
Mar 18, 2013, 5:16:02 PM3/18/13
to ez...@googlegroups.com

Hi Mike - thanks for the quick reply.  I fit a logistic regression to the data and wanted to use ezPlot2 to plot the predicted probabilities and show the 95% CI.  Rather than show the probabilities as distinct points, I wanted to connect them with a line as shown in the image below (not sure if it will work as I haven't posted images to a google group).  I'd like to include year as a random effect because I want to account for year, but do not want to test for a year effect as the response variable is a behavior in an animal.  I removed "CI=0.95" and the "do_lines=TRUE" arguments and received the error. 
Reply all
Reply to author
Forward
0 new messages