py-econometrics / wildboottest

python module for wild cluster bootstrapping
https://py-econometrics.github.io/wildboottest/
MIT License
7 stars 0 forks source link

Is this just a permutation function? #12

Closed amichuda closed 2 years ago

amichuda commented 2 years ago
        #TODO: Is this just a permutation function?
        permutations(
            n = 2,
            r = N_G_bootcluster,
            v = c(1, -1),
            repeats.allowed = TRUE
        )
s3alfisc commented 2 years ago

Yes, this is indeed just a permutation function, as taken from the gtools package: i.e. for G = 3 clusters, there are only 2^3 unique combinations of rademacher draws: ((1,1,1), (1, -1, -1), (1,-1,1),...,(-1,-1,-1)) and the function gets you all of these:

library(gtools)

N <- 100
G <- 3
bootcluster <- sample(1:G, N, TRUE)
bootcluster[1:5]
# [1] 1 4 3 1 4
N_G_bootcluster <- length(unique(bootcluster))
v <- permutations(
  n = 2,
  r = N_G_bootcluster,
  v = c(1, -1),
  repeats.allowed = TRUE
)

t(v)
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
# [1,]   -1   -1   -1   -1    1    1    1    1
# [2,]   -1   -1    1    1   -1   -1    1    1
# [3,]   -1    1   -1    1   -1    1   -1    1

This is low priority for a first implementation, we can just start with calling np.random.sample([-1,1], N_G_bootcluster * B) for a start.