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

Fix: Ensure Correct Column (npde_mode_simBlq vs. npde_simBlq) is Used for sim_blq=TRUE in Plotting Functions #381

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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: 10 additions & 3 deletions R/pmxClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,16 @@ pmx_initialize <- function(self, private, data_path, input, dv,
# In some cases xx and xx_simBlq are not the same
suppressWarnings({
for(cn in c("iwRes", "pwRes", "npde")) {
if(paste0(cn, "_mode_simBlq") %in% colnames(self[["data"]][["sim_blq"]])) {
self[["data"]][["sim_blq"]][[toupper(cn)]] <-
self[["data"]][["sim_blq"]][[paste0(cn, "_mode_simBlq")]]
col_name_mode <- paste0(cn, "_mode_simBlq") # e.g., npde_mode_simBlq
col_name_simple <- paste0(cn, "_simBlq") # e.g., npde_simBlq

# If the "_mode_simBlq" column exists
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the _mode_simBlq column exists, is there a _mean_simBlq or other sort of column. In some cases, the endpoint is also part of the variable name; do we know if that is the case here?

if (col_name_mode %in% colnames(self[["data"]][["sim_blq"]])) {
self[["data"]][["sim_blq"]][[toupper(cn)]] <- self[["data"]][["sim_blq"]][[col_name_mode]]
}
# Otherwise, use the simple "_simBlq" column
else if (col_name_simple %in% colnames(self[["data"]][["sim_blq"]])) {
self[["data"]][["sim_blq"]][[toupper(cn)]] <- self[["data"]][["sim_blq"]][[col_name_simple]]
}
}
})
Expand Down
Binary file added tests/testthat/hiv_project.zip
Binary file not shown.
59 changes: 59 additions & 0 deletions tests/testthat/test-simBlq-npde.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
skip_if_not(file.exists(test_path("hiv_project.zip")))
.path <- normalizePath(test_path("hiv_project.zip"))

withr::with_tempdir({

unzip(.path)

ctr <- suppressWarnings(pmx_mlxtran("hiv_project.mlxtran", endpoint = c(1, 2)))




test_that("BLQ column class is correct", {
# Check if the sim_blq dataset exists
expect_true("sim_blq_npde_iwres" %in% names(ctr$data), info = "sim_blq dataset is missing in ctr$data.")

# Check if the npde_simBlq column exists in the dataset
expect_true("npde_simBlq" %in% colnames(ctr$data[["sim_blq"]]),
info = "npde_simBlq column is missing in sim_blq_npde_iwres dataset.")

# Verify the class of the column
expect_is(ctr$data[["sim_blq"]][["npde_simBlq"]], "numeric",
info = "npde_simBlq column is not of class numeric.")
})


test_that("Variable mapped to y-aesthetic is correct", {
# Generate the plot with sim_blq = TRUE
plot <- pmx_plot_npde_pred(ctr, sim_blq = TRUE)

# Extract the ggplot mapping
mapping <- ggplot2::ggplot_build(plot)$data[[1]]

# Check that the y aesthetic is mapped to the correct column
expect_true("y" %in% names(mapping), info = "y aesthetic is missing in the plot mapping.")
expect_equal(mapping$y, ctr$data[["sim_blq"]][["npde_simBlq"]],
info = "y aesthetic is not correctly mapped to npde_simBlq.")
})


test_that("Exact values of npde_simBlq match the residuals file", {
# Load the reference data
residuals_path <- normalizePath("hiv_project/ChartsData/ScatterPlotOfTheResiduals/y1_residuals.txt") # Remplacez par le chemin exact après extraction
residuals_file <- fread(residuals_path)

expected_values <- residuals_file[["npde_simBlq"]]

# Check if the npde_simBlq column exists
expect_true("npde_simBlq" %in% colnames(ctr$data[["sim_blq_npde_iwres"]]),
info = "npde_simBlq column is missing in sim_blq dataset.")

# Compare values
actual_values <- ctr$data[["sim_blq_npde_iwres"]][["npde_simBlq"]]
expect_equal(actual_values, expected_values,
tolerance = 1e-6, info = "npde_simBlq values do not match expected values.")
})


})
Loading