repeated measures PERMANOVA nowhere to find the internet seems full of people looking for a way to account for non-independence of samples when using the PERMANOVA method as implemented in the functions adonis or adonis2.
If there is anyone here who could point me to a solution, that would be great. My design is very simple: 2 groups randomly assigned, measured at 3 time points. I want to know whether the groups differ over time in beta diversity.
the formula used for that in linear models would be this:
dist ~ group * time + (1|subject_id)
That way I would get the effect of the intervention at each time point while accounting for non-independence of samples belonging to the same subject.
How can I code this using adonis2?
 A: One way is to use a restricted permutation test; your data are not exchangeable between subjects, so in this instance you would permute samples within the groups defined by the factor subject.
To do that, you would have to do:
library("permute")
h <- how(plots = Plots(strata = df$subject, type = "none"),
         nperm = 499)

adonis2(…, permutations = h)

More flexibility is afforded if you use dbrda() as we have a formula that can take Condition() which is often needed for model-based testing.
Technically, within subjects, your data are only exchangeable if there is no trend, and we preserve the dependence structure between observations. A cyclic shift permutation would work within the subjects, so you would need to add within = Within(type = "series") to that how() call above. This assumes that you data are in time order within subjects, and that they are evenly spaced in time.
If all the subjects were assessed at the same time points, an argument can be made that the subjects experienced the same “time”, and hence there are dependencies within time over the subjects. I. That case you need to use the same permutation of the three time points in all subjects. To do this you need to add constant = TRUE to the Within() call above.
Unfortunately, if you need that last bit (constant = TRUE), there are only three valid permutations of the data and the minimum p value you could achieve would be 0.33, regardless of how many observations you might have at the level of subject 
