Skip to content

Commit 16c0aea

Browse files
committed
eventdata to event
Merge branch 'Event_Table' of https://github.com/Merck/wpgsd into Event_Table # Conflicts: # R/generate_event_cc.R # R/generate_event_ol.R # R/generate_event_table_.R # tests/testthat/test-developer-generate_event_commoncontrol_addhypo.R # tests/testthat/test-developer-generate_event_population_addhypo.R
2 parents 84576b4 + 84e0755 commit 16c0aea

8 files changed

+50
-315
lines changed

R/generate_event_cc.R

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,27 @@
3232
#'
3333
#' #----------------------Example of two IAs and FA
3434
#' event <- data.frame(
35-
#'Population = c("Experimental 1", "Experimental 2", "Experimental 3", "Control"),
36-
#'IA1 = c(70, 75, 80, 85), # First Interim Analysis values indicating the number of events observed in each group
37-
#'IA2 = c(90, 95, 100, 105), # Second Interim Analysis values indicating the number of events observed in each group
38-
#'FA = c(135, 150, 165, 170)
39-
#')
35+
#' Population = c("Experimental 1", "Experimental 2", "Experimental 3", "Control"),
36+
#' IA1 = c(70, 75, 80, 85), # First Interim Analysis values indicating the number of events observed in each group
37+
#' IA2 = c(90, 95, 100, 105), # Second Interim Analysis values indicating the number of events observed in each group
38+
#' FA = c(135, 150, 165, 170)
39+
#' )
4040
#'
41-
#'hypothesis <- list(
42-
#' H1 = "Experimental 1 vs. Control",
43-
#' H2 = "Experimental 2 vs. Control",
44-
#' H3 = "Experimental 1 vs. Experimental 2"
45-
#')
41+
#' hypothesis <- list(
42+
#' H1 = "Experimental 1 vs. Control",
43+
#' H2 = "Experimental 2 vs. Control",
44+
#' H3 = "Experimental 1 vs. Experimental 2"
45+
#' )
4646
#'
47-
#'generate_event_table_cc(event, hypothesis)
48-
47+
#' generate_event_table_cc(event, hypothesis)
4948
generate_event_table_cc <- function(event, hypothesis) {
5049
result_df <- tibble(
5150
one_hypothesis = integer(),
5251
another_hypothesis = integer(),
5352
analysis = integer(),
5453
common_events = integer()
5554
)
56-
55+
5756
# Iterate through the input data to calculate the events
5857
for (i in 1:length(hypothesis)) { # number of hypothesis
5958
for (j in i:length(hypothesis)) {
@@ -66,7 +65,7 @@ generate_event_table_cc <- function(event, hypothesis) {
6665
} else {
6766
eventn <- event[i, k + 1] + event[event$Population == "Control", k + 1]
6867
}
69-
68+
7069
result_df <- rbind(result_df, tibble(
7170
one_hypothesis = i,
7271
another_hypothesis = j,
@@ -78,18 +77,4 @@ generate_event_table_cc <- function(event, hypothesis) {
7877
}
7978
}
8079
return(result_df)
81-
}
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)
80+
}

R/generate_event_cc_addhypo.R

Lines changed: 0 additions & 64 deletions
This file was deleted.

R/generate_event_ol.R

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@
3434
#' )
3535
#'
3636
#' generate_event_table_ol(event, hypothesis)
37-
#'
37+
#'
3838
#' #----------------------Example of two IAs and FA
3939
#' event <- data.frame(
40-
#'Population = c("Population 1", "Population 2", "Population 1 Intersection 2", "Overall population"),
41-
#'IA1 = c(100, 110, 80, 225), # First Interim Analysis values indicating the number of events observed in each group
42-
#'IA2 = c(120, 130, 90, 240), # Second Interim Analysis values indicating the number of events observed in each group
43-
#'FA = c(200, 220, 160, 450)
44-
#')
40+
#' Population = c("Population 1", "Population 2", "Population 1 Intersection 2", "Overall population"),
41+
#' IA1 = c(100, 110, 80, 225), # First Interim Analysis values indicating the number of events observed in each group
42+
#' IA2 = c(120, 130, 90, 240), # Second Interim Analysis values indicating the number of events observed in each group
43+
#' FA = c(200, 220, 160, 450)
44+
#' )
4545
#'
46-
#'hypothesis <- list(
47-
#' H1 = "Efficacy in Population 1",
48-
#' H2 = "Efficacy in Population 2",
49-
#' H3 = "Efficacy in Overall population"
50-
#')
46+
#' hypothesis <- list(
47+
#' H1 = "Efficacy in Population 1",
48+
#' H2 = "Efficacy in Population 2",
49+
#' H3 = "Efficacy in Overall population"
50+
#' )
5151
#'
52-
#'generate_event_table_ol(event, hypothesis)
52+
#' generate_event_table_ol(event, hypothesis)
5353
#'
5454
generate_event_table_ol <- function(event, hypothesis) {
5555
result_df <- tibble(
@@ -58,15 +58,15 @@ generate_event_table_ol <- function(event, hypothesis) {
5858
analysis = integer(),
5959
common_events = integer()
6060
)
61-
61+
6262
for (i in 1:length(hypothesis)) {
6363
for (j in i:length(hypothesis)) {
6464
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]
67-
67+
6868
common_factor <- intersect(hyp_i, hyp_j)
69-
69+
7070
if (length(common_factor) > 0) {
7171
if ("Overall population" %in% c(hyp_i, hyp_j)) {
7272
eventn <- event[event$Population == "Overall population", k + 1]
@@ -78,7 +78,7 @@ generate_event_table_ol <- function(event, hypothesis) {
7878
} else {
7979
eventn <- event[event$Population == "Population 1 Intersection 2", k + 1]
8080
}
81-
81+
8282
result_df <- rbind(result_df, tibble(
8383
one_hypothesis = i,
8484
another_hypothesis = j,
@@ -89,23 +89,6 @@ generate_event_table_ol <- function(event, hypothesis) {
8989
}
9090
}
9191
}
92-
92+
9393
return(result_df)
94-
}
95-
96-
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-
94+
}

R/generate_event_ol_addhypo.R

Lines changed: 0 additions & 95 deletions
This file was deleted.

R/generate_event_table_.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@
5656
#'
5757
generate_event_table_ <- function(event, hypothesis, type = c("common_control", "overlap_population")) {
5858
type <- match.arg(type)
59-
59+
6060
result_df <- tibble(
6161
one_hypothesis = integer(),
6262
another_hypothesis = integer(),
6363
analysis = integer(),
6464
common_events = integer()
6565
)
66-
66+
6767
if (type == "common_control") {
6868
result_df <- generate_event_table_cc(event, hypothesis) # see generate_event_cc.R
6969
} else if (type == "overlap_population") {
7070
result_df <- generate_event_table_ol(event, hypothesis) # see generate_event_ol.R
7171
}
7272
return(result_df)
73-
}
73+
}

0 commit comments

Comments
 (0)