Conversation
- `plyr::rbind.fill(...)` → `data.table::rbindlist(..., fill = TRUE, use.names = TRUE)` - `plyr::ddply(dat, cols, func)` → `lapply()` over unique combinations + `data.table::rbindlist()` - Added `data.table::setDF()` calls to convert back to data.frame for compatibility
**1. `beta()` function:** - Replaced growing vector (`beta <- NULL; beta[length(beta) + 1] <- ...`) with pre-allocated `numeric(length(phi))` - Used `which.max(densityIV$y)` instead of `densityIV$y == max(densityIV$y)` (safer, avoids floating-point equality issues) **2. `boot()` function:** - Pre-generate all random values as two matrices (2 `rnorm` calls instead of 2000) - Pre-compute `ones <- rep(1, n)` and `weights` outside the loop instead of recomputing each iteration - Cache `nphi <- length(phi)` to avoid repeated `length()` calls The loop itself still iterates 1000 times calling `beta()` (which calls `stats::density()`), but the per-iteration overhead is reduced by eliminating random number generation and redundant computations from inside the loop
- **Moved `ve` computation outside the loop** — was being recalculated identically on every iteration - **Eliminated the `for` loop entirely** — the `prop` calculation, `vg`, `r`, `correction`, and `sign` operations are all vectorized now - **Single call to `get_population_allele_frequency()`** with full vectors instead of element-by-element
- Pre-generate all random values as two matrices (2 `rnorm` calls instead of 2000) — `boot_exp` and `boot_out` are `nboot x nsnp` matrices - Loop now indexes rows from the pre-generated matrices instead of calling `rnorm()` each iteration - `sapply` → `vapply` for `model`, `Q`, `Qdash` extraction (4 calls)
- sapply` → `vapply` for `model`, `Q`, `Qdash` extraction (4 calls)
960def4 to
90a4d90
Compare
90a4d90 to
b1f4c70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some optimizations including:
mr_egger_regression_bootstrap()weighted_median_bootstrap()weighted_median()functionplyr::rbind.fill(...)todata.table::rbindlist(..., fill = TRUE, use.names = TRUE)plyr::ddply(dat, cols, func)tolapply()over unique combinations +data.table::rbindlist()data.table::setDF()calls to convert back to data.frame for compatibilityflip_alleles()usechartr()instead of 4gsub()callsrandom_string()use single call tosample()instead of n callsmr_mode()apply(..., any(is.na()))withcomplete.case()mr()functionOptimize get_r_from_lor()functionmr_rucker_bootstrap()andmr_rucker_jackknife_internal()functionssapply()withvapply()in several casessimple_cap()function