Skip to content

Commit

Permalink
Update kmg01 usage after g_km refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Mar 21, 2024
1 parent 656e5d5 commit e4c2241
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Imports:
rlistings (>= 0.2.7),
rtables (>= 0.6.6),
stringr (>= 1.4.1),
tern (>= 0.9.3.9002),
tern (>= 0.9.3.9027),
tibble (>= 2.0.0),
utils
Suggests:
Expand Down
5 changes: 2 additions & 3 deletions R/kmg01.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ kmg01_main <- function(adam_db,
variables = variables,
control_surv = control_surv,
control_coxph_pw = control_cox,
...,
draw = FALSE
...
)
}

Expand Down Expand Up @@ -82,7 +81,7 @@ kmg01_pre <- function(adam_db, dataset = "adtte", ...) {
#' )
#'
#' pre_data <- log_filter(syn_data, PARAMCD == "OS", "adtte")
#' run(kmg01, pre_data, dataset = "adtte", line_col = col)
#' run(kmg01, pre_data, dataset = "adtte", col = col)
kmg01 <- chevron_g(
main = kmg01_main,
preprocess = kmg01_pre
Expand Down
19 changes: 9 additions & 10 deletions tests/testthat/test-kmg01.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("kmg01 works as expected", {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
pre_data <- expect_silent(kmg01_pre(filter_data, dataset = "adtte"))
raw_res <- expect_silent(kmg01_main(pre_data, dataset = "adtte"))
expect_true(grid::is.grob(raw_res))
expect_true(ggplot2::is.ggplot(raw_res))
})

# kmg01 ----
Expand All @@ -18,9 +18,9 @@ test_that("kmg01 works as expected with custom color set", {

filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data, dataset = "adtte", col = col))
expect_true(grid::is.grob(res))
expect_true(ggplot2::is.ggplot(res))
res <- expect_silent(run(kmg01, filter_data, dataset = "adtte", col = unname(col)))
expect_true(grid::is.grob(res))
expect_true(ggplot2::is.ggplot(res))
})

test_that("kmg01 works if change pvalue, ties and conf level", {
Expand All @@ -31,26 +31,25 @@ test_that("kmg01 works if change pvalue, ties and conf level", {
ties = "efron",
conf_level = 0.99
))
expect_true(grid::is.grob(res))
expect_true(ggplot2::is.ggplot(res))
})


test_that("kmg01 works if change annotation position", {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte", annot_surv_med = FALSE,
position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7)
dataset = "adtte", annot_surv_med = FALSE, annot_coxph = TRUE,
control_annot_coxph = control_coxph_annot(x = 0.78, y = 0.9)
))
expect_true(grid::is.grob(res))
expect_true(ggplot2::is.ggplot(res))
})


test_that("kmg01 works for stratified anlaysis", {
test_that("kmg01 works for stratified analysis", {
filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte")
res <- expect_silent(run(kmg01, filter_data,
dataset = "adtte", annot_surv_med = FALSE,
position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7),
strat = c("STRATA1", "STRATA2")
))
expect_true(grid::is.grob(res))
expect_true(ggplot2::is.ggplot(res))
})
57 changes: 28 additions & 29 deletions vignettes/chevron_catalog.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1155,54 +1155,53 @@ head(l_ae_nollt, 10)
3) Users are expected to select the treatment groups to compare, otherwise, all treatment groups available in the input datasets will be plotted.
4) The comparative statistics are not included by default.
5) The estimation of median survival time per treatment group by default.
6) By default, the `run` function will not render the plot. For viewing and testing purpose, the users can include the argument `draw = TRUE` to view the plot in the `Plots` tab.
7) More arguments in the `g_km` and `control_coxph` functions can be passed through, please use the Help to find out more information.
6) More arguments in the `g_km` and `control_coxph` functions can be passed through, please use the Help to find out more information.

```{r}
```{r, fig.width = 10, fig.height = 6}
proc_data <- log_filter(syn_data, PARAMCD == "OS", "adtte")
run(kmg01, proc_data, dataset = "adtte", draw = TRUE)
run(kmg01, proc_data, dataset = "adtte")
```

#### **2. Kaplan-Meier Plot (with comparative statistics)**

To enable the comparative statistics (hazard ratio and p-value), the argument `annot_coxph` needs to be set to TRUE. The compare group is determined by the levels in the factorized variable of treatment group and the first level is used as reference group in the statistics.

```{r}
```{r, fig.width = 10, fig.height = 6}
proc_data <- log_filter(syn_data, PARAMCD == "OS", "adtte")
run(kmg01, proc_data, dataset = "adtte", draw = TRUE, annot_coxph = TRUE)
run(kmg01, proc_data, dataset = "adtte", annot_coxph = TRUE, control_annot_coxph = tern::control_coxph_annot(x = 0.33, y = 0.42))

Check warning on line 1171 in vignettes/chevron_catalog.rmd

View workflow job for this annotation

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

file=vignettes/chevron_catalog.rmd,line=1171,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 129 characters.
```

#### **3. Kaplan-Meier Plot (without censoring marks)**

To suppress the censoring marks, set the argument `cencor_show` to FALSE.

```{r}
```{r, fig.width = 10, fig.height = 6}
proc_data <- log_filter(syn_data, PARAMCD == "OS", "adtte")
run(kmg01, proc_data, dataset = "adtte", draw = TRUE, censor_show = FALSE)
run(kmg01, proc_data, dataset = "adtte", censor_show = FALSE)
```

#### **4. Kaplan-Meier Plot (without estimation of median survival time)**

```{r}
```{r, fig.width = 10, fig.height = 6}
proc_data <- log_filter(syn_data, PARAMCD == "OS", "adtte")
run(kmg01, proc_data, dataset = "adtte", draw = TRUE, annot_surv_method = FALSE)
run(kmg01, proc_data, dataset = "adtte", annot_surv_med = FALSE)
```

#### **5. Kaplan-Meier Plot (with statistical annotation of either median or min of survival time)**

To add the statistics annotation, use the function `annot_stats`. Options are `min` or `median`.

```{r}
```{r, fig.width = 10, fig.height = 6}
proc_data <- log_filter(syn_data, PARAMCD == "OS", "adtte")
run(kmg01, proc_data, dataset = "adtte", draw = TRUE, annot_stats = "median")
run(kmg01, proc_data, dataset = "adtte", draw = TRUE, annot_stats = c("min", "median"))
run(kmg01, proc_data, dataset = "adtte", annot_stats = "median")
run(kmg01, proc_data, dataset = "adtte", annot_stats = c("min", "median"))
```

#### **6. Kaplan-Meier Plot (without the table of patient at risk)**
#### **6. Kaplan-Meier Plot (without the table of patients at risk)**

```{r}
```{r, fig.width = 10, fig.height = 6}
proc_data <- log_filter(syn_data, PARAMCD == "OS", "adtte")
run(kmg01, proc_data, dataset = "adtte", draw = TRUE, annot_at_risk = FALSE)
run(kmg01, proc_data, dataset = "adtte", annot_at_risk = FALSE)
```

### **Mean Plot (`MNG01`)**
Expand All @@ -1215,57 +1214,57 @@ run(kmg01, proc_data, dataset = "adtte", draw = TRUE, annot_at_risk = FALSE)
4) The variable Analysis Value `AVAL` is used for plotting by default.
5) If the input dataset contains results of the same analyses in multiple units,(e.g. SI/CV units in `ADLB`), please make sure that the parameters in appropriate units are selected in advance.

```{r}
```{r, fig.height = 8}
proc_data <- log_filter(syn_data, PARAMCD == "DIABP", "advs")
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), draw = TRUE)
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"))
```

#### **2. Plot of Mean and Confidence Interval of Change from Baseline of Vital Signs**

```{r}
```{r, fig.height = 8}
proc_data <- log_filter(syn_data, PARAMCD == "DIABP", "advs")
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), y_var = "CHG", draw = TRUE)
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), y_var = "CHG")
```

#### **3. Plot of Mean (+/-SD) (Changing the Statistics)**

To change the statistics, use the argument `interval_fun`. Options are `mean_ci`, `mean_sei`, `mean_sdi`, `median_ci`, `quantiles`,`range`.

```{r}
```{r, fig.height = 8}
proc_data <- log_filter(syn_data, PARAMCD == "DIABP", "advs")
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), interval_fun = "mean_sdi", draw = TRUE)
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), interval_fun = "mean_sdi")
```

#### **4. Plot of Mean and Confidence Interval (Modify Alpha Level)**

To change the alpha level of the confidence interval, use the argument `control = control_analyze_vars(conf_level = <0.xx>)`. Note that this is only in effect when `interval_fun` is set to `mean_ci`.

```{r}
```{r, fig.height = 8}
proc_data <- log_filter(syn_data, PARAMCD == "DIABP", "advs")
run(
mng01, proc_data,
dataset = "advs", x_var = c("AVISIT", "AVISITN"),
interval_fun = "mean_ci", draw = TRUE, control = tern::control_analyze_vars(conf_level = 0.80)
interval_fun = "mean_ci", control = tern::control_analyze_vars(conf_level = 0.80)
)
```

#### **5. Plot of Mean and Confidence Interval (With Number of Patients Only)**

```{r}
```{r, fig.height = 8}
proc_data <- log_filter(syn_data, PARAMCD == "DIABP", "advs")
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), table = "n", draw = TRUE)
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), table = "n")
```

#### **6. Plot of Mean and Confidence Interval (without Table Section)**

```{r}
```{r, fig.height = 8}
proc_data <- log_filter(syn_data, PARAMCD == "DIABP", "advs")
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), table = NULL, draw = TRUE)
run(mng01, proc_data, dataset = "advs", x_var = c("AVISIT", "AVISITN"), table = NULL)
```

A new argument has been added to control the theme (e.g. setting the angle of the axis); see an example below:

```{r}
```{r, fig.height = 8}
ggtheme <- ggplot2::theme(
panel.grid = ggplot2::element_line(colour = "black", linetype = 3),
panel.background = ggplot2::element_rect(fill = "white"),
Expand Down

0 comments on commit e4c2241

Please sign in to comment.