Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ setImgSrc.js
\.github
RELEASE_BODY\.txt
^\.github$
^cran-plan\.md$
^tools$
27 changes: 14 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: chefStats
Title: Provide methods for different statistics
Title: Provide Methods for Different Statistics
Version: 0.1.1
Authors@R:
c(person(given = "Matthew David Phelps",
Expand All @@ -22,14 +22,19 @@ Authors@R:
email = "cino@novonordisk.com"),
person(given = "Novo Nordisk A/S",
role = "cph"))
Maintainer: Christian Haargaard Olsen <cino@novonordisk.com>
Description: Provide a library of methods that can be used to calculate different statistics.
Description: Provides a library of statistical methods for use in clinical trial evidence
generation workflows. Functions cover subject counts, event rates, odds ratios,
relative risks, risk differences, p-values, and demographic summaries, all
formatted for use with the 'chef' pipeline framework. Designed to support
healthcare technology assessments such as AMNOG dossier submissions.
License: MIT + file LICENSE
BugReports: https://github.com/hta-pharma/chefStats/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Remotes:
hta-pharma/chef@feature/CRAN_submission
Suggests:
testr,
covr,
pkgdown,
testthat,
Expand All @@ -39,7 +44,8 @@ Suggests:
pharmaverseadam,
tidyr,
purrr,
kableExtra
kableExtra,
withr
Imports:
Barnard,
stats,
Expand All @@ -48,14 +54,9 @@ Imports:
checkmate,
cli,
usethis,
DescTools
Remotes:
hta-pharma/chef,
matthew-phelps/testr
DescTools
Config/testthat/edition: 3
VignetteBuilder: knitr
Config/testthat/parallel: true
URL:
https://hta-pharma.github.io/chefStats/,
https://github.com/hta-pharma/chefStats,
https://app.codecov.io/github/hta-pharma/chefStats
URL: https://hta-pharma.github.io/chefStats/,
https://github.com/hta-pharma/chefStats
1 change: 1 addition & 0 deletions R/BreslowDayFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @return A vector with three values statistic - Breslow and Day test
#' statistic pval - p value evtl. based on the Tarone test statistic using a
#' \eqn{\chi^2(K-1)} distribution
#' @keywords internal
breslowdaytest_ <- function(x, odds_ratio = NA, correct = FALSE) {

# Call the BreslowDayTest from the DescTools package
Expand Down
20 changes: 19 additions & 1 deletion R/across_strata_across_trt.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
#'
#' @return A data.table containing the statistics for p-value interaction tests.
#' @export
#' @examples
#' dat <- data.table::data.table(
#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8"),
#' TRT = c("Active", "Active", "Active", "Active",
#' "Placebo", "Placebo", "Placebo", "Placebo"),
#' STRATA = c("M", "M", "F", "F", "M", "M", "F", "F")
#' )
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' p_val_interaction(dat, event_index = c(1L, 3L, 5L, 7L),
#' treatment_var = "TRT", treatment_refval = "Placebo",
#' subjectid_var = "USUBJID", strata_var = "STRATA")
p_val_interaction <- function(dat,
event_index,
treatment_var,
Expand Down Expand Up @@ -69,7 +81,13 @@ p_val_interaction <- function(dat,
#' @param ... optional arguments to
#' @return A list containing Hedges G statistics.
#' @export
#'
#' @examples
#' dat <- data.table::data.table(
#' treatment_val = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo"),
#' stat_var = rep(c("N_sub", "mean_value", "sd_value"), 2),
#' stat_val = c(50, 12.3, 2.1, 50, 10.1, 2.5)
#' )
#' hedges_g(dat, reference_val = "Placebo")
hedges_g <-
function(dat, reference_val, safe_mode = FALSE, ...) {
n_trt <-
Expand Down
1 change: 1 addition & 0 deletions R/barnard_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' error (default), or return an NA (safe_mode = FALSE)
#'
#' @return 2-sided p-value for the Barnards Unconditional Exact test
#' @keywords internal
#' @importFrom Barnard barnard.test

barnard_test_ <-
Expand Down
33 changes: 27 additions & 6 deletions R/building_blocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
#'
#' @param cell_index A vector of integers referencing the rows of `dat` (as
#' specified by the `INDEX_` column in `dat`) that match the population to be
#' analyzed. See the "Endpoint Events" vignette in {ramnog} for more
#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} for more
#' information.
#' @param subjectid_var character. Name of the subject identifier variable in
#' the data (default is "USUBJID").
#' @param dat data.table. The analysis data set.
#'
#' @return An integer
#' @export
#'
#' @examples
#' dat <- data.table::data.table(
#' USUBJID = c("S1", "S2", "S3"),
#' VALUE = c(1.1, 2.2, 3.3)
#' )
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' n_subj_(dat, cell_index = dat[["INDEX_"]], subjectid_var = "USUBJID")
n_subj_ <-
function(dat,
cell_index,
Expand All @@ -28,7 +35,11 @@ n_subj_ <-
#'
#' @return an integer value
#' @export
#'
#' @examples
#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3"))
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' n_event_(dat, intersect_index = c(1L, 2L))
n_event_ <- function(dat, intersect_index) {
dat[list(intersect_index)] |>
NROW()
Expand All @@ -46,7 +57,11 @@ n_event_ <- function(dat, intersect_index) {
#'
#' @return an interger value
#' @export
#'
#' @examples
#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3"))
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' n_subj_event_(dat, intersect_index = c(1L, 2L), subjectid_var = "USUBJID")
n_subj_event_ <- function(dat, intersect_index, subjectid_var) {
dat[list(intersect_index)] |>
data.table::uniqueN(by = subjectid_var)
Expand All @@ -57,7 +72,7 @@ n_subj_event_ <- function(dat, intersect_index, subjectid_var) {
#' @param dat data.table. The analysis data set.
#' @param cell_index A vector of integers referencing the rows of `dat` (as
#' specified by the `INDEX_` column in `dat`) that match the population to be
#' analyzed. See the "Endpoint Events" vignette in {ramnog} for more
#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog} for more
#' information.
#' @param intersect_index A vector of intergers referencing the rows of `dat`
#' that match both (1) the population to be analyzed and (2) the defenition of
Expand All @@ -66,7 +81,13 @@ n_subj_event_ <- function(dat, intersect_index, subjectid_var) {
#' the data (default is "USUBJID").
#'
#' @return an integer value
#' @export
#' @export
#' @examples
#' dat <- data.table::data.table(USUBJID = c("S1", "S2", "S3"))
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' p_subj_event_(dat, cell_index = 1:3, intersect_index = c(1L, 2L),
#' subjectid_var = "USUBJID")
p_subj_event_ <-
function(dat,
cell_index,
Expand Down
48 changes: 44 additions & 4 deletions R/by_strata_across_trt.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' `dat`.
#' @param cell_index A vector of integers referencing the rows of `dat` (as
#' specified by the `INDEX_` column in `dat`) that match the population to be
#' analyzed. See the "Endpoint Events" vignette in {ramnog}
#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog}
#' for more information.
#' @param treatment_var character. The name of the treatment variable in the data.
#' @param treatment_refval character. The reference value of the treatment variable in the data.
Expand All @@ -18,6 +18,16 @@
#'
#' @return A data.table containing Relative Risk statistics.
#' @export
#' @examples
#' dat <- data.table::data.table(
#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6"),
#' TRT = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo")
#' )
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' RR(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]],
#' treatment_var = "TRT", treatment_refval = "Placebo",
#' subjectid_var = "USUBJID")
RR <- function(dat,
event_index,
cell_index,
Expand Down Expand Up @@ -66,7 +76,7 @@ RR <- function(dat,
#' `dat`.
#' @param cell_index A vector of integers referencing the rows of `dat` (as
#' specified by the `INDEX_` column in `dat`) that match the population to be
#' analyzed. See the "Endpoint Events" vignette in {ramnog}
#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog}
#' for more information.
#' @param treatment_var character. The name of the treatment variable in the data.
#' @param treatment_refval character. The reference value of the treatment variable in the data.
Expand All @@ -75,6 +85,16 @@ RR <- function(dat,
#'
#' @return A data.table containing Odds Ratio statistics.
#' @export
#' @examples
#' dat <- data.table::data.table(
#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6"),
#' TRT = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo")
#' )
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' OR(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]],
#' treatment_var = "TRT", treatment_refval = "Placebo",
#' subjectid_var = "USUBJID")
OR <- function(dat,
event_index,
cell_index,
Expand Down Expand Up @@ -124,7 +144,7 @@ OR <- function(dat,
#' `dat`.
#' @param cell_index A vector of integers referencing the rows of `dat` (as
#' specified by the `INDEX_` column in `dat`) that match the population to be
#' analyzed. See the "Endpoint Events" vignette in {ramnog}
#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog}
#' for more information.
#' @param treatment_var character. The name of the treatment variable in the data.
#' @param treatment_refval character. The reference value of the treatment variable in the data.
Expand All @@ -134,6 +154,16 @@ OR <- function(dat,
#'
#' @return A data.table containing Risk Difference statistics.
#' @export
#' @examples
#' dat <- data.table::data.table(
#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6"),
#' TRT = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo")
#' )
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' RD(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]],
#' treatment_var = "TRT", treatment_refval = "Placebo",
#' subjectid_var = "USUBJID")
RD <- function(dat,
event_index,
cell_index,
Expand Down Expand Up @@ -184,7 +214,7 @@ RD <- function(dat,
#' `dat`.
#' @param cell_index A vector of integers referencing the rows of `dat` (as
#' specified by the `INDEX_` column in `dat`) that match the population to be
#' analyzed. See the "Endpoint Events" vignette in {ramnog}
#' analyzed. See the "Endpoint Events" vignette in \pkg{ramnog}
#' for more information.
#' @param safe_mode Boolean determing if the function should fail when given
#' input that cannot be calculated (`safe_mode = TRUE`), or if it should silently return a `NA` value (default).
Expand All @@ -196,6 +226,16 @@ RD <- function(dat,
#' @param ... Optional parameters.
#' @return A data.table containing p-value statistics.
#' @export
#' @examples
#' dat <- data.table::data.table(
#' USUBJID = c("S1", "S2", "S3", "S4", "S5", "S6"),
#' TRT = c("Active", "Active", "Active", "Placebo", "Placebo", "Placebo")
#' )
#' dat[, INDEX_ := .I]
#' data.table::setkey(dat, INDEX_)
#' p_val(dat, event_index = c(1L, 2L, 4L), cell_index = dat[["INDEX_"]],
#' treatment_var = "TRT", treatment_refval = "Placebo",
#' subjectid_var = "USUBJID")
p_val <-
function(dat,
event_index,
Expand Down
Loading
Loading