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

Suggestion: use qtab() for crosstab() #117

Open
SebKrantz opened this issue May 29, 2023 · 2 comments
Open

Suggestion: use qtab() for crosstab() #117

SebKrantz opened this issue May 29, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@SebKrantz
Copy link

qtab() introduced in collapse 1.8.0 should be more efficient than the workaround with fsum(). You need to pass the data to the weights argument w of qtab(). In any case, even if that should not be the case, fsum() now has an argument fill = TRUE, which you can set to avoid the res[is.na(res)] <- 0 line.

@s3alfisc
Copy link
Owner

Oh, that's super cool! Thanks for pointing me to it. I will move to qtab() with the next release. Thanks! =)

@s3alfisc s3alfisc added the enhancement New feature or request label May 29, 2023
@s3alfisc
Copy link
Owner

Yes, it indeed gives good speed up:

library(microbenchmark)

N <- 100000
a <- sample(1:20, N, replace = TRUE)
b <- sample(1:300, N, replace = TRUE)
y <- matrix(rnorm(N), N, 1)
data <- y
var1 <- data.frame(a = a)
var2 <- data.frame(b = b)

microbenchmark(
ct1 <- fwildclusterboot:::crosstab(data = data, var1 = var1, var2 = var2),
ct4 <- fwildclusterboot:::crosstab4(data = data, var1 = var1, var2 = var2),
ct5 <- fwildclusterboot:::crosstab_qtab(data = data, var1 = var1, var2 = var2),
times = 1
)

# min         lq       mean     median         uq        max
# 5.353802   5.353802   5.353802   5.353802   5.353802
# 225.850701 225.850701 225.850701 225.850701 225.850701
# 3.371901   3.371901   3.371901   3.371901   3.371901

Nice! :)

s3alfisc added a commit that referenced this issue Jun 17, 2023
@s3alfisc s3alfisc linked a pull request Jun 17, 2023 that will close this issue
@s3alfisc s3alfisc removed a link to a pull request Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants