Skip to content

Commit

Permalink
Plot fixes for censoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Sep 21, 2022
1 parent cef4e2c commit c819d63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions R/plot.nlmixr2.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.setupPlotData <- function(data) {
.dat <- as.data.frame(data)
.dat <- .dat[!is.na(.dat$RES),]
.dat <- .dat[!is.na(.dat$RES), ]
.doCmt <- FALSE
if (any(names(.dat) == "CMT")) {
if (length(levels(.dat$CMT)) > 1) {
Expand Down Expand Up @@ -37,7 +37,7 @@
if (any(names(.dat0) == "CENS")) {
dataPlot <- data.frame(DV = .dat0$DV, CENS = .dat0$CENS, utils::stack(.dat0[, vars, drop = FALSE]))
.aes <- ggplot2::aes(.data$values, .data$DV, color = .data$CENS)
if (length(levels(.data$CENS)) == 3) {
if (length(levels(.dat0$CENS)) == 3) {
.color <- ggplot2::scale_color_manual(values = c("blue", "black", "red"))
} else {
.color <- ggplot2::scale_color_manual(values = c("black", "red"))
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-plots-cens.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
test_that("plot censoring", {
skip_on_cran()

dat <- xgxr::case1_pkpd %>%
dplyr::rename(DV=LIDV) %>%
dplyr::filter(CMT %in% 1:2) %>%
dat <- xgxr::case1_pkpd |>
dplyr::rename(DV=LIDV) |>
dplyr::filter(CMT %in% 1:2) |>
dplyr::filter(TRTACT != "Placebo")

doses <- unique(dat$DOSE)
nid <- 10 # 7 ids per dose group
dat2 <- do.call("rbind",
lapply(doses, function(x) {
ids <- dat %>%
dplyr::filter(DOSE == x) %>%
dplyr::summarize(ids=unique(ID)) %>%
ids <- dat |>
dplyr::filter(DOSE == x) |>
dplyr::summarize(ids=unique(ID)) |>
dplyr::pull()
ids <- ids[seq(1, nid)]
dat %>%
dat |>
dplyr::filter(ID %in% ids)
}))

## Use 2 compartment model
cmt2 <- function(){
cmt2 <- function() {
ini({
lka <- log(0.1) # log Ka
lv <- log(10) # Log Vc
Expand Down

0 comments on commit c819d63

Please sign in to comment.