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