Dupouey Jean-Luc
2008-Jan-26 21:02 UTC
[R] How to apply the wilcox_test function to subsets ?
Dear R-forumites, I want to apply a Wilcoxon test on subsets of the data frame mydata, splitted using the myindice variable. When I send : wilcoxtest <- by(mydata, mydata$myindice, function(x) {wilcox_test(x$value~x$fact)}) I get : Error in eval(expr, envir, enclos) : object "x" not found whereas wilcoxtest <- by(mydata, mydata$myindice, function(x) {wilcox.test(x$value~x$fact)}) works ! Why does it fail with the wilcox_test only? And, most important, how can I apply the wilcox_test function to subsets of mydata splitted according to mydata$myindice ? Thanks in advance, Jean-Luc Dupouey Forest Ecology and Ecophysiology Unit INRA 54280 Champenoux France mail: dupouey@nancy.inra.fr [[alternative HTML version deleted]]
David Winsemius
2008-Jan-26 22:43 UTC
[R] How to apply the wilcox_test function to subsets ?
"Dupouey Jean-Luc" <dupouey at nancy.inra.fr> wrote in news:000001c8605e$c987c650$0b01a8c0 at PHYTOD420: On my system wilcox.test() exists, whereas wilcox_test() did not. Help.search("wilcox_test") does not produce any clues. If you are using a test from another package, you should specify which package the test comes from. Web searching produces links to package coin. Have you tried? wtest <- by(mydata, mydata$myindice, function (x) { wilcox_test(value~fact, data=x)}) ----slight modification to the wilcox_test example data------> mydatapd age grp 1 0.80 At term 1 2 0.83 At term 2 3 1.89 At term 1 4 1.04 At term 2 5 1.45 At term 1 6 1.38 At term 2 7 1.91 At term 1 8 1.64 At term 2 9 0.73 At term 1 10 1.46 At term 2 11 1.15 12-26 Weeks 1 12 0.88 12-26 Weeks 2 13 0.90 12-26 Weeks 1 14 0.74 12-26 Weeks 2 15 1.21 12-26 Weeks 1 16 1.10 12-26 Weeks 2> wilcoxtest <- by(mydata, mydata$grp, function(x)+ {wilcox_test(pd~age, data=x)} + )> wilcoxtestAsymptotic Wilcoxon Mann-Whitney Rank Sum Test data: pd by age (12-26 Weeks, At term) Z = -0.4472, p-value = 0.6547 alternative hypothesis: true mu is not equal to 0 --------------------------------------------------- Asymptotic Wilcoxon Mann-Whitney Rank Sum Test data: pd by age (12-26 Weeks, At term) Z = -1.3416, p-value = 0.1797 alternative hypothesis: true mu is not equal to 0 -- David Winsemius> I want to apply a Wilcoxon test on subsets of the data frame mydata, > splitted using the myindice variable. When I send : >> wilcoxtest <- by(mydata, mydata$myindice, function(x) > {wilcox_test(x$value~x$fact)}) >> I get : > > Error in eval(expr, envir, enclos) : object "x" not found > > whereas > > wilcoxtest <- by(mydata, mydata$myindice, function(x) > {wilcox.test(x$value~x$fact)})> works !> Why does it fail with the wilcox_test only? And, most important, how > can I apply the wilcox_test function to subsets of mydata splitted > according to mydata$myindice ? >