Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #66

Merged
merged 3 commits into from
Sep 28, 2024
Merged

Dev #66

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
13 changes: 9 additions & 4 deletions R/simaerep.R
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,20 @@ eval_sites <- function(df_sim_sites,
#'@keywords internal
p_adjust <- function(df, col, suffix, method = "BH") {

col_adj <- paste0(col, "_adj")
col_suffix <- paste0(col, suffix)

if (is.na(method) || is.null(method) || method %in% c("None", "none")) {
return(df)
df_out <- df %>%
mutate(
!! as.name(col_suffix) := 1 - .data[[col]]
)

return(df_out)
}

if (inherits(df, "data.frame")) {

col_adj <- paste0(col, "_adj")
col_suffix <- paste0(col, suffix)

df_out <- df %>%
mutate(
!! as.name(col_adj) := p.adjust(.data[[col]], method = method),
Expand Down
21 changes: 15 additions & 6 deletions R/simaerep_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,26 @@ plot_study <- function(df_visit,

# ordered sites -------------------------------------------------------------

if (any(stringr::str_detect(colnames(df_eval), "_adj$"))) {
thresh <- 0.5
breaks <- c(0, 0.5, 0.75, 0.95, ifelse(max(df_eval[[prob_col]], na.rm = TRUE) > 0.95,
max(df_eval[[prob_col]], na.rm = TRUE) + 0.1,
NA))
} else {
thresh <- 0.9
breaks <- c(0, 0.9, 0.95, 0.99, ifelse(max(df_eval[[prob_col]], na.rm = TRUE) > 0.95,
max(df_eval[[prob_col]], na.rm = TRUE) + 0.1,
NA))
}

n_site_ur_gr_0p5 <- df_eval %>%
filter(.data[[prob_col]] > 0.5) %>%
filter(.data[[prob_col]] > thresh) %>%
nrow()

if (n_site_ur_gr_0p5 > 0) {
sites_ordered <- df_eval %>%
arrange(.data$study_id, desc(.data[[prob_col]]), .data[[col_mean_site]]) %>%
filter(.data[[prob_col]] > 0.5) %>%
filter(.data[[prob_col]] > thresh) %>%
head(n_sites) %>%
.$site_number
} else {
Expand Down Expand Up @@ -604,10 +616,7 @@ plot_study <- function(df_visit,
# define score cut-offs + labels----------------------------------------------

palette <- RColorBrewer::brewer.pal(9, "Blues")[c(3, 5, 7, 9)]
breaks <- c(0, 0.5, 0.75, 0.95, ifelse(max(df_eval[[prob_col]], na.rm = TRUE) > 0.95,
max(df_eval[[prob_col]], na.rm = TRUE) + 0.1,
NA)
)


breaks <- breaks[! is.na(breaks)]

Expand Down
53 changes: 52 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Download as pdf in the [release section](https://github.com/openpharma/simaerep/

## Application

Recommended Threshold: `aerep$dfeval$prob_low_prob_ur: 0.95`


```{r fig.width=10}

suppressPackageStartupMessages(library(simaerep))
Expand All @@ -96,9 +99,57 @@ df_visit %>%

aerep <- simaerep(df_visit)

plot(aerep, study = "A")
plot(aerep, study = "A")
```

*Left panel shows mean AE reporting per site (lightblue and darkblue lines) against mean AE reporting of the entire study (golden line). Single sites are plotted in descending order by AE under-reporting probability on the right panel in which grey lines denote cumulative AE count of single patients. Grey dots in the left panel plot indicate sites that were picked for single plotting. AE under-reporting probability of dark blue lines crossed threshold of 95%. Numbers in the upper left corner indicate the ratio of patients that have been used for the analysis against the total number of patients. Patients that have not been on the study long enough to reach the evaluation point (visit_med75, see introduction) will be ignored.*

## Optimized Statistical Performance

Following the recommendation of our latest [performance benchmark](https://openpharma.github.io/simaerep/articles/performance.html) statistical performance can be increased by using the [inframe](https://openpharma.github.io/simaerep/articles/inframe.html) algorithm without multiplicity correction.

**Note that the plot is more noisy because no patients are excluded and only a few patients contribute to the event count at higher visits**

Recommended Threshold: `aerep$dfeval$prob_low_prob_ur: 0.99`

```{r}
aerep <- simaerep(
df_visit,
inframe = TRUE,
visit_med75 = FALSE,
mult_corr = FALSE
)

plot(aerep, study = "A")
```

## In Database Calculation

The [inframe](https://openpharma.github.io/simaerep/articles/inframe.html) algorithm uses only `dbplyr` compatible table operations and can be executed within a database backend as we demonstrate here using `duckdb`.

However, we need to provide a in database table that has as many rows as the desired replications in our simulation, instead of providing an integer for the `r` parameter.

```{r}
con <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:")
df_r <- tibble(rep = seq(1, 1000))

dplyr::copy_to(con, df_visit, "visit")
dplyr::copy_to(con, df_r, "r")

tbl_visit <- tbl(con, "visit")
tbl_r <- tbl(con, "r")


aerep <- simaerep(
tbl_visit,
r = tbl_r,
inframe = TRUE,
visit_med75 = FALSE,
mult_corr = FALSE
)

plot(aerep, df_visit = tbl_visit)

DBI::dbDisconnect(con)
```

72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ using

## Application

Recommended Threshold: `aerep$dfeval$prob_low_prob_ur: 0.95`

``` r

suppressPackageStartupMessages(library(simaerep))
Expand Down Expand Up @@ -143,7 +145,7 @@ df_visit %>%

aerep <- simaerep(df_visit)

plot(aerep, study = "A")
plot(aerep, study = "A")
```

<img src="man/figures/README-unnamed-chunk-2-1.png" width="100%" />
Expand All @@ -159,3 +161,71 @@ upper left corner indicate the ratio of patients that have been used for
the analysis against the total number of patients. Patients that have
not been on the study long enough to reach the evaluation point
(visit_med75, see introduction) will be ignored.*

## Optimized Statistical Performance

Following the recommendation of our latest [performance
benchmark](https://openpharma.github.io/simaerep/articles/performance.html)
statistical performance can be increased by using the
[inframe](https://openpharma.github.io/simaerep/articles/inframe.html)
algorithm without multiplicity correction.

**Note that the plot is more noisy because no patients are excluded and
only a few patients contribute to the event count at higher visits**

Recommended Threshold: `aerep$dfeval$prob_low_prob_ur: 0.99`

``` r
aerep <- simaerep(
df_visit,
inframe = TRUE,
visit_med75 = FALSE,
mult_corr = FALSE
)

plot(aerep, study = "A")
```

<img src="man/figures/README-unnamed-chunk-3-1.png" width="100%" />

## In Database Calculation

The
[inframe](https://openpharma.github.io/simaerep/articles/inframe.html)
algorithm uses only `dbplyr` compatible table operations and can be
executed within a database backend as we demonstrate here using
`duckdb`.

However, we need to provide a in database table that has as many rows as
the desired replications in our simulation, instead of providing an
integer for the `r` parameter.

``` r
con <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:")
df_r <- tibble(rep = seq(1, 1000))

dplyr::copy_to(con, df_visit, "visit")
dplyr::copy_to(con, df_r, "r")

tbl_visit <- tbl(con, "visit")
tbl_r <- tbl(con, "r")


aerep <- simaerep(
tbl_visit,
r = tbl_r,
inframe = TRUE,
visit_med75 = FALSE,
mult_corr = FALSE
)

plot(aerep, df_visit = tbl_visit)
#> study = NULL, defaulting to study:A
```

<img src="man/figures/README-unnamed-chunk-4-1.png" width="100%" />

``` r

DBI::dbDisconnect(con)
```
4 changes: 2 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# submission simaerep v0.5.0
# submission simaerep v0.6.0

## Test Results

No notes, warnings or errors

## Test Environments

- Rhub, debian
- Rhub - linux, macos, macos-arm64, windows devel
- GitHub CI/CD macOS-latest


Expand Down
4 changes: 2 additions & 2 deletions docs/404.html

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

51 changes: 50 additions & 1 deletion docs/index.html

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

Binary file added man/figures/README-unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading