Matthieu Dubois
2009-May-07 10:11 UTC
[R] error using lapply with oneway_test (coin package)
Dear expeRts, I would like to use a oneway_test (from package coin) to test whether two groups differ on various variables. The variables are encoded within a data frame. Unfortunately, I obtained an error, that I don't understand. Could you please help me ? Example: library(coin) y <- as.data.frame(matrix(rnorm(200), ncol=2)) group <- as.factor(unif(100)) lapply(y, function(var) oneway_test(var ~ group)) Error message is: (in French, my locale) Erreur dans eval(expr, envir, enclos) : objet 'var' introuvable (my personal translation in English) Error in eval(expr, envir, enclos) : object 'var' not found Thank you, Matthieu Matthieu Dubois Post-doctoral fellow Psychology and NeuroCognition Lab (CNRS UMR 5105) Université Pierre Mendès-France BP47 --- 38040 Grenoble Cedex 9 --- France Email: matthieu.dubois@upmf-grenoble.fr Gmail: matthdub@gmail.com http://web.upmf-grenoble.fr/LPNC/membre_matthieu_dubois [[alternative HTML version deleted]]
Duncan Murdoch
2009-May-07 12:08 UTC
[R] error using lapply with oneway_test (coin package)
On 07/05/2009 6:11 AM, Matthieu Dubois wrote:> Dear expeRts, > > I would like to use a oneway_test (from package coin) to test whether > two groups differ on various variables. The variables are encoded > within a data frame. Unfortunately, I obtained an error, that I don't > understand. Could you please help me ? > > Example: > library(coin) > y <- as.data.frame(matrix(rnorm(200), ncol=2)) > group <- as.factor(unif(100)) > > lapply(y, function(var) oneway_test(var ~ group)) > > Error message is: > (in French, my locale) Erreur dans eval(expr, envir, enclos) : objet > 'var' introuvable > (my personal translation in English) Error in eval(expr, envir, > enclos) : object 'var' not foundThat's a scoping problem, I think a bug in oneway_test. Because the formula var ~ group is created with the anonymous function within lapply, its environment should be the evaluation frame of that function call and var should be visible. If I replace oneway_test() with lm() it works. I think a workaround is to construct the data argument explicitly, i.e. lapply(y, function(var) oneway_test(var ~ group, data.frame(var=var, group=group))) I've cc'd Torsten Hothorn, the maintainer of coin. Duncan Murdoch> > Thank you, > > Matthieu > > Matthieu Dubois > Post-doctoral fellow > > Psychology and NeuroCognition Lab (CNRS UMR 5105) > Universit? Pierre Mend?s-France > BP47 --- 38040 Grenoble Cedex 9 --- France > > Email: matthieu.dubois at upmf-grenoble.fr > Gmail: matthdub at gmail.com > http://web.upmf-grenoble.fr/LPNC/membre_matthieu_dubois > > > > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Apparently Analagous Threads
- Unexpected results using the oneway_test in the coin package
- Different result with "kruskal.test" and post-hoc analysis with Nemenyi-Damico-Wolfe-Dunn test implemented in the help page for oneway_test in the coin package that uses multcomp
- Compiling only some C files
- permutation test on paired samples
- one sample permutation test using package 'coin'