Skip to content

Commit

Permalink
rev
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeJSeo committed Jul 21, 2024
1 parent db8d149 commit 899fdca
Show file tree
Hide file tree
Showing 27 changed files with 197 additions and 930 deletions.
2 changes: 1 addition & 1 deletion R/bucher.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ print.maicplus_bucher <- function(x, ci_digits = 2, pval_digits = 3,
#' @param exponentiate whether the treatment effect and confidence
#' interval should be exponentiated. This applies to relative
#' treatment effects. Default is set to false.

#' @keywords internal

reformat <- function(x, ci_digits = 2, pval_digits = 3,
show_pval = TRUE, exponentiate = FALSE) {
Expand Down
1 change: 1 addition & 0 deletions R/maic_unanchored.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#' @importFrom sandwich vcovHC
#' @importFrom boot boot boot.ci
#' @return A list, contains 'descriptive' and 'inferential'
#' @example inst/examples/maic_anchored_ex.R
#' @export

maic_unanchored <- function(weights_object,
Expand Down
3 changes: 2 additions & 1 deletion R/process_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ dummize_ipd <- function(raw_ipd, dummize_cols, dummize_ref_level) {
#' should be followed by legal suffixes (i.e. MEAN, MEDIAN, SD, or PROP). Note that COUNT
#' suffix is no longer accepted.
#' @examples
#' # load in IPD
#' data(adsl_sat)
#' data(agd)
#' agd <- process_agd(agd)
#' ipd_centered <- center_ipd(ipd = adsl_sat, agd = agd)
#' @return centered ipd using aggregate level data averages
#' @export
Expand Down Expand Up @@ -238,6 +238,7 @@ complete_agd <- function(use_agd) {
#' @param trt values to include in treatment column
#'
#' @return a data frame that can be used as input to `survival::Surv`
#' @keywords internal

ext_tte_transfer <- function(dd, time_scale = "months", trt = NULL) {
time_scale <- match.arg(time_scale, choices = c("years", "months", "weeks", "days"))
Expand Down
6 changes: 3 additions & 3 deletions R/reporting.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @return a data frame with sample size, incidence rate, median survival time with 95% CI, hazard ratio estimate with
#' 95% CI and Wald test of hazard ratio
#'
#' @example inst/examples/report_table_tte_ex.R
#' @export

report_table_tte <- function(coxobj, medSurvobj, tag = NULL) {
Expand Down Expand Up @@ -51,13 +51,13 @@ report_table_tte <- function(coxobj, medSurvobj, tag = NULL) {
#' helper function: sort out a nice report table to summarize binary analysis results
#'
#' @param binobj object from glm()
#' @param weighted_result object res_AB
#' @param weighted_result weighted result object

Check warning on line 54 in R/reporting.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/reporting.R,line=54,col=49,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @param eff_measure a string, binary effect measure, could be "OR", "RR", "RD"
#' @param tag a string, by default NULL, if specified, an extra 1st column is created in the output
#'
#' @return a data frame with sample size, incidence rate, estimate of binary effect measure with
#' 95% CI and Wald test of hazard ratio
#'
#' @example inst/examples/report_table_binary_ex.R
#' @export

report_table_binary <- function(binobj, weighted_result = NULL, eff_measure = c("OR", "RD", "RR"), tag = NULL) {
Expand Down
4 changes: 1 addition & 3 deletions R/survival-helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
#' @examples
#' data(adtte_sat)
#' data(pseudo_ipd_sat)
#'
#' combined_data <- rbind(adtte_sat[, c("TIME", "EVENT", "ARM")], pseudo_ipd_sat)
#' kmobj <- survfit(Surv(TIME, EVENT) ~ ARM, combined_data, conf.type = "log-log")
#' kmdat <- do.call(rbind, survfit_makeup(kmobj))
#' kmdat$treatment <- factor(kmdat$treatment)
#'
#' # Derive median survival time
#' medSurv <- medSurv_makeup(kmobj, legend = "before matching", time_scale = "day")
Expand Down
1 change: 0 additions & 1 deletion R/time-helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ settings_env <- new.env()
#' # The default time scale is days:
#' set_time_conversion(default = "days", days = 1, weeks = 7, months = 365.25 / 12, years = 365.25)
#'
#'
#' # Set the default time scale to years
#' set_time_conversion(
#' default = "years",
Expand Down
2 changes: 1 addition & 1 deletion inst/examples/kmplot2_anchored_ex.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# anchored example using kmplot
# anchored example using kmplot2

data(weighted_twt)
data(adtte_twt)
Expand Down
33 changes: 33 additions & 0 deletions inst/examples/maic_anchored_binary_ex.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Anchored example using maic_anchored for binary outcome

data(weighted_twt)
data(adtte_twt)
data(pseudo_ipd_twt)

# Reported summary data
pseudo_adrs <- get_pseudo_ipd_binary(
binary_agd = data.frame(
ARM = c("B", "C", "B", "C"),
RESPONSE = c("YES", "YES", "NO", "NO"),
COUNT = c(280, 120, 200, 200)
),
format = "stacked"
)

# inferential result
result_binary <- maic_anchored(
weights_object = weighted_twt,
ipd = adrs_twt,
pseudo_ipd = pseudo_adrs,
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
endpoint_name = "Binary Event",
endpoint_type = "binary",
eff_measure = "OR"
)

result_binary$inferential$report_overall_robustCI
result_binary$inferential$report_overall_bootCI
43 changes: 4 additions & 39 deletions inst/examples/maic_anchored_ex.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,14 @@
# Anchored example using maic_anchored for binary outcome

# weighted_twt # weighted patient level data from estimate_weights()
# adrs_twt # patient level outcome data
# pseudo_adrs # pseudo patient level outcome data from publication

# Reported summary data
pseudo_adrs <- get_pseudo_ipd_binary(
binary_agd = data.frame(
ARM = c("B", "C", "B", "C"),
RESPONSE = c("YES", "YES", "NO", "NO"),
COUNT = c(280, 120, 200, 200)
),
format = "stacked"
)

# inferential result
result_binary <- maic_anchored(
weights_object = weighted_twt,
ipd = adrs_twt,
trt_var_ipd = "ARM",
pseudo_ipd = pseudo_adrs,
trt_var_agd = "ARM",
trt_ipd = "A",
trt_agd = "B",
trt_common = "C",
endpoint_name = "Binary Event",
endpoint_type = "binary",
eff_measure = "OR"
)

result_binary$inferential$report_overall_robustCI
result_binary$inferential$report_overall_bootCI


# Anchored example using maic_anchored for time-to-event data

# weighted_twt # weighted patient level data from estimate_weights()
# adtte_twt # two arm patient level time-to-event data
# pseudo_ipd_twt # digitised time-to-event data
data(weighted_twt)
data(adtte_twt)
data(pseudo_ipd_twt)

result_tte <- maic_anchored(
weights_object = weighted_twt,
ipd = adtte_twt,
trt_var_ipd = "ARM",
pseudo_ipd = pseudo_ipd_twt,
trt_var_ipd = "ARM",
trt_var_agd = "ARM",
trt_ipd = "A",
trt_agd = "B",
Expand Down
13 changes: 13 additions & 0 deletions inst/examples/report_table_binary_ex.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
data(adrs_sat)

testdat <- data.frame(Yes = 280, No = 120)
rownames(testdat) <- "B"
pseudo_ipd_binary_sat <- get_pseudo_ipd_binary(
binary_agd = testdat,
format = "unstacked"
)
combined_data <- rbind(adrs_sat[, c("USUBJID", "RESPONSE", "ARM")], pseudo_ipd_binary_sat)
combined_data$ARM <- as.factor(combined_data$ARM)

binobj_dat <- glm(RESPONSE ~ ARM, combined_data, family = binomial(link = "logit"))
report_table_binary(binobj_dat, eff_measure = "OR")
10 changes: 10 additions & 0 deletions inst/examples/report_table_tte_ex.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data(adtte_sat)
data(pseudo_ipd_sat)
combined_data <- rbind(adtte_sat[, c("TIME", "EVENT", "ARM")], pseudo_ipd_sat)
unweighted_cox <- coxph(Surv(TIME, EVENT == 1) ~ ARM, data = combined_data)

# Derive median survival time
kmobj <- survfit(Surv(TIME, EVENT) ~ ARM, combined_data, conf.type = "log-log")
medSurv <- medSurv_makeup(kmobj, legend = "before matching", time_scale = "day")

report_table_tte(unweighted_cox, medSurv)

Check warning on line 10 in inst/examples/report_table_tte_ex.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=inst/examples/report_table_tte_ex.R,line=10,col=42,[trailing_blank_lines_linter] Missing terminal newline.
2 changes: 1 addition & 1 deletion man/center_ipd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ext_tte_transfer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/kmplot2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 4 additions & 39 deletions man/maic_anchored.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions man/maic_unanchored.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/medSurv_makeup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/reformat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion man/report_table_binary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions man/report_table_tte.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/time_conversion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified tests/testthat/data/test_binary_unanchored_expected.RData
Binary file not shown.
Binary file modified tests/testthat/data/test_tte_unanchored_expected.RData
Binary file not shown.
Loading

0 comments on commit 899fdca

Please sign in to comment.