Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RE: ezANOVA return error message "....is not a variable in the data frame provided" #32

Open
rxhu opened this issue Dec 10, 2012 · 8 comments

Comments

@rxhu
Copy link

rxhu commented Dec 10, 2012

ezANOVA version 4 or later does not accept variable inputs for its function parameters. Here is the procedure to reproduce the bug:

Example 1:

library(ez)
data(ANT)
var = .(rt)
rt_anova = ezANOVA(
data = ANT[ANT$error==0,]
, dv = var
, wid = subnum
, within = .(cue,flank)
, between = group
)

Error in ezANOVA_main(data = data, dv = dv, wid = wid, within = within, :
"var" is not a variable in the data frame provided.

Example 2:

library(ez)
data(ANT)
var = .(subnum)
rt_anova = ezANOVA(
data = ANT[ANT$error==0,]
, dv = rt
, wid = var
, within = .(cue,flank)
, between = group
)

Error in ezANOVA_main(data = data, dv = dv, wid = wid, within = within, :
"var" is not a variable in the data frame provided.

This can be tested for any of ezANOVA's input parameters with the same error.

The reason I call it a BUG is that, for example, if I have multiple columns of dependent variables needed to be tested, a loop over the names of multiple dependent variables is the convenient way to get it done efficiently, in particular when the number of dependent variables is large, for example, more than 50,000 in my case and their names are literally diverse and different.

However, ezANOVA verison 3 or earlier did work for variable inputs. I have looked at the codes between version 4 and 3 and found that the following piece of codes for argument check in ezANOVA function of version 4 or later cause the problem:

args_to_check = c('dv','wid','within','between','observed','diff','within_full','within_covariates','between_covariates')
args = as.list(match.call()[-1])
for(i in 1:length(args)){
arg_name = names(args)[i]
if(arg_name%in%args_to_check){
if(is.symbol(args[[i]])){
code = paste(arg_name,'=.(',as.character(args[[i]]),')',sep='')
eval(parse(text=code))
}else{
if(is.language(args[[i]])){
arg_vals = as.character(args[[i]])
arg_vals = arg_vals[2:length(arg_vals)]
arg_vals = paste(arg_vals,collapse=',')
code = paste(arg_name,'=.(',arg_vals,')',sep='')
eval(parse(text=code))
}
}
}
}

I hope this will help you fix the bugs. It is generally unacceptable that a function doesn't allow to be called by another function with variable inputs for its function parameters

@crsh
Copy link

crsh commented Dec 11, 2012

I agree that it would be nice, if variable input was possible. For now, this 'hack' may save you from copypasta.

@rxhu
Copy link
Author

rxhu commented Dec 11, 2012

Thanks crsh for your comments. I have found a better solution but not sure whether it would affect the calculation results or not in general. At least the results are correct in my case. As I described, ezANOVA 3.0.0 was working for variable inputs and the superficial difference between 4.1.1 and 3.0.0 in ezANOVA function is the piece of codes for argument check as I copied in the above. I downloaded the source codes, commented them out, rebuild the package, and re-installed the package. It worked perfectly and gave the same results as version 3.0.0 did.

Since the error was thrown when calling ezANOVA_main function which is defined as internal and is not directly exposed to any end-user calls, I would suggest that the argument check codes be moved into ezANOVA_main function where the inputs get immediate uses after validation. Not only does this give a unique location for finding the error, but importantly this would save tons of lines of codes if ezANOVA_main function has to be called in many places in a package or project, in other words, you don't need to copy the argument check codes in front of every time this function gets called.

Hope this would help.

@drasnop
Copy link

drasnop commented Aug 14, 2015

+1 Any good analysis script needs to be able to call ezANOVA with variable arguments.

@OlafHaag
Copy link

I don't get it. I wanted to use ezANOVA for repeated measures (because I read it was supposed to be easy, and I'm a R beginner) and so I did something like:
ezANOVA(rframe, dv=.(rframe$"depvar"), wid=.(rframe$"S"), within=.(rframe$"Direction",rframe$"Block"), detailed=TRUE)
But I get this error:

"rframe$depvar" is not a variable in the data frame provided.

The data looks like this:
S Direction Block depvar
1 Left 1 1
1 Left 1 1
1 Left 2 -1
1 Left 2 1
1 Right 1 -1
1 Right 1 1
1 Right 2 -1
1 Right 2 -1
2 Left 1 1
2 Left 1 -1
2 Left 2 1
2 Left 2 -1
2 Right 1 -1
2 Right 1 -1
2 Right 2 -1
2 Right 2 1
... and so on

How am I even supposed to use ezANOVA?! I don't know how to get it to read my data!

@mike-lawrence
Copy link
Owner

You don't need to put the rframe$ bits before each variable name, and you
don't need to put the quote marks around the variable names either.

Let me know if you encounter any further troubles.

Mike

Mike Lawrence
Graduate Student
Department of Psychology & Neuroscience
Dalhousie University

~ Certainty is (possibly) folly ~

On Thu, Jan 28, 2016 at 9:07 PM, Vaquero84 [email protected] wrote:

I don't get it. I wanted to use ezANOVA for repeated measures (because I
read it was supposed to be easy, and I'm an R beginner) and so I did
something like:
ezANOVA(rframe, dv=.(rframe$"depvar"), wid=.(rframe$"S"),
within=.(rframe$"Direction",rframe$"Block"), detailed=TRUE)
But I get this error:

"rframe$depvar" is not a variable in the data frame provided.

The data looks like this:
S Direction Block depvar
1 Left 1 1
1 Left 1 1
1 Left 2 -1
1 Left 2 1
1 Right 1 -1
1 Right 1 1
1 Right 2 -1
1 Right 2 -1
2 Left 1 1
2 Left 1 -1
2 Left 2 1
2 Left 2 -1
2 Right 1 -1
2 Right 1 -1
2 Right 2 -1
2 Right 2 1
... and so on

How am I even supposed to use ezANOVA?! I don't know how to get it to read
my data!


Reply to this email directly or view it on GitHub
#32 (comment).

@mangosarah
Copy link

mangosarah commented Feb 16, 2017

Hello,

I have the same problem as @Vaquero84. I'm also a R beginner and the ezANOVA function gives me the same error.

This is my ANOVA:

ANOVAghq <- ezANOVA(data=complete.cases(dataforanova), dv=.(ghq), wid=.(TN), between=.(schuljahr), within=.(Messzeitpunkte), type=3, detailed=T)
ANOVAghq

This is the error I get:

Error in ezANOVA_main(data = data, dv = dv, wid = wid, within = within, : "ghq" is not a variable in the data frame provided.

And this is how I get the table for the ANOVA:

dataforanova <- melt(data, id=c("TN", "schuljahr"), measured=c("ghq.1", "ghq.2", "ghq.3"))
names(dataforanova) <- c("TN", "schuljahr", "messzeitpunkte", "ghq")
dataforanova$Messzeitpunkte <- gl(3, 267, labels = c("T1", "T2", "T3"))

I don't know how to put my data here. But if I look at it with View(dataforanova), there is the variable ghq. Still ezANOVA doesn't find it. What is wrong? Can anyone help me, please? @Vaquero84 did you solve the problem? Maybe I made a really silly mistake and don't get it, because I'm just learning R.

Thanks a lot!!

@MavropaliasG
Copy link

Any news on this ? Why can't we set the arguments that call for column names as variables ?

@mike-lawrence
Copy link
Owner

mike-lawrence commented Mar 12, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants