We ran into an scenario where a cluster is small such that https://github.com/ntdyjack/fasthplus/blob/main/R/bsf.R#L20 fails. That's because the small cluster is smaller than the t divided by the number of clusters. That is, t / length(q).
We can avoid this by choosing t with code like this:
Looks like reprex doesn't include the traceback() output. Here it is:
Error in sample.int(length(x), size, replace, prob) :
cannot take a sample larger than the population when 'replace = FALSE'
> traceback()
6: sample.int(length(x), size, replace, prob)
5: sample(x, round(t/length(q))) at #1
4: FUN(X[[i]], ...)
3: lapply(X = X, FUN = FUN, ...)
2: sapply(q, function(x) sample(x, round(t/length(q))))
1: as.vector(sapply(q, function(x) sample(x, round(t/length(q)))))
EDIT end
The problem with the above solution, is that it could result in very low values of t when for example you have clusters that are very small compared to others. Abby @abspangler13 has a case where we have 15 clusters and the smallest one has a size of 8. So the smallest t would then be 15 * 8 = 120 as shown below, which would be very small.
Hi,
We ran into an scenario where a cluster is small such that https://github.com/ntdyjack/fasthplus/blob/main/R/bsf.R#L20 fails. That's because the small cluster is smaller than the
t
divided by the number of clusters. That is,t / length(q)
.We can avoid this by choosing
t
with code like this:Otherwise, when
t / length(q)
is larger than the smallest cluster size, then you run into an error withsample()
becausereplace = FALSE
by default. Alternatively, https://github.com/ntdyjack/fasthplus/blob/736494f1534ca04db14775210fd1bcbfdfe7864e/R/bsf.R#L20 could be changed to havesample(replace = TRUE)
but I don't know if this would break your bootstrap assumptions.Created on 2022-03-08 by the reprex package (v2.0.1)
EDIT start
Looks like
reprex
doesn't include thetraceback()
output. Here it is:EDIT end
The problem with the above solution, is that it could result in very low values of
t
when for example you have clusters that are very small compared to others. Abby @abspangler13 has a case where we have 15 clusters and the smallest one has a size of 8. So the smallestt
would then be15 * 8 = 120
as shown below, which would be very small.Best, Leo