Skip to content

Commit

Permalink
Merge pull request #355 from ggPMXdevelopment/323-bug-for-nlmixr2-fits
Browse files Browse the repository at this point in the history
323 bug for nlmixr2 fits
  • Loading branch information
mattfidler committed Apr 14, 2023
2 parents 04ea68e + 368041a commit 2278417
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 30 deletions.
9 changes: 8 additions & 1 deletion R/nlmixr.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


#' Creates pmx controller from an nlimxr fit object
#'
#' @param fit nlmixr object
Expand Down Expand Up @@ -117,7 +119,12 @@ pmx_nlmixr <- function(fit, dvid, conts, cats, strats, endpoint, settings, vpc =
}
}
}
input <- as.data.table(fit$dataMergeInner)
# use the fit DV because it simulates censoring
# $fitMergeInner prefers the DV from the fit, so preserve it here
input <- fit$fitMergeInner
# if it hasn't been implemented use dataMergeInner instead
if (is.null(input)) input <- fit$dataMergeInner
input <- as.data.table(input)
for (v in conts) {
if (v != "") {
class(input[[v]]) <- "double"
Expand Down
15 changes: 9 additions & 6 deletions R/plot-individual.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ plot_pmx.individual <-
point$shape <- NULL
max_y <- aggregate(TIME ~ ID, data=dx, max)
colnames(max_y) <- c("ID", "maxValue")
dx <- base::merge(dx, max_y, by="ID", all.x = T)
dx <- base::merge(dx, max_y, by="ID", all.x = TRUE)
# Rounding because "predictions" data are rounded:
dx$isobserv <- with(dx, round(TIME) <= maxValue)
point$data <- base::merge(point$data, max_y, by="ID")
Expand Down Expand Up @@ -139,20 +139,23 @@ plot_pmx.individual <-
}
}
}

if (!is.null(point)) {
n <- ifelse(any(point$data$isobserv == "ignored"), 3, 2)
n <- ifelse(any(point$data$isobserv == "ignored"), 3,
ifelse(length(point$data$isobserv) == 0L, 1, 2))
linetype_values <- c(rep("solid", n), "dashed")
if (any(point$data$isobserv == "ignored"))
if (any(point$data$isobserv == "ignored")) {
linetype_labels <- c("accepted",
"ignored",
"individual predictions",
"population predictions")
else
} else if (length(point$data$isobserv) == 0L) {
linetype_labels <- c("individual predictions",
"population predictions")
} else {
linetype_labels <- c("accepted",
"individual predictions",
"population predictions")

}
} else {
n <- 2
linetype_labels <- c("accepted",
Expand Down
67 changes: 44 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ diagnostics such as: - residual- and empirical Bayes estimate
(EBE)-based plots, - distribution plots, - prediction- and
simulation-based diagnostics (visual predictive checks).

ggPMX creates plot objects which can be further customized and extended
using the extensive [ggplot2
syntax](https://ggplot2.tidyverse.org/reference/gg-add.html).

In addition, shrinkage and summary parameters tables can be also
produced. By default, the PDF- or Word-format diagnostic report contains
essential goodness-of-fit plots. However, these can be adapted to
Expand Down Expand Up @@ -756,7 +760,9 @@ ctr %>% pmx_plot_eta_matrix

In order to generate VPCs a simulation dataset is requried. Creation of
VPC is slightly different dependening on the fitting software used
(Monolix, NONMEM or nlmixr).
(Monolix, NONMEM or nlmixr). Make sure to use the same name for the dv
column in the simulation file as the one used in the input (modeling
dataset).

### Models fitted with Monolix (versions 2016 and later)

Expand Down Expand Up @@ -896,21 +902,29 @@ ctr %>% pmx_plot_vpc(bin=pmx_vpc_bin(style = "kmeans",n=5))

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

### Stratification
### Set custom x- and/or y-axis labels

``` r
ctr %>% pmx_plot_vpc(strat.facet="SEX",facets=list(nrow=2))
ctr %>% pmx_plot_vpc(labels = c(x = "DV axis", y = "TIME axis"))
```

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

### Stratification

``` r
ctr %>% pmx_plot_vpc(strat.facet=~SEX,facets=list(nrow=2))
```

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

### Monolix-like customisation

User can customize the options to get a Monolix-like display.

``` r
ctr %>% pmx_plot_vpc(
strat.facet="SEX",
strat.facet=~SEX,
facets=list(nrow=2),
type="percentile",
is.draft = FALSE,
Expand All @@ -923,36 +937,37 @@ ctr %>% pmx_plot_vpc(
)
```

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

# Diagnostics report

A report (in pdf and docx format) containing all default diagnostic
plots can be created using the *pmx\_report* function. The *format* can
plots can be created using the *pmx\_report* function. The *output* can
take three different values:

- “report”: produces a pdf and a docx file (named `name.pdf` and
`name.png` specified in argument *name*, located in *save\_dir*)
with default diagnostic plots
- “plots”: produces a folder named after *plots_subdir* parameter `ggpmx_GOF` located in *save\_dir*
that contains all default diagnotic plots, each in a pdf and png
file. The different plots are numerated in order to have an unique
identifier for each plot (ex: ebe\_box-1.pdf). This is necessary for
having correct footnotes that indicated the path to the source file
(for submission reports).
- “both”: is a combination of both options above.
- “plots”: produces a folder named after *plots\_subdir* parameter
(`ggpmx_GOF` by default, if parameter is not specified) located in
*save\_dir* that contains all default diagnostic plots, each in a
pdf and png file. The different plots are numerated in order to have
an unique identifier for each plot (ex: ebe\_box-1.pdf). This is
necessary for having correct footnotes that indicated the path to
the source file (for submission reports).
- “all”: is a combination of both options above.

Example:

``` r
ctr %>% pmx_report(name='Diagnostic_plots2',
save_dir = work_dir,
plots_subdir = "ggpmx_report",
format='both')
output='all')
```

Note that running the same command first with the option
format=‘plots’” and then with the option “format=‘report’” will
output=‘plots’” and then with the option “output=‘report’” will
remove the *ggpmx\_GOF* folder.

Note also that by default, the report will have the DRAFT label on all
Expand All @@ -967,7 +982,7 @@ the following command:
ctr %>% pmx_report(name='Diagnostic_plots1',
save_dir = work_dir,
plots_subdir = "ggpmx_report",
format='report')
output='report')
```

The Rmarkdown (.Rmd) file is the “template”. The user can modify the
Expand All @@ -979,7 +994,7 @@ command:
ctr %>% pmx_report(name='Diagnostic_plots3',
save_dir = work_dir,
plots_subdir = "ggpmx_report",
format='report',
output='report',
template=file.path(work_dir,'Diagnostic_plots1.Rmd'))
```

Expand Down Expand Up @@ -1084,6 +1099,7 @@ all plots. In order to switch this label off, the user sets the
`is.draft` option of `pmx_settings()` to `FALSE`.

``` r

ctr <- theophylline(settings = pmx_settings(is.draft = FALSE))
```

Expand Down Expand Up @@ -1371,10 +1387,10 @@ plot types.

``` r
args(pmx_gpar)
#> function (labels, axis.title, axis.text, ranges, is.smooth, smooth,
#> is.band, band, is.draft, draft, discrete, is.identity_line,
#> identity_line, scale_x_log10, scale_y_log10, color.scales,
#> is.legend, legend.position)
#> function (is.title, labels, axis.title, which_pages, print, axis.text,
#> ranges, is.smooth, smooth, is.band, band, is.draft, draft,
#> discrete, is.identity_line, identity_line, smooth_with_bloq,
#> scale_x_log10, scale_y_log10, color.scales, is.legend, legend.position)
#> NULL
```

Expand Down Expand Up @@ -1447,11 +1463,16 @@ ctr %>% pmx_comp_shrink( fun = "var")
```

``` r
ctr %>% pmx_plot_eta_box( shrink=list(fun = "var"))
ctr %>% pmx_plot_eta_box( shrink=pmx_shrink(fun = "var"))
```

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

Note that for plotting functions which take a shrink parameter, this can
be created using the `pmx_shrink` function to create a `pmxShrinkClass`
object (or it can be a list which can be converted into such an object
using `pmx_shrink`).

## Shrinkage and stratification

Shrinkage can be applied after stratification :
Expand Down Expand Up @@ -1494,4 +1515,4 @@ ctr %>% pmx_plot_eta_box(is.shrink = TRUE, strat.facet = "SEX",
facets=list(scales="free_y",ncol=2))
```

<img src="man/figures/README-unnamed-chunk-41-1.png" width="100%" />
<img src="man/figures/README-unnamed-chunk-45-1.png" width="100%" />
Binary file modified man/figures/README-illustrate_diagnostic-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-illustrate_diagnostic-4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-illustrate_diagnostic-5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-settings_cat_labels3-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-settings_color_scales_local-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-settings_solor_scales-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-settings_solor_scales_a-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-settings_use.finegrid-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-shrink_plot_box-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-shrink_plot_hist-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-shrink_plot_no-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-shrink_plot_strat-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-shrink_plot_var-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-26-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-27-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-28-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-29-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-30-1.png
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-31-1.png
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-45-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2278417

Please sign in to comment.