Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different numbers of strata across blocks #27

Open
dbaranger opened this issue Aug 25, 2020 · 3 comments
Open

Allow different numbers of strata across blocks #27

dbaranger opened this issue Aug 25, 2020 · 3 comments

Comments

@dbaranger
Copy link

Permute requires the number of strata to be the same across all plots. However, it also requires the number of strata to be the same across all blocks. Since blocks are never exchanged, this seems unnecessary, and it prevents an easy implementation of permutation schemes where the defining feature of a block is the number of strata. For instance, if I have a variable number of observations per sample, I would like to define the block as the number of observations per sample, and then permute such that I only exchange with samples that have the same number of observations. This is a common enough design that some researchers have written custom code specific to this kind of design. Is it possible to allow blocks to have different number of strata?

@gavinsimpson
Copy link
Owner

Do you have an example where I enforce this in permute? I don't recall putting in that restriction but it's a while since I wrote a lot of this and something might have sneaked in without my thinking too much about it.

I suspect this is getting caught in check() because I'm not considering the blocks at the point I check for strata length consistency. I certainly take a look at addressing this, but if you have some dummy or example code that triggers the issue that would help me get to fixing this sooner?

@dbaranger
Copy link
Author

Hi! Thanks for the quick response. Here's an rpe:

With unbalanced blocks:

dat<-data.frame(blocklevel = c(rep(1,10),rep(2,30)), plotlevel = c(rep(c(1,2),5),rep(c(3:5),10))) dat<-dat[order(dat$plotlevel,dat$blocklevel),]

perms<-shuffleSet(n = dim(dat)[1], nset = 2, control = how(within = Within(type = "free"), blocks = dat$blocklevel, plots = Plots(strata = dat$plotlevel,type = "free") ))

produces the error:

Error in check(sn, control = control, quietly = quietly) : Design must be balanced if permuting 'strata'.

If instead the blocks all have the same number of levels:
dat<-data.frame(blocklevel = c(rep(1,20),rep(2,30)), plotlevel = c(rep(c(1,2),10),rep(c(3:5),10))) dat<-dat[order(dat$plotlevel,dat$blocklevel),]

No error, runs perfectly. And if the first example includes only one of the blocks it also runs perfectly.

@gavinsimpson
Copy link
Owner

Thanks for this; I should be able to quickly fix check() to run the strata checks within blocks to allow this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants