mike-lawrence / ez

Development repository for the `ez` package for R
52 stars 17 forks source link

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

Open rxhu opened 11 years ago

rxhu commented 11 years ago

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 commented 11 years ago

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

rxhu commented 11 years ago

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 commented 9 years ago

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

OlafHaag commented 8 years ago

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 commented 8 years ago

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 notifications@github.com 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 https://github.com/mike-lawrence/ez/issues/32#issuecomment-176506202.

mangosarah commented 7 years ago

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 commented 6 years ago

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

mike-lawrence commented 6 years ago

I suspect that what folks are trying to achieve here might be solved by using tidy evaluation:

https://www.rstudio.com/resources/webinars/tidy-eval/

But it's really a sufficiently advanced use case that I'm not going to devote any time to it myself. Feel free to submit a pull request if you come up with any solutions yourself.

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

~ Certainty is (possibly) folly ~

On Mon, Mar 12, 2018 at 7:30 AM, Georgios Mavropalias < notifications@github.com> wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mike-lawrence/ez/issues/32#issuecomment-372262372, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJM_XV10oLC8Ls10WGkij81mH89XzXcks5tdk5cgaJpZM4ATnkI .