# [R] power analysis for Friedman's test

Greg Snow 538280 @end|ng |rom gm@||@com
Thu Apr 18 23:08:16 CEST 2019

```Generally you should do the power analysis before collecting any data.
Since you have results it looks like you already have the data
collected.

But if you want to compute the power for a future study, one option is
to use simulation.

1. decide what the data will look like
2. decide how you will analyze the data
3. simulate data and analyze it based on 1 and 2
4. repeat step 3 a bunch of times, the proportion of "Significant"

Here is an example to use as a starting point:

simfun <- function(nblocks=10, means=c(0,0,0), within.sd=1, between.sd=1) {
g <- factor(rep(seq_len(nblocks), each=length(means)))
t <- rep(seq_along(means), nblocks)
y <- means[t] + rnorm(nblocks, 0, between.sd)[g] + rnorm(length(g),
0, within.sd)
friedman.test(y ~ t | g)\$p.value
}

# test size of test
out <- replicate(1000, simfun())
hist(out)
mean(out <= 0.05)

# now for power
out2 <- replicate(1000, simfun(nblocks=25, means=c(10, 10.5, 11)))
hist(out2)
mean(out2 <= 0.05)

On Thu, Apr 18, 2019 at 1:40 PM George Karavasilis <gkaravas using ee.duth.gr> wrote:
>
> Hello,
> I am running a non parametric repeated measures experiment with
> Friedman’s test:
>
>          Friedman rank sum test
>
> data:  glikozi and week and subject
> Friedman chi-squared = 18.538, df = 3, p-value = 0.0003405
>
> How could I run a power analysis for this test in R?
> Thank you!
>
> --
> George Karavasilis
> Serres, Greece
>
>
> ---
> Αυτό το e-mail ελέγχθηκε για ιούς από το πρόγραμμα Avast antivirus.
> https://www.avast.com/antivirus
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help