Skip to content

Commit 84576b4

Browse files
committed
update eventdata to event
1 parent d6d7df4 commit 84576b4

5 files changed

+63
-34
lines changed

R/generate_event_cc.R

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' This function generates a table of events for given experimental arms and a control group based on specified hypotheses.
22
#'
3-
#' @param event_data A dataframe containing the following columns:
3+
#' @param event A dataframe containing the following columns:
44
#' - `Population`: A character vector listing the population groups (e.g., experimental arms and control).
55
#' - `IA`: A numeric vector indicating the number of events observed in each group during interim analysis.
66
#' - `FA`: A numeric vector indicating the number of events observed in each group during final analysis.
@@ -16,7 +16,7 @@
1616
#'
1717
#' @examples
1818
#' #------------------------Example of IA and FA
19-
#' event_data <- data.frame(
19+
#' event <- data.frame(
2020
#' Population = c("Experimental 1", "Experimental 2", "Experimental 3", "Control"),
2121
#' IA = c(70, 75, 80, 85), # Interim Analysis values indicating the number of events observed in each group
2222
#' FA = c(135, 150, 165, 170)
@@ -28,10 +28,10 @@
2828
#' H3 = "Experimental 1 vs. Experimental 2"
2929
#' )
3030
#'
31-
#' generate_event_table_cc(event_data, hypothesis)
31+
#' generate_event_table_cc(event, hypothesis)
3232
#'
3333
#' #----------------------Example of two IAs and FA
34-
#' event_data <- data.frame(
34+
#' event <- data.frame(
3535
#'Population = c("Experimental 1", "Experimental 2", "Experimental 3", "Control"),
3636
#'IA1 = c(70, 75, 80, 85), # First Interim Analysis values indicating the number of events observed in each group
3737
#'IA2 = c(90, 95, 100, 105), # Second Interim Analysis values indicating the number of events observed in each group
@@ -44,9 +44,9 @@
4444
#' H3 = "Experimental 1 vs. Experimental 2"
4545
#')
4646
#'
47-
#'generate_event_table_cc(event_data, hypothesis)
47+
#'generate_event_table_cc(event, hypothesis)
4848

49-
generate_event_table_cc <- function(event_data, hypothesis) {
49+
generate_event_table_cc <- function(event, hypothesis) {
5050
result_df <- tibble(
5151
one_hypothesis = integer(),
5252
another_hypothesis = integer(),
@@ -57,25 +57,39 @@ generate_event_table_cc <- function(event_data, hypothesis) {
5757
# Iterate through the input data to calculate the events
5858
for (i in 1:length(hypothesis)) { # number of hypothesis
5959
for (j in i:length(hypothesis)) {
60-
for (k in 1:(ncol(event_data) - 1)) { # Iterate through the analyses
60+
for (k in 1:(ncol(event) - 1)) { # Iterate through the analyses
6161
if (i != j) {
6262
hyp_i <- unlist(strsplit(hypothesis[[i]], " vs. "))
6363
hyp_j <- unlist(strsplit(hypothesis[[j]], " vs. "))
6464
common_factor <- intersect(hyp_i, hyp_j)
65-
event <- event_data[event_data$Population == common_factor, k + 1]
65+
eventn <- event[event$Population == common_factor, k + 1]
6666
} else {
67-
event <- event_data[i, k + 1] + event_data[event_data$Population == "Control", k + 1]
67+
eventn <- event[i, k + 1] + event[event$Population == "Control", k + 1]
6868
}
6969

7070
result_df <- rbind(result_df, tibble(
7171
one_hypothesis = i,
7272
another_hypothesis = j,
7373
analysis = k,
74-
common_events = event
74+
common_events = eventn
7575
))
7676
result_df <- result_df[order(result_df$analysis), ]
7777
}
7878
}
7979
}
8080
return(result_df)
8181
}
82+
83+
event <- data.frame(
84+
Population = c("Experimental 1", "Experimental 2", "Experimental 3", "Control"),
85+
IA = c(70, 75, 80, 85), # Interim Analysis values indicating the number of events observed in each group
86+
FA = c(135, 150, 165, 170)
87+
)
88+
89+
hypothesis <- list(
90+
H1 = "Experimental 1 vs. Control",
91+
H2 = "Experimental 2 vs. Control",
92+
H3 = "Experimental 1 vs. Experimental 2"
93+
)
94+
95+
generate_event_table_cc(event, hypothesis)

R/generate_event_ol.R

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' This function generates a table of events for specified populations based on the provided hypotheses.
22
#'
3-
#' @param event_data` dataframe should have the following structure:
3+
#' @param event` dataframe should have the following structure:
44
#' - `Population`: A character vector indicating the population groups (e.g., "Population 1", "Population 2", "Population 1 Intersection 2", and "Overall population").
55
#' - `IA`: Numeric vector indicating the number of events observed in each group during interim analysis.
66
#' - `FA`: Numeric vector indicating the number of events observed in each group during final analysis.
@@ -21,7 +21,7 @@
2121
#'
2222
#' @examples
2323
#' #------------------------Example of IA and FA
24-
#' event_data <- data.frame(
24+
#' event <- data.frame(
2525
#' Population = c("Population 1", "Population 2", "Population 1 Intersection 2", "Overall population"),
2626
#' IA = c(100, 110, 80, 225), # Interim Analysis values indicating the number of events observed in each group
2727
#' FA = c(200, 220, 160, 450)
@@ -33,10 +33,10 @@
3333
#' H3 = "Efficacy in Overall population"
3434
#' )
3535
#'
36-
#' generate_event_table_ol(event_data, hypothesis)
36+
#' generate_event_table_ol(event, hypothesis)
3737
#'
3838
#' #----------------------Example of two IAs and FA
39-
#' event_data <- data.frame(
39+
#' event <- data.frame(
4040
#'Population = c("Population 1", "Population 2", "Population 1 Intersection 2", "Overall population"),
4141
#'IA1 = c(100, 110, 80, 225), # First Interim Analysis values indicating the number of events observed in each group
4242
#'IA2 = c(120, 130, 90, 240), # Second Interim Analysis values indicating the number of events observed in each group
@@ -49,9 +49,9 @@
4949
#' H3 = "Efficacy in Overall population"
5050
#')
5151
#'
52-
#'generate_event_table_ol(event_data, hypothesis)
52+
#'generate_event_table_ol(event, hypothesis)
5353
#'
54-
generate_event_table_ol <- function(event_data, hypothesis) {
54+
generate_event_table_ol <- function(event, hypothesis) {
5555
result_df <- tibble(
5656
one_hypothesis = integer(),
5757
another_hypothesis = integer(),
@@ -61,29 +61,29 @@ generate_event_table_ol <- function(event_data, hypothesis) {
6161

6262
for (i in 1:length(hypothesis)) {
6363
for (j in i:length(hypothesis)) {
64-
for (k in 1:(ncol(event_data) - 1)) {
64+
for (k in 1:(ncol(event) - 1)) {
6565
hyp_i <- unlist(strsplit(hypothesis[[i]], "Efficacy in "))[2]
6666
hyp_j <- unlist(strsplit(hypothesis[[j]], "Efficacy in "))[2]
6767

6868
common_factor <- intersect(hyp_i, hyp_j)
6969

7070
if (length(common_factor) > 0) {
7171
if ("Overall population" %in% c(hyp_i, hyp_j)) {
72-
event <- event_data[event_data$Population == "Overall population", k + 1]
72+
eventn <- event[event$Population == "Overall population", k + 1]
7373
} else {
74-
event <- event_data[i, k + 1]
74+
eventn <- event[i, k + 1]
7575
}
7676
} else if ("Overall population" %in% c(hyp_i, hyp_j)) {
77-
event <- event_data[i, k + 1]
77+
eventn <- event[i, k + 1]
7878
} else {
79-
event <- event_data[event_data$Population == "Population 1 Intersection 2", k + 1]
79+
eventn <- event[event$Population == "Population 1 Intersection 2", k + 1]
8080
}
8181

8282
result_df <- rbind(result_df, tibble(
8383
one_hypothesis = i,
8484
another_hypothesis = j,
8585
analysis = k,
86-
common_events = event
86+
common_events = eventn
8787
))
8888
result_df <- result_df[order(result_df$analysis), ]
8989
}
@@ -94,3 +94,18 @@ generate_event_table_ol <- function(event_data, hypothesis) {
9494
}
9595

9696

97+
event <- data.frame(
98+
Population = c("Population 1", "Population 2", "Population 1 Intersection 2", "Overall population"),
99+
IA = c(100, 110, 80, 225), # Interim Analysis values indicating the number of events observed in each group
100+
FA = c(200, 220, 160, 450)
101+
)
102+
103+
hypothesis <- list(
104+
H1 = "Efficacy in Population 1",
105+
H2 = "Efficacy in Population 2",
106+
H3 = "Efficacy in Overall population"
107+
)
108+
109+
generate_event_table_ol(event, hypothesis)
110+
111+

R/generate_event_table_.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' This function creates a table summarizing event counts based on specified hypotheses and user input data.
22
#' It can handle two types of analysis: one comparing experimental groups to a common control and another analyzing the overlap of populations.
33
#'
4-
#' @param event_data` dataframe should have the following structure:
4+
#' @param event` dataframe should have the following structure:
55
#' - `Population`: A character vector indicating the population groups. For example, "Population 1", "Population 2", "Overall population" in overlap population situation; or experimental arms and control in common control situation.
66
#' - `IA`: Numeric vector indicating the number of events observed in each group during interim analysis.
77
#' - `FA`: Numeric vector indicating the number of events observed in each group during final analysis.
@@ -25,7 +25,7 @@
2525
#'
2626
#' @examples
2727
#' # ----------------------- Example of common control
28-
#' event_data <- data.frame(
28+
#' event <- data.frame(
2929
#' Population = c("Experimental 1", "Experimental 2", "Experimental 3", "Control"),
3030
#' IA = c(70, 75, 80, 85), # Interim analysis values indicating the number of events observed in each experimental group.
3131
#' FA = c(135, 150, 165, 170) # Final analysis values indicating the cumulative number of events observed in each group.
@@ -37,10 +37,10 @@
3737
#' H3 = "Experimental 1 vs. Experimental 2" # Hypothesis comparing Experimental 1 and Experimental 2.
3838
#' )
3939
#'
40-
#' generate_event_table_(event_data, hypothesis, type = "common_control")
40+
#' generate_event_table_(event, hypothesis, type = "common_control")
4141
#'
4242
#' # ------------------------ Example of overall population
43-
#' event_data <- data.frame(
43+
#' event <- data.frame(
4444
#' Population = c("Population 1", "Population 2", "Population 1 Intersection 2", "Overall population"),
4545
#' IA = c(100, 110, 80, 225), # Interim analysis values for the overall population.
4646
#' FA = c(200, 220, 160, 450) # Final analysis values for the overall population.
@@ -52,9 +52,9 @@
5252
#' H3 = "Efficacy in Overall population" # Hypothesis assessing efficacy in the overall population.
5353
#' )
5454
#'
55-
#' generate_event_table_(event_data, hypothesis, type = "overlap_population")
55+
#' generate_event_table_(event, hypothesis, type = "overlap_population")
5656
#'
57-
generate_event_table_ <- function(event_data, hypothesis, type = c("common_control", "overlap_population")) {
57+
generate_event_table_ <- function(event, hypothesis, type = c("common_control", "overlap_population")) {
5858
type <- match.arg(type)
5959

6060
result_df <- tibble(
@@ -65,9 +65,9 @@ generate_event_table_ <- function(event_data, hypothesis, type = c("common_contr
6565
)
6666

6767
if (type == "common_control") {
68-
result_df <- generate_event_table_cc(event_data, hypothesis) # see generate_event_cc.R
68+
result_df <- generate_event_table_cc(event, hypothesis) # see generate_event_cc.R
6969
} else if (type == "overlap_population") {
70-
result_df <- generate_event_table_ol(event_data, hypothesis) # see generate_event_ol.R
70+
result_df <- generate_event_table_ol(event, hypothesis) # see generate_event_ol.R
7171
}
7272
return(result_df)
7373
}

tests/testthat/test-developer-generate_event_commoncontrol_addhypo.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test_that("Generate event table returns the expected sorted data", {
66
common_events = c(155, 85, 70, 160, 75, 165, 305, 170, 135, 320, 150, 335)
77
)
88

9-
event_data <- data.frame(
9+
event <- data.frame(
1010
Population = c("Experimental 1", "Experimental 2", "Experimental 3", "Control"),
1111
IA = c(70, 75, 80, 85),
1212
FA = c(135, 150, 165, 170)
@@ -18,7 +18,7 @@ test_that("Generate event table returns the expected sorted data", {
1818
H3 = "Experimental 1 vs. Experimental 2"
1919
)
2020

21-
result_table <- generate_event_table_cc(event_data, hypothesis)
21+
result_table <- generate_event_table_cc(event, hypothesis)
2222

2323

2424
expect_identical(result_table, expected_data)

tests/testthat/test-developer-generate_event_population_addhypo.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test_that("Generate event table ol returns the expected sorted data", {
66
common_events = c(100, 80, 100, 110, 110, 225, 200, 160, 200, 220, 220, 450)
77
)
88

9-
event_data <- data.frame(
9+
event <- data.frame(
1010
Population = c("Population 1", "Population 2", "Population 1 Intersection 2", "Overall population"),
1111
IA = c(100, 110, 80, 225),
1212
FA = c(200, 220, 160, 450)
@@ -18,7 +18,7 @@ test_that("Generate event table ol returns the expected sorted data", {
1818
H3 = "Efficacy in Overall population"
1919
)
2020

21-
result_table <- generate_event_table_ol(event_data, hypothesis)
21+
result_table <- generate_event_table_ol(event, hypothesis)
2222

2323
expect_identical(result_table, expected_data)
2424
})

0 commit comments

Comments
 (0)