Passing a variable name to ezPlot2 from within a function

37 views
Skip to first unread message

Adriana De Palma

unread,
Mar 13, 2013, 9:13:36 AM3/13/13
to ez...@googlegroups.com
Hi there,

I'm trying to write a function that takes a model of class mer, calculates predictions (using ezPredict), provides the plotting data (using ezPlot2) and plots it in my own preferred manner.

My problem is that ezPlot2 will not accept the argument x if it is specified within my function. Here's a short example:

let's say the model is called fm1 and the variable we want on the x-axis is called xfactor.

plot_lmer_means<-function(model,variable){
  require(ez, quietly = TRUE)
  preds<-ezPredict(model,effect_variability_only = TRUE)
  plot.data<-as.data.frame(ezPlot2(preds = preds, x = variable,do_plot = FALSE))
  ....plotting code......
}

plot_lmer_means(fm1,xfactor)

This does not work.

However if I specify exactly the same argument within the ezPlot2 code itself, it works:

plot_lmer_means<-function(model){
  require(ez, quietly = TRUE)
  preds<-ezPredict(model,effect_variability_only = TRUE)
  plot.data<-as.data.frame(ezPlot2(preds = preds, x = xfactor,do_plot = FALSE))
  ....actual plotting code......
}

plot_lmer_means(fm1)

I'm just not sure why ezPlot2 will not accept an argument from my wrapper function.

Any thoughts would be greatly appreciated as I'd like to get my head around this...

Thanks,

Adriana

Mike Lawrence

unread,
Mar 13, 2013, 9:24:27 AM3/13/13
to ez...@googlegroups.com
Strange! I'll have a chance to look at this later this evening, but in
the meantime can you confirm that the same thing happens with the
latest version of ez? (I believe that your use of the argument
"effect_variability_only" in your call to ezPredict suggests you are
using an older version; the latest version replaces that argument with
"zero_intercept_variability"; same behaviour, different argument
name).


Cheers,

Mike

--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

~ Certainty is folly... I think. ~
> --
> 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.
>
>

Adriana De Palma

unread,
Mar 13, 2013, 11:00:34 AM3/13/13
to ez...@googlegroups.com
Apologies - that was in some older code (I had just read that it might be better to use that argument but it isn't for this version  of ez, as you said).

I'm using the package version 4.1-1. 

Adriana De Palma

unread,
Mar 13, 2013, 11:02:53 AM3/13/13
to ez...@googlegroups.com
 
I have read that maybe it is something to do with my variable being called from the wrong environment but I don't really understand it...

Thank you very much for your help!

Adriana 
Reply all
Reply to author
Forward
0 new messages