Skip to content

Commit

Permalink
v0.2.14
Browse files Browse the repository at this point in the history
  • Loading branch information
stevechoy committed Feb 10, 2025
1 parent 9f96e49 commit 70b7019
Show file tree
Hide file tree
Showing 156 changed files with 2,177 additions and 1,153 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MVPapp
Title: Model Visualization Platform
Version: 0.2.13
Version: 0.2.14
Authors@R: c(
person("Steve", "Choy", email = "[email protected]", role = c("aut", "cre")),
person("Jin Gyu", "Kim", role = "aut"))
Expand Down Expand Up @@ -52,9 +52,9 @@ Suggests: readr,
Depends: R (>= 3.5.0)
LazyData: true
Collate: "utils-pipe.R"
"ui_settings_v_0_2_13.R"
"ui_settings_v_0_2_14.R"
"code_templates_v_0_2_10.R"
"functions_v_0_2_13.R"
"functions_v_0_2_14.R"
"config.R"
"run_mvp.R"
"data.R"
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export(dp_checkbox_name)
export(draw_correlation_plot)
export(eval_parse)
export(expand_addl_ii)
export(exposures_table)
export(extract_matrix)
export(extract_model_params)
export(facet_by_label)
Expand Down Expand Up @@ -219,6 +220,7 @@ export(pkpd_te)
export(placeholder_password)
export(plot_data_with_nm)
export(plot_iiv_data_with_nm)
export(plot_iiv_exp_data)
export(plot_three_data_with_nm)
export(plot_title_label)
export(plot_title_placeholder)
Expand Down Expand Up @@ -322,12 +324,14 @@ importFrom(ggplot2,geom_count)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_rect)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggplot_build)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,label_both)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_color_manual)
importFrom(ggplot2,scale_fill_manual)
importFrom(ggplot2,scale_size_area)
importFrom(ggplot2,scale_x_log10)
importFrom(ggplot2,scale_y_log10)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# MVPapp 0.2.14 (2025-02-07)

## Features

* Additional tab for Variability plots to display box plots of exposures (#22)

## Bugfixes

* Minor updates to some tooltips and button placements to increase clarity.

# MVPapp 0.2.13 (2025-02-04)

## Features
Expand Down
168 changes: 168 additions & 0 deletions R/functions_v_0_2_13.R → R/functions_v_0_2_14.R
Original file line number Diff line number Diff line change
Expand Up @@ -4297,4 +4297,172 @@ trim_columns <- function(data,

return(data_to_plot)

}

#-------------------------------------------------------------------------------
#' @name exposures_table
#'
#' @title Function to calculate exposures from IIV output
#'
#' @param input_simulated_table a dataframe (usually created from mrgsim)
#' @param output_conc y variable of interest to perform summary stats calc
#' @param start_time start time interval for metrics
#' @param end_time end time interval for metrics
#' @param debug show debugging messages
#'
#' @returns a dataframe with additional columns of summary stats
#' @importFrom dplyr mutate if_else ungroup select filter rename first group_by distinct summarise
#' @export
#-------------------------------------------------------------------------------

exposures_table <- function(input_simulated_table,
output_conc,
start_time = NULL,
end_time = NULL,
debug = FALSE
) {

input_simulated_table$YVARNAME <- input_simulated_table[[output_conc]]

# if (debug) {
# message(start_time)
# message(end_time)
# tmp <- input_simulated_table %>% dplyr::filter(TIME >= start_time)
# message(dplyr::glimpse(tmp))
# tmp2 <- input_simulated_table %>% dplyr::filter(TIME <= start_time)
# message(dplyr::glimpse(tmp2))
# }

metrics_table <- input_simulated_table %>% dplyr::filter(TIME >= start_time, TIME <= end_time) %>%
group_by(ID) %>%
dplyr::mutate(CMIN = min(YVARNAME, na.rm = TRUE)[1],
CMAX = max(YVARNAME, na.rm = TRUE)[1], ### First element if multiple values found
CAVG = mean(YVARNAME, na.rm = TRUE)
) %>%
ungroup()

# Calculate CMAX and TMAX in a separate table
tmax_table <- metrics_table %>%
group_by(ID) %>%
summarise(TMIN = TIME[which.min(YVARNAME)[1]],
TMAX = TIME[which.max(YVARNAME)[1]]) %>% # First element if multiple values found
ungroup()

metrics_table <- left_join(metrics_table, tmax_table, by = "ID")

metrics_table <- metrics_table %>%
group_by(ID) %>%
dplyr::mutate(YLAG = dplyr::lag(YVARNAME),
XLAG = dplyr::lag(TIME),
dYVAR = (YVARNAME + YLAG) * (TIME - XLAG) * 0.5, # Area for trapezoid
dYVAR = dplyr::if_else(is.na(dYVAR), 0, dYVAR),
AUC = sum(dYVAR)) %>%
dplyr::ungroup()

metrics_table_id <- metrics_table %>%
dplyr::select(ID, CMIN, CMAX, CAVG, AUC, TMAX, TMIN) %>%
dplyr::distinct(ID, .keep_all = TRUE)
return(metrics_table_id)
}

#-------------------------------------------------------------------------------
#' @name plot_iiv_exp_data
#'
#' @title Function to plot variability exposure data
#'
#' @param input_dataset Input dataset of Model 1 and/or Model 2 that contains MODEL ID CMIN CAVG CMAX AUC
#' @param yvar Name of Y-variable (exposure metric) to be plotted, string
#' @param ylab Optional name for yvar
#' @param model_1_name Optional name for Model 1
#' @param model_2_name Optional name for Model 2
#' @param model_1_color Color for Model 1
#' @param model_2_color Color for Model 2
#' @param show_stats Display texts of stats for each box plot
#' @param title Title for plot
#'
#' @returns a ggplot object
#' @importFrom dplyr select mutate all_of summarise
#' @importFrom ggplot2 theme_bw geom_boxplot scale_fill_manual geom_text
#' @importFrom forcats fct_inorder
#' @importFrom ggrepel geom_text_repel
#' @export
#-------------------------------------------------------------------------------

plot_iiv_exp_data <- function(input_dataset,
yvar = 'yvar',
ylab = yvar,
model_1_name = '',
model_2_name = '',
model_1_color = "#F8766D",
model_2_color = "#7570B3",
show_stats = TRUE,
xlab = '',
title = "") {

input_dataset$MODEL <- gsub("Model 1", model_1_name, input_dataset$MODEL)
input_dataset$MODEL <- gsub("Model 2", model_2_name, input_dataset$MODEL)
input_dataset$MODEL <- as.factor(input_dataset$MODEL) %>%
forcats::fct_inorder()

# Define the colors for the models
model_colors <- c()

# Check if "Model 1" exists in the data
if (model_1_name %in% input_dataset$MODEL) {
model_colors[model_1_name] <- model_1_color
}

# Check if "Model 2" exists in the data
if (model_2_name %in% input_dataset$MODEL) {
model_colors[model_2_name] <- model_2_color
}

p <- ggplot2::ggplot(data = input_dataset, aes(x = MODEL, y = .data[[yvar]], group = MODEL, fill = MODEL)) +
ggplot2::theme_bw() +
ggplot2::geom_boxplot(alpha = 0.5) +
ggplot2::scale_fill_manual(values = model_colors)

if(show_stats) {
# Calculate statistics for each group
stats_df <- input_dataset %>%
dplyr::group_by(MODEL) %>%
dplyr::summarise(maximum = max(.data[[yvar]], na.rm = TRUE) %>% round(digits = 2),
upper975 = quantile(.data[[yvar]], probs = 0.975, na.rm = TRUE) %>% round(digits = 2),
upper95 = quantile(.data[[yvar]], probs = 0.95, na.rm = TRUE) %>% round(digits = 2),
mean = mean(.data[[yvar]], na.rm = TRUE) %>% round(digits = 2),
median = median(.data[[yvar]], na.rm = TRUE) %>% round(digits = 2),
lower025 = quantile(.data[[yvar]], probs = 0.025, na.rm = TRUE) %>% round(digits = 2),
lower05 = quantile(.data[[yvar]], probs = 0.05, na.rm = TRUE) %>% round(digits = 2),
minimum = min(.data[[yvar]], na.rm = TRUE) %>% round(digits = 2)) %>%
dplyr::ungroup()

p <- p +
ggplot2::geom_text(data = stats_df, aes(x = MODEL, y = maximum, label = paste("Max:", maximum)), vjust = -1) +
ggplot2::geom_text(data = stats_df, aes(x = MODEL, y = upper95, label = paste("95%:", upper95)), vjust = -1) +
ggplot2::geom_text(data = stats_df, aes(x = MODEL, y = mean, label = paste("Mean:", mean)), vjust = -1) +
ggplot2::geom_text(data = stats_df, aes(x = MODEL, y = median, label = paste("Median:", median)), vjust = -1) +
ggplot2::geom_text(data = stats_df, aes(x = MODEL, y = lower05, label = paste("5%:", lower05)), vjust = -1) +
ggplot2::geom_text(data = stats_df, aes(x = MODEL, y = minimum, label = paste("Min:", minimum)), vjust = 1)

# p <- p +
# ggrepel::geom_text_repel(data = stats_df, aes(x = MODEL, y = maximum, label = paste("Max:", maximum))) +
# ggrepel::geom_text_repel(data = stats_df, aes(x = MODEL, y = upper95, label = paste("95%:", upper95))) +
# ggrepel::geom_text_repel(data = stats_df, aes(x = MODEL, y = mean, label = paste("Mean:", mean))) +
# ggrepel::geom_text_repel(data = stats_df, aes(x = MODEL, y = median, label = paste("Median:", median))) +
# ggrepel::geom_text_repel(data = stats_df, aes(x = MODEL, y = lower05, label = paste("5%:", lower05))) +
# ggrepel::geom_text_repel(data = stats_df, aes(x = MODEL, y = minimum, label = paste("Min:", minimum)))

}

if(ylab != '') {
p <- p + ggplot2::labs(x = "", y = ylab)
} else {
p <- p + ggplot2::labs(x = "", y = yvar)
}

p <- p +
ggplot2::ggtitle(title) +
ggplot2::theme(legend.position = "none")

return(p)
}
2 changes: 1 addition & 1 deletion R/ui_settings_v_0_2_13.R → R/ui_settings_v_0_2_14.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ label_lloq_colname <- 'LLOQ Column'
bspop_lloq_colname <- '(Optional) Provide LLOQ/BLQ column to be plotted as dashed horizontal lines.'

#' @export
bspop_download_plot <- 'Adjust output settings in the "Download Options" box below.'
bspop_download_plot <- 'Adjust output settings in the "Download Options" box below.<br><br>This button will be disabled when the plot is interactive, instead please download by using the Camera icon on the top right of the plot.'
#' @export
plotly_filename_label <- "Plot name"
#' @export
Expand Down
13 changes: 12 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Uploading NONMEM-formatted datasets (.csv) and tab-delimited text files (.txt) i

4. Quick data exploration are provided by the "General Plot", "Ind. Plot", and "Corr. Plot" tabs (tip: clicking on the legend can toggle each subgroup on/off when the plot is interactive):

General plots are flexible plots that can handle continuous/continuous, continuous/discrete (Box plot option), and discrete/discrete (Box plot option) types of data. Settings from General Plots will be carried over to the "Ind. Plot", where users can explore individual profiles in more detail. Dosing information from the "EVID", "ADDL", "II", "RATE" can be inserted on each plot when the Dose Column is provided. LLOQ information can also be inserted.
General plots are flexible plots that can handle continuous/continuous, continuous/discrete (Box plot option), and discrete/discrete (Box plot option) types of data. Settings from General Plots will be carried over to the "Ind. Plot", where users can explore individual profiles in more detail. Dosing information ("EVID", "ADDL", "II", "RATE" columns) can be inserted on each plot when the Dose Column is provided. LLOQ information can also be inserted.

![](www/facet_plot.png)

Expand Down Expand Up @@ -160,6 +160,17 @@ Both OMEGAs and SIGMAs, if it exists in the model, will be available for the use

![](www/varplot.png)

#### Comparing Exposure Differences

Summary of exposure metrics are readily available to be viewed, which is handy when assessing differences in models, dosing regimens, and/or demographics.\

1. Navigate to the "Exposure Box Plots" on the top right side of the page.\
2. Select the time intervals of interest to derive metrics, which could be relevant when deriving AUCtau,ss, for example. By default the entire time range is used.
3. Pick an exposure metric in the "Select Metric" option in the "Plotting Options" box. Currently, Cmax, Cmin, Cavg, AUC, Tmax and Tmin are supported.
4. Labels, titles, and the option to insert more summary statistics are available to further customize the plot, allowing great "off-the-shelf" graphics to be downloaded for presentations.

![](www/expplot.png)

## Extended Features and Vignettes

### Providing external models and changing default settings
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ General plots are flexible plots that can handle continuous/continuous,
continuous/discrete (Box plot option), and discrete/discrete (Box plot
option) types of data. Settings from General Plots will be carried over
to the “Ind. Plot”, where users can explore individual profiles in more
detail. Dosing information from the “EVID”, “ADDL”, “II”, “RATE” can be
detail. Dosing information (“EVID”, “ADDL”, “II”, “RATE” columns) can be
inserted on each plot when the Dose Column is provided. LLOQ information
can also be inserted.

Expand Down Expand Up @@ -285,6 +285,26 @@ matrices has reverted to its last known state.

![](www/varplot.png)

#### Comparing Exposure Differences

Summary of exposure metrics are readily available to be viewed, which is
handy when assessing differences in models, dosing regimens, and/or
demographics. 

1. Navigate to the “Exposure Box Plots” on the top right side of the
page.
2. Select the time intervals of interest to derive metrics, which could
be relevant when deriving AUCtau,ss, for example. By default the
entire time range is used.
3. Pick an exposure metric in the “Select Metric” option in the
“Plotting Options” box. Currently, Cmax, Cmin, Cavg, AUC, Tmax and
Tmin are supported.
4. Labels, titles, and the option to insert more summary statistics are
available to further customize the plot, allowing great
“off-the-shelf” graphics to be downloaded for presentations.

![](www/expplot.png)

## Extended Features and Vignettes

### Providing external models and changing default settings
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

12 changes: 6 additions & 6 deletions docs/articles/data-exploration.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

2 changes: 1 addition & 1 deletion docs/articles/supply-passwords.html

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

2 changes: 1 addition & 1 deletion docs/authors.html

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

Loading

0 comments on commit 70b7019

Please sign in to comment.