Calculate CI for chi-squared of the Friedman test in R I have a dataset (not normal distribution) with repeated measures over time. As such I was planning to use the Friedman.test in R:
friedman.test(dash ~ time | nr)

this gave:

Friedman rank sum test
data: dash and time and nr Friedman chi-squared = 105.26, df = 2, p-value < 2.2e-16

To calculate the CI of the chi-squared I tried the following:
friedman_boot <- function(data, indices) {
  return(friedman.test(dash ~ time | nr, data = data_t[indices, ])$statistic)
}

boot_results <- boot(data = data_t, statistic = friedman_boot, R = 1000)

boot_ci <- boot.ci(boot.out = boot_results, type = "perc", conf = 0.95)

boot_ci

which gave:
boot_results <- boot(data = data_t, statistic = friedman_boot, R = 1000) 

Error in friedman.test.default(mf[[1L]], mf[[2L]], mf[[3L]]) : not an unreplicated complete block design

I do not quite understand why this happens. Does anyone have another way to calculate CI for the test statistic?
 A: It's not clear why you need to calculate the CI for the Friedman statistic, particularly given the very small p-value, but here's a way to proceed if you do.
The problem is that the friedman.test() function, according to its R help page, requires "exactly one observation in [outcome] y for each combination of levels of groups and blocks," where the "group" is time in your case and "blocks" are your nr values. Your resampling leads to repeated nr values in the same group, violating that requirement.
You also don't seem to be resampling by block/nr, which would be more consistent with the original sampling: a set of individuals each followed over all time values. To do that, start by reshaping your data into wide format so that you select all observations for each nr value together. The tidyr nest() function can simplify that. After you've taken a bootstrap re-sample from the wide format, adjust the nr values so that there are no duplicates (to get around the warning from friedman.test()) and unnest() to long format for your tests.
A: I think the solution presented by @EdM is the correct approach to apply bootstrap for Friedman's test.
You may be interested in Kendall's W which is used as an effect size statistic for Friedman's test, and is a standardized version of the chi-square statistic from that test.
In R, one implementation is in the DescTools package (KendallW()). And I have a version which implements the confidence interval by bootstrap in the rcompanion package (kendallW()).
For each of these, the input is passed to the function as a table, e.g. by
 XT = xtabs(dash ~ time | nr, data = data_t)

If you conduct the bootstrap yourself, you might want to work with data in this table format.  The native friedman.test() function can also handle data in this format, so it should be easy to pass the bootstrap data to this function (without converting it back to long format).
