# Nonparametric test

To get the power of the t-test I use this R code:

pwr.t.test(n=25,d=0.35,sig.level=0.05,type="one.sample",alternative="greater")


and for the test of the Pearson coefficient of correlation I use this R code :

pwr.r.test(r=0.3,n=36,sig.level=0.05,alternative="greater")


I would like to know if it is possible to get the R code/script to get the power of the 3 nonparametric test (Wilcoxon, Wilcoxon/Mann-Whitney and the Kruskal-Wallis)?

One option to find power for any type of test is to use simulation. This answer and this answer (and others) shows examples of using simulation to compute power (but for a different tests than you ask about, you will need to modify accordingly).

In the coin package, I believe all the tests come with both the asymptotic and exact power calculations available. See its entry. It has the Wilcoxon, Kruskall, and many others.

This answer confused the distribution of the null with the power. It is incorrect.

• I did a quick read through of the help and a vignette, and tried several search terms but I couldn't find any functions relating to power and sample size. It's possible I missed something but are you sure coin does this? – Glen_b Jul 5 '17 at 2:29
• @Glen_b, please see the help on wilcox_test for example (maps to LocationTests) which says: "The conditional null distribution of the test statistic is used to obtain p-values and an asymptotic approximation of the exact distribution is used by default (distribution = "asymptotic"). Alternatively, the distribution can be approximated via Monte Carlo resampling or computed exactly for univariate two-sample problems by setting distribution to "approximate" or "exact" respectively. See asymptotic, approximate and exact for details." – Avraham Jul 5 '17 at 15:38
• Thanks. That part is discussing the various ways to approximate the distribution of the test statistic under the null hypothesis (which is needed to compute p-values). It's not talking about computation of power there at all, which would use the distribution of the test statistic under some condition other than the null. – Glen_b Jul 5 '17 at 21:50
• If you can see some way to fix or improve it, that could be better, though I'd be slightly surprised if there's software for the power of the Wilcoxon-Mann-Whitney or the Kruskal-Walls (though you might find it done for the Gaussian case perhaps, or with simulation for a location-shift alternative with naming a common distribution or supplying a function to generate samples). As it currently stands it seems it's not a correct answer to the question -- but mod-deletions aren't really for genuine attempts at an answer (that's what votes are for), so I'll leave that choice up to you. ... ctd – Glen_b Jul 6 '17 at 14:47
• ctd... If you don't delete, at least consider correcting the spelling on Kruskal (and hopefully adding -Wallis so we name the test rather than R's abbreviation) – Glen_b Jul 6 '17 at 14:50

There is probably no single code for power analysis of the said tests because there are various ways how to define the effect. Is it a location scale model? Is the effect proportional? Is it something else? The WMW and KW tests will detect various effects with various meaning. You'll have to study the structure of the research question you have in mind to decide this prior to write some ad hoc-simulation code.