1

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)?

Glen_b
  • 257,508
  • 32
  • 553
  • 939
varin sacha
  • 753
  • 2
  • 8
  • 18
  • check out this older post: http://stats.stackexchange.com/questions/3113/parametric-sample-size-calculation-and-non-parametric-analysis –  Sep 03 '13 at 19:58

3 Answers3

3

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).

Greg Snow
  • 46,563
  • 2
  • 90
  • 159
2

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.

Avraham
  • 3,182
  • 21
  • 40
  • 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 05 '17 at 02: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 05 '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 05 '17 at 21:50
  • @Glen_b I may have conflated the two in which case the answer is wrong. Should I delete it? – Avraham Jul 06 '17 at 14:18
  • 1
    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 06 '17 at 14:47
  • 1
    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 06 '17 at 14:50
1

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.

Horst Grünbusch
  • 5,020
  • 17
  • 22