Skip to content
Merged
Show file tree
Hide file tree
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 May 19, 2026
781ebba
temp commit, not yet finished
iaugusty May 19, 2026
712a9f5
update roxygen/test/disable NULL for occ_var
iaugusty May 29, 2026
704849e
update NEWS
iaugusty May 29, 2026
bb19d5c
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty May 29, 2026
2876b01
Merge branch 'dev' into feature/hotfix_eair
iaugusty May 29, 2026
fc318b7
lintr + spelling
iaugusty May 29, 2026
373a610
removed duplicated section
iaugusty May 29, 2026
8ba3f5e
lintr
iaugusty May 29, 2026
a5f3e41
retrigger CI
iaugusty May 29, 2026
50783dd
Update check_CRAN.yaml
munoztd0 May 29, 2026
0bece99
Update check_CRAN.yaml
munoztd0 Jun 1, 2026
f0d9ecb
Merge branch 'dev' into feature/hotfix_eair
munoztd0 Jun 1, 2026
280f027
Merge branch 'dev' into feature/hotfix_eair
munoztd0 Jun 1, 2026
d85aefd
Merge branch 'dev' into feature/hotfix_eair
munoztd0 Jun 1, 2026
a94bf35
Merge remote-tracking branch 'origin/dev' into feature/hotfix_eair
iaugusty Jun 5, 2026
133d097
add new approaches for conf interval for diff in rate
iaugusty Jun 5, 2026
d50b9e6
add new approach for occ_var = NULL, count_events
iaugusty Jun 9, 2026
6e1f9cb
assign cps
iaugusty Jun 9, 2026
1411f27
match precision of test a_eair_diff with snapshot version
iaugusty Jun 9, 2026
1b3cb0f
lintr
iaugusty Jun 9, 2026
ebd42dc
importFrom stats ave
iaugusty Jun 9, 2026
c1e22e9
namespace stats, ave
iaugusty Jun 9, 2026
5e2f5cb
added rateci github to suggest and added remotes
munoztd0 Jun 10, 2026
004d88f
update label behaviour depending on rowsplit or not
iaugusty Jun 11, 2026
2ecebad
a_eair_diff separate tests with ratesci from snapshot tests
iaugusty Jun 18, 2026
0277ccc
address review comments Nik
iaugusty Jun 19, 2026
93bfe16
remotes pharmaverseadamjnj for test test-summarize_ancova
iaugusty Jun 19, 2026
6388019
Merge remote-tracking branch 'origin/dev' into feature/hotfix_eair
iaugusty Jun 19, 2026
5b82f2a
lintr
iaugusty Jun 19, 2026
2e4850f
Merge branch 'dev' into feature/hotfix_eair
munoztd0 Jun 22, 2026
73f2931
Several updates
iaugusty Jun 25, 2026
f706c85
Merge remote-tracking branch 'origin/dev' into feature/hotfix_eair
iaugusty Jun 25, 2026
6a5a76a
spell and lintr
iaugusty Jun 25, 2026
9b58932
fix : ! subscript out of bounds
munoztd0 Jun 25, 2026
46be3fc
pass ref_col_expr NULL when not relevant
iaugusty Jun 25, 2026
0a39219
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty Jun 25, 2026
4f1b5b6
fix: tests
munoztd0 Jun 25, 2026
569f48c
lintr
munoztd0 Jun 25, 2026
847d2e8
update: test accroding to new ratesci updates
munoztd0 Jun 25, 2026
cf187c1
update: test to data pahrmaverse
munoztd0 Jun 25, 2026
799aac2
- introduced new helper function for riskdiff setup
iaugusty Jun 29, 2026
294935d
style + lint
iaugusty Jun 29, 2026
84e5918
style + lint
iaugusty Jun 29, 2026
26ae5f4
update snapshot after lintr
iaugusty Jun 29, 2026
1d51bf0
update to new CRAN release fo ratesci
munoztd0 Jul 3, 2026
319a791
Merge remote-tracking branch 'origin/feature/hotfix_eair' into featur…
munoztd0 Jul 3, 2026
94f65c0
Merge branch 'dev' into feature/hotfix_eair
iaugusty Jul 3, 2026
dbf45d4
h_incidence_rate tern got exported
iaugusty Jul 6, 2026
8ee011e
new function a_eair_strat_j
iaugusty Jul 6, 2026
586c232
spellcheck
iaugusty Jul 6, 2026
cbdda69
allow scoring to be performed on other than first number in cellvalue…
iaugusty Jul 7, 2026
f6368b0
temp commit, not yet finished
iaugusty May 19, 2026
3b050c2
update roxygen/test/disable NULL for occ_var
iaugusty May 29, 2026
163e2c4
update NEWS
iaugusty May 29, 2026
a69bfd1
temp commit, not yet finished
iaugusty May 19, 2026
f6cc18e
lintr + spelling
iaugusty May 29, 2026
f3a1d92
lintr
iaugusty May 29, 2026
ee7ce30
retrigger CI
iaugusty May 29, 2026
171c469
Update check_CRAN.yaml
munoztd0 Jun 1, 2026
fe7be26
add new approaches for conf interval for diff in rate
iaugusty Jun 5, 2026
f985b20
add new approach for occ_var = NULL, count_events
iaugusty Jun 9, 2026
4fa7b50
assign cps
iaugusty Jun 9, 2026
d25e5a8
match precision of test a_eair_diff with snapshot version
iaugusty Jun 9, 2026
4f76d89
lintr
iaugusty Jun 9, 2026
b99e707
importFrom stats ave
iaugusty Jun 9, 2026
4fd1933
namespace stats, ave
iaugusty Jun 9, 2026
3ae4c4b
added rateci github to suggest and added remotes
munoztd0 Jun 10, 2026
8abd51e
update label behaviour depending on rowsplit or not
iaugusty Jun 11, 2026
7bde155
update to new CRAN release fo ratesci
munoztd0 Jul 3, 2026
1bf6155
a_eair_diff separate tests with ratesci from snapshot tests
iaugusty Jun 18, 2026
71b883b
address review comments Nik
iaugusty Jun 19, 2026
3185f18
remotes pharmaverseadamjnj for test test-summarize_ancova
iaugusty Jun 19, 2026
f4c5482
lintr
iaugusty Jun 19, 2026
9c42639
Several updates
iaugusty Jun 25, 2026
cf04e53
spell and lintr
iaugusty Jun 25, 2026
8e7a13d
pass ref_col_expr NULL when not relevant
iaugusty Jun 25, 2026
56814da
fix : ! subscript out of bounds
munoztd0 Jun 25, 2026
a2a0306
fix: tests
munoztd0 Jun 25, 2026
b49ce10
lintr
munoztd0 Jun 25, 2026
d12166e
update: test accroding to new ratesci updates
munoztd0 Jun 25, 2026
7d7e055
update: test to data pahrmaverse
munoztd0 Jun 25, 2026
833e478
- introduced new helper function for riskdiff setup
iaugusty Jun 29, 2026
a8503b1
style + lint
iaugusty Jun 29, 2026
5a94fff
style + lint
iaugusty Jun 29, 2026
2c88f5f
update snapshot after lintr
iaugusty Jun 29, 2026
b047591
h_incidence_rate tern got exported
iaugusty Jul 6, 2026
d7050e6
new function a_eair_strat_j
iaugusty Jul 6, 2026
65100e0
spellcheck
iaugusty Jul 6, 2026
1076583
allow scoring to be performed on other than first number in cellvalue…
iaugusty Jul 7, 2026
15a1e6c
in_ref_col() - support ref_path = NULL, minor variables change in uni…
wwojciech Jul 15, 2026
575858c
fix merge issues with rebase on dev
munoztd0 Jul 15, 2026
da2294c
fix: lintr
munoztd0 Jul 15, 2026
e2e832a
Update R/utils.R
iaugusty Jul 16, 2026
bad3e53
Update utils.R
munoztd0 Jul 16, 2026
d66e786
merge + lintr
iaugusty Jul 16, 2026
b6e9c2d
lintr
iaugusty Jul 16, 2026
7261f8a
Merge branch 'dev' into feature/hotfix_eair
munoztd0 Jul 16, 2026
ad77deb
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty Jul 16, 2026
a0f5f5e
Merge branch 'feature/hotfix_eair' of https://github.com/johnsonandjo…
iaugusty Jul 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/check_CRAN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
needs: check

- uses: r-lib/actions/check-r-package@v2
timeout-minutes: 10
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
Expand Down
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ Suggests:
pharmaverseadamjnj (>= 0.0.2),
multcomp,
lifecycle,
dplyr
dplyr,
ratesci (>= 1.1.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
Remotes:
insightsengineering/formatters@main,
insightsengineering/tern@main,
petelaud/ratesci@master,
johnsonandjohnson/pharmaverseadamjnj@dev,
Comment thread
munoztd0 marked this conversation as resolved.
insightsengineering/rtables@main,
insightsengineering/rtables.officer@main
Config/roxygen2/version: 8.0.0
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(a_cmhrms_j_with_exclude)
export(a_coxph_hr)
export(a_diff_means)
export(a_eair100_j)
export(a_eair_strat_j)
export(a_event_free)
export(a_freq_combos_j)
export(a_freq_j)
Expand Down Expand Up @@ -160,6 +161,7 @@ importFrom(formatters,wrap_string_ttype)
importFrom(generics,tidy)
importFrom(rtables,in_rows)
importFrom(rtables,rcell)
importFrom(stats,ave)
importFrom(stats,complete.cases)
importFrom(stats,setNames)
importFrom(stats,t.test)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Reduce sampling of `rbmi` test to make tests shorter (#323)
- Optimize shared tables in `test-tt_to_tblfile` (#323)
- Changed forked `h_ancova` for the `tern` one
- Add extra statistics to `a_eair100_j` and introduce scaling factor `num_p_year` (default = 100) (#361)
- Removed ellipsis argument from `a_freq_resp_var_j` (#236)
- Removed `dplyr` from `junco` and replaced by base R #201
- Replaced `assertthat` by `checkmate` for consistency #201
Expand All @@ -36,6 +37,7 @@
- Use new exported splv_extra and value_expr accessors (insightsengineering#1098)
- Update new exported calls from rtables.officer
- update documentation to `roxygen2` 8.0.0
- Add extra statistics to `a_eair100_j` and introduce scaling factor `num_p_year` (default = 100) (#361)

### Added
- Added `categorize_pval()` for assigning p-values to validated, user-defined categories.
Expand Down
142 changes: 142 additions & 0 deletions R/a_eair_diff.R
Comment thread
iaugusty marked this conversation as resolved.
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be relatively optimistic that we have these 3 in tern already implemented - did you have a look already?

scas = h_s_eair_diff_mn(x1, n1, x2, n2, conf_level, skew = TRUE)
Comment thread
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)
}
Loading
Loading