-
Notifications
You must be signed in to change notification settings - Fork 4
Feature eair: Extra combined statistic required to be able to present "n (EAIR per 100 SY)" #362
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
Merged
Merged
Changes from all commits
Commits
Show all changes
100 commits
Select commit
Hold shift + click to select a range
b102ea9
temp commit, not yet finished
iaugusty 781ebba
temp commit, not yet finished
iaugusty 712a9f5
update roxygen/test/disable NULL for occ_var
iaugusty 704849e
update NEWS
iaugusty bb19d5c
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty 2876b01
Merge branch 'dev' into feature/hotfix_eair
iaugusty fc318b7
lintr + spelling
iaugusty 373a610
removed duplicated section
iaugusty 8ba3f5e
lintr
iaugusty a5f3e41
retrigger CI
iaugusty 50783dd
Update check_CRAN.yaml
munoztd0 0bece99
Update check_CRAN.yaml
munoztd0 f0d9ecb
Merge branch 'dev' into feature/hotfix_eair
munoztd0 280f027
Merge branch 'dev' into feature/hotfix_eair
munoztd0 d85aefd
Merge branch 'dev' into feature/hotfix_eair
munoztd0 a94bf35
Merge remote-tracking branch 'origin/dev' into feature/hotfix_eair
iaugusty 133d097
add new approaches for conf interval for diff in rate
iaugusty d50b9e6
add new approach for occ_var = NULL, count_events
iaugusty 6e1f9cb
assign cps
iaugusty 1411f27
match precision of test a_eair_diff with snapshot version
iaugusty 1b3cb0f
lintr
iaugusty ebd42dc
importFrom stats ave
iaugusty c1e22e9
namespace stats, ave
iaugusty 5e2f5cb
added rateci github to suggest and added remotes
munoztd0 004d88f
update label behaviour depending on rowsplit or not
iaugusty 2ecebad
a_eair_diff separate tests with ratesci from snapshot tests
iaugusty 0277ccc
address review comments Nik
iaugusty 93bfe16
remotes pharmaverseadamjnj for test test-summarize_ancova
iaugusty 6388019
Merge remote-tracking branch 'origin/dev' into feature/hotfix_eair
iaugusty 5b82f2a
lintr
iaugusty 2e4850f
Merge branch 'dev' into feature/hotfix_eair
munoztd0 73f2931
Several updates
iaugusty f706c85
Merge remote-tracking branch 'origin/dev' into feature/hotfix_eair
iaugusty 6a5a76a
spell and lintr
iaugusty 9b58932
fix : ! subscript out of bounds
munoztd0 46be3fc
pass ref_col_expr NULL when not relevant
iaugusty 0a39219
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty 4f1b5b6
fix: tests
munoztd0 569f48c
lintr
munoztd0 847d2e8
update: test accroding to new ratesci updates
munoztd0 cf187c1
update: test to data pahrmaverse
munoztd0 799aac2
- introduced new helper function for riskdiff setup
iaugusty 294935d
style + lint
iaugusty 84e5918
style + lint
iaugusty 26ae5f4
update snapshot after lintr
iaugusty 1d51bf0
update to new CRAN release fo ratesci
munoztd0 319a791
Merge remote-tracking branch 'origin/feature/hotfix_eair' into featur…
munoztd0 94f65c0
Merge branch 'dev' into feature/hotfix_eair
iaugusty dbf45d4
h_incidence_rate tern got exported
iaugusty 8ee011e
new function a_eair_strat_j
iaugusty 586c232
spellcheck
iaugusty cbdda69
allow scoring to be performed on other than first number in cellvalue…
iaugusty f6368b0
temp commit, not yet finished
iaugusty 3b050c2
update roxygen/test/disable NULL for occ_var
iaugusty 163e2c4
update NEWS
iaugusty a69bfd1
temp commit, not yet finished
iaugusty f6cc18e
lintr + spelling
iaugusty f3a1d92
lintr
iaugusty ee7ce30
retrigger CI
iaugusty 171c469
Update check_CRAN.yaml
munoztd0 fe7be26
add new approaches for conf interval for diff in rate
iaugusty f985b20
add new approach for occ_var = NULL, count_events
iaugusty 4fa7b50
assign cps
iaugusty d25e5a8
match precision of test a_eair_diff with snapshot version
iaugusty 4f76d89
lintr
iaugusty b99e707
importFrom stats ave
iaugusty 4fd1933
namespace stats, ave
iaugusty 3ae4c4b
added rateci github to suggest and added remotes
munoztd0 8abd51e
update label behaviour depending on rowsplit or not
iaugusty 7bde155
update to new CRAN release fo ratesci
munoztd0 1bf6155
a_eair_diff separate tests with ratesci from snapshot tests
iaugusty 71b883b
address review comments Nik
iaugusty 3185f18
remotes pharmaverseadamjnj for test test-summarize_ancova
iaugusty f4c5482
lintr
iaugusty 9c42639
Several updates
iaugusty cf04e53
spell and lintr
iaugusty 8e7a13d
pass ref_col_expr NULL when not relevant
iaugusty 56814da
fix : ! subscript out of bounds
munoztd0 a2a0306
fix: tests
munoztd0 b49ce10
lintr
munoztd0 d12166e
update: test accroding to new ratesci updates
munoztd0 7d7e055
update: test to data pahrmaverse
munoztd0 833e478
- introduced new helper function for riskdiff setup
iaugusty a8503b1
style + lint
iaugusty 5a94fff
style + lint
iaugusty 2c88f5f
update snapshot after lintr
iaugusty b047591
h_incidence_rate tern got exported
iaugusty d7050e6
new function a_eair_strat_j
iaugusty 65100e0
spellcheck
iaugusty 1076583
allow scoring to be performed on other than first number in cellvalue…
iaugusty 15a1e6c
in_ref_col() - support ref_path = NULL, minor variables change in uni…
wwojciech 575858c
fix merge issues with rebase on dev
munoztd0 da2294c
fix: lintr
munoztd0 e2e832a
Update R/utils.R
iaugusty bad3e53
Update utils.R
munoztd0 d66e786
merge + lintr
iaugusty b6e9c2d
lintr
iaugusty 7261f8a
Merge branch 'dev' into feature/hotfix_eair
munoztd0 ad77deb
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty a0f5f5e
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
|
iaugusty marked this conversation as resolved.
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| .h_s_eair_diff_scalar <- function(x1, | ||
| n1, | ||
| x2, | ||
| n2, | ||
| conf_type = c("wald", "waldcc", "mn", "scas"), | ||
| conf_level = 0.95) { | ||
| conf_type <- match.arg(conf_type) | ||
| diff_est <- switch(conf_type, | ||
| waldcc = h_s_eair_diff_wald(x1, n1, x2, n2, conf_level, cc = TRUE), | ||
| wald = h_s_eair_diff_wald(x1, n1, x2, n2, conf_level, cc = FALSE), | ||
| mn = h_s_eair_diff_mn(x1, n1, x2, n2, conf_level, skew = FALSE), | ||
|
Comment on lines
+9
to
+11
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be relatively optimistic that we have these 3 in |
||
| scas = h_s_eair_diff_mn(x1, n1, x2, n2, conf_level, skew = TRUE) | ||
|
iaugusty marked this conversation as resolved.
|
||
| ) | ||
| list(diff_est = diff_est$est, diff_lcl = diff_est$ci[1], diff_ucl = diff_est$ci[2]) | ||
| } | ||
|
|
||
| h_s_eair_diff <- function(x1, | ||
| n1, | ||
| x2, | ||
| n2, | ||
| conf_type, | ||
| conf_level = 0.95) { | ||
| results <- mapply( | ||
| .h_s_eair_diff_scalar, | ||
| x1, n1, x2, n2, | ||
| MoreArgs = list(conf_type = conf_type, conf_level = conf_level), | ||
| SIMPLIFY = FALSE | ||
| ) | ||
| data.frame( | ||
| diff_est = sapply(results, `[[`, "diff_est"), | ||
| diff_lcl = sapply(results, `[[`, "diff_lcl"), | ||
| diff_ucl = sapply(results, `[[`, "diff_ucl") | ||
| ) | ||
| } | ||
|
|
||
| h_s_eair_diff_wald <- function(x1, n1, x2, n2, conf_level, cc = TRUE) { | ||
| alpha <- 1 - conf_level | ||
| est <- x1 / n1 - x2 / n2 | ||
| se <- sqrt(x1 / n1^2 + x2 / n2^2) | ||
|
|
||
| coeff <- stats::qnorm(1 - alpha / 2) | ||
| term2 <- coeff * se | ||
| if (cc) { | ||
| term2 <- term2 + 0.5 * (1 / n1 + 1 / n2) | ||
| } | ||
| lcl <- est - term2 | ||
| ucl <- est + term2 | ||
|
|
||
| eair_diff <- list() | ||
| eair_diff$est <- est | ||
| eair_diff$ci <- c(lcl, ucl) | ||
| eair_diff | ||
| } | ||
|
|
||
| h_s_eair_diff_mn <- function(x1, n1, x2, n2, conf_level, skew = FALSE) { | ||
| alpha <- 1 - conf_level | ||
| z <- stats::qnorm(1 - alpha / 2) | ||
|
|
||
| est <- x1 / n1 - x2 / n2 | ||
|
|
||
| lcl <- .conf_poi_rd(x1, n1, x2, n2, z, lower = TRUE, skew = skew, level = conf_level) | ||
| ucl <- .conf_poi_rd(x1, n1, x2, n2, z, lower = FALSE, skew = skew, level = conf_level) | ||
|
|
||
| eair_diff <- list() | ||
| eair_diff$est <- est | ||
| eair_diff$ci <- c(lcl, ucl) | ||
| eair_diff | ||
| } | ||
|
|
||
| .score_poi_rd <- function(x1, n1, x2, n2, theta, skew = FALSE, level = 0.95) { | ||
| alpha <- 1 - level | ||
| p1hat <- x1 / n1 | ||
| p2hat <- x2 / n2 | ||
| Stheta <- (p1hat - p2hat) - theta | ||
| if (isTRUE(abs(Stheta) == 0)) { | ||
| return(0) | ||
| } | ||
| x <- x1 + x2 | ||
| N <- n1 + n2 | ||
| A <- N | ||
| B <- N * theta - x | ||
| C_ <- -x2 * theta | ||
| num <- (-B + sqrt(B^2 - 4 * A * C_)) | ||
| p2d <- ifelse(isTRUE(num == 0), 0, num / (2 * A)) | ||
| p1d <- p2d + theta | ||
| V <- p1d / n1 + p2d / n2 | ||
| score1 <- Stheta / sqrt(V) | ||
|
|
||
| if (!skew) { | ||
| return(score1) | ||
| } | ||
|
|
||
| # Skewness correction (SCAS) | ||
| mu3 <- p1d / (n1^2) - p2d / (n2^2) | ||
| scterm <- mu3 / (6 * V^(3 / 2)) | ||
| if (isTRUE(scterm == 0)) { | ||
| return(score1) | ||
| } | ||
|
|
||
| A_q <- scterm | ||
| B_q <- 1 | ||
| C_q <- -(score1 + scterm) | ||
| dsct <- B_q^2 - 4 * A_q * C_q | ||
| if (dsct < 0) { | ||
| # Fallback to simplified skewness correction | ||
| qtnorm <- stats::qnorm(1 - alpha / 2) | ||
| score1 <- score1 - (qtnorm^2 - 1) * scterm | ||
| } else { | ||
| score1 <- (-B_q + sqrt(dsct)) / (2 * A_q) | ||
| } | ||
|
|
||
| return(score1) | ||
| } | ||
|
|
||
| .conf_poi_rd <- function(x1, n1, x2, n2, z, lower = FALSE, | ||
| skew = FALSE, level = 0.95) { | ||
| p1 <- x1 / n1 | ||
| p2 <- x2 / n2 | ||
| p_hat <- p1 - p2 | ||
| dp <- 1 + ifelse(lower, 1, -1) * p_hat | ||
| i <- 1 | ||
| while (i <= 50) { | ||
| dp <- 0.5 * dp | ||
| y <- p_hat + ifelse(lower, -1, 1) * dp | ||
| score <- .score_poi_rd(x1, n1, x2, n2, y, skew = skew, level = level) | ||
| # For lower bound: score decreases as y moves left, find where score = +z | ||
| # -> move y further left if score > z (still too close to estimate) | ||
| # For upper bound: score decreases as y moves right, find where score = -z | ||
| # -> move y further right if score > -z (still too close to estimate) | ||
| if (lower) { | ||
| if (score < z) p_hat <- y | ||
| } else { | ||
| if (score > -z) p_hat <- y | ||
| } | ||
| if ((dp < 1e-07) || (abs(score - ifelse(lower, z, -z)) < 1e-06)) { | ||
| break | ||
| } else { | ||
| i <- i + 1 | ||
| } | ||
| } | ||
| return(y) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.