An open API service indexing awesome lists of open source software.

https://github.com/nlmixr2/monolix2rx

Convert Monolix models to nlmixr2/rxode2 models
https://github.com/nlmixr2/monolix2rx

monolix nlmixr2 pharmacometrics rxode2

Last synced: 29 days ago
JSON representation

Convert Monolix models to nlmixr2/rxode2 models

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# monolix2rx

[![R-CMD-check](https://github.com/nlmixr2/monolix2rx/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nlmixr2/monolix2rx/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/nlmixr2/monolix2rx/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nlmixr2/monolix2rx?branch=main)
[![CRAN
version](http://www.r-pkg.org/badges/version/monolix2rx)](https://cran.r-project.org/package=monolix2rx)
[![CRAN total
downloads](https://cranlogs.r-pkg.org/badges/grand-total/monolix2rx)](https://cran.r-project.org/package=monolix2rx)
[![CRAN total
downloads](https://cranlogs.r-pkg.org/badges/monolix2rx)](https://cran.r-project.org/package=monolix2rx)
[![CodeFactor](https://www.codefactor.io/repository/github/nlmixr2/monolix2rx/badge)](https://www.codefactor.io/repository/github/nlmixr2/monolix2rx)
![r-universe](https://nlmixr2.r-universe.dev/badges/monolix2rx)

The goal of monolix2rx is to convert `Monolix` to `rxode2` to use for
simulation and sharing the model in an open-source framework.

## Installation

You can install the development version of monolix2rx from
[GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("nlmixr2/monolix2rx")
```
## What you can do with `monolix2rx`/`babelmixr2`

You can do many useful tasks directly converting between nlmixr2 and
NONMEM models; you can:

- [Convert a Monolix model to a rxode2/nlmixr2 model](https://nlmixr2.github.io/monolix2rx/articles/convert-nlmixr2.html)

Then with nlmixr2 fit models and monolix2rx models coming from both conversions, you can:

- [Perform simulations of new
dosing](https://nlmixr2.github.io/monolix2rx/articles/simulate-new-dosing.html) from the Monolix model or even [simulate using the uncertainty in your model to simulate new scenarios](https://nlmixr2.github.io/monolix2rx/articles/simulate-uncertainty.html)

- [Modify the model to calculate derived parameters](https://nlmixr2.github.io/monolix2rx/articles/simulate-extra-items.html) (like AUC). These parameters slow down Monolix’s optimization, but can help in your simulation scenario.

- [Simulating with Covariates/Input PK
parameters](https://nlmixr2.github.io/monolix2rx/articles/simulate-new-dosing-with-covs.html). This example shows approaches to resample from the input dataset for covariate selection.

With nonmem2rx and babelmixr2, convert the imported rxode2 model to a nlmixr2 object, allowing:

- [Generation of Word and PowerPoint plots with
nlmixr2rpt](https://nlmixr2.github.io/monolix2rx/articles/create-office.html)

- [Easy VPC
creation](https://nlmixr2.github.io/monolix2rx/articles/create-vpc.html)
(with `vpcPlot()`)

- [Easy Individual plots with extra solved
points](https://nlmixr2.github.io/monolix2rx/articles/create-augPred.html). This
will show the curvature of individual and population fits for
sparse data-sets (with `augPred()`)

## Example

If you are trying to convert a Monolix to a rxode2 model you simply
need the path to the `mlxtran` file. For example, the classic demo of
theophylline is included in `monolix2rx` and can be imported below:

```{r example}
library(monolix2rx)
# First load in the model; in this case the theo model
# This is modified from the Monolix demos by saving the model
# file as a text file (hence you can access without model library).
# Additionally some of the file paths were shortened so they could
# be included with monolix2rx

pkgTheo <- system.file("theo", package="monolix2rx")
mlxtranFile <- file.path(pkgTheo, "theophylline_project.mlxtran")

rx <- monolix2rx(mlxtranFile)

rx

# If you are only interseted in the parsing you can use `mlxtran`

mlx <- mlxtran(mlxtranFile)

mlx

# this can be converted to a list
mlx <- as.list(mlx)

mlx$DATAFILE$FILEINFO$FILEINFO
```

## Translating models from the Monolix model library

For models using Monolix's model library, the models may not be
accessible as text files in all versions of Monolix. In the `mlxtran`
files you may see something like:

```
lib:bolus_1cpt_TlagVCl.txt
```

For older versions of Monolix, the model libraries are a group of text
files. You can find it by looking for a file in the Monolix library
like `bolus_1cpt_TlagVCl.txt`. In this case it would be in
`pk/bolus_1cpt_TlagVCl.txt`. The parent directory would be the model
library. If you have access to these files (even if they are from an
old version of Monolix) you can make `monolix2rx` aware of the model
library by using:

```{r setupLib}
# If the model library was located in ~/src/monolix/library
# Then you would set the model library up as follows:
options(monolix2rx.library="~/src/monolix/library/")
```

In Unix, this can be a symbolic link to whatever model library you
would like to use.

You can check to see if it works by trying to translate the model file
to `rxode2`:

```{r monolix2rxLib}
monolix2rx("lib:bolus_1cpt_TlagVCl.txt")
```

If you computer is setup correctly (like above) you will see the
translated model. Note since it isn't a `mlxtran` file the
relationship between population parameters, between subject
variability etc and initial parameter estimates are not in the model.

If the model library is not setup correctly you will see or cannot be
found in an old model library you get:

```{r monolix2rxLib2}
try(monolix2rx("lib:notThere.txt"))
```

In newer versions of Monolix, the model library was turned into a
binary database that is accessed by the GUI and `lixoftConnectors`.
If you have `lixoftConnectors` on your system and it can successfully
load the model with `lixoftConnectors::getLibraryModelContent()` then
`monolix2rx` will also load the model correctly (and will use this
version over the text files when both are setup)

This means you will need to import models into `rxode2` you need to:

- For a model built from the model library you will need:

- have a path to the text file Monolix Library and setup the
`monolix2rx.library` with
`options(monolix2rx.library="~/src/monolix/library/")`

- have `lixoftConnectors` installed and connected to a newer (and
licensed) version of Monolix that can get the model library
content by `lixoftConnectors::getLibraryModelContent()`

- or without these options, you will need to save the model to a
text file outside of the model library so you can import the model.

# Note on testing

The tests in this package include testing the `Monolix` demo files,
the `Monolix` library files (if available), and Monolix validation
suite.

Since these are a part of Monolix itself, they are not included in
this package. You can setup `monolix2rx` to run tests on all of these
files as well by setting up some options:

``` r
# setup monolix library (and will test that the parsing and translation are as expected)
options(monolix2rx.library="~/src/monolix/library/")
# setup monolix demos to be tested
options(monolix2rx.demo="~/src/monolix/demos/")
```