Ordered set partitions and formulas in permute

Wait 5 sec.

[This article was first published on From the bottom of the heap — R posts, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.I’ve been giving permute a bit of attention recently. Two additions should make it easier to set up permutation tests: an option for ordered set partitions, and formulas for specifying plots and blocks. That’s a rather grand name for the first addition, so let’s start with what it does.These changes are in the development version. To follow along, install it from my R-universe:install.packages("permute", repos = c( "https://gavinsimpson.r-universe.dev", "https://cloud.r-project.org"))Same groups, fewer permutationsThe jackal data that come with permute contain mandible lengths, in millimetres, for male and female golden jackals. They’re also used in the package vignette. Let’s ask whether mean mandible length differs between the sexes.library("permute")data(jackal, package = "permute")table(jackal$Sex) Male Female 10 10 We could shuffle all the observation indices and use them to rearrange the sex labels. With the default Within(type = "free") design, the number of possible index permutations is:numPerms(nrow(jackal), control = how(within = Within(type = "free")))[1] 2.432902e+18But swapping a pair of males, or a pair of females, leaves the group labels unchanged. If our statistic is a difference of means, we haven’t created a different result by doing that.What we need are the distinct ways of assigning the observations to two labelled groups, keeping the group sizes fixed. That’s the ordered set partition. Here, ordered means the groups are distinguishable — male and female have different roles — rather than that observations have to be sorted inside each group.The new option is type = "partition" which belongs in Plots(). I’ll use the new formula interface here too; ~ Sex says to get the grouping variable from data, to which we pass jackal:ctrl