Type: Package
Title: Application of NODEs in 'Monolix', 'NONMEM', and 'nlmixr2'
Version: 0.1.0
Description: An easy-to-use tool for implementing Neural Ordinary Differential Equations (NODEs) in pharmacometric software such as 'Monolix', 'NONMEM', and 'nlmixr2', see Bräm et al. (2024) <doi:10.1007/s10928-023-09886-4> and Bräm et al. (2025) <doi:10.1002/psp4.13265>. The main functionality is to automatically generate structural model code describing computations within a neural network. Additionally, parameters and software settings can be initialized automatically. For using these additional functionalities with 'Monolix', 'pmxNODE' interfaces with 'MonolixSuite' via the 'lixoftConnectors' package. The 'lixoftConnectors' package is distributed with 'MonolixSuite' (https://monolixsuite.slp-software.com/r-functions/2024R1/package-lixoftconnectors) and is not available from public repositories.
License: GPL (≥ 3)
Encoding: UTF-8
RoxygenNote: 7.3.3
Suggests: rxode2, nlmixr2, lixoftConnectors, withr, testthat (≥ 3.0.0), knitr, rmarkdown
Imports: tidyr, ggplot2, checkmate
Config/testthat/edition: 3
BugReports: https://github.com/braemd/pmxNODE/issues
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2025-11-19 13:00:17 UTC; BraemD
Author: Dominic Bräm ORCID iD [aut, cre], Bernhard Steiert [ctb], Gilbert Koch [ctb], Matthew Fidler ORCID iD [ctb]
Maintainer: Dominic Bräm <domi.braem@hotmail.com>
Repository: CRAN
Date/Publication: 2025-11-26 09:20:02 UTC

Neural Network ODE language in nlmixr2 langauage

Description

Neural Network ODE language in nlmixr2 langauage

Usage

NN(
  number = 1,
  state = "t",
  min_init = 0.5,
  max_init = 10,
  n_hidden = 5,
  act = c("ReLU", "Softplus"),
  time_nn = FALSE,
  beta = 20,
  pop = getOption("pmxNODE.pop", TRUE),
  eta_model = c("prop", "add"),
  theta_scale = 0.1,
  eta_scale = 0.1,
  pre_fixef = getOption("pmxNODE.pre_fixef", NULL),
  iniDf = NULL
)

Arguments

number

The neural network number

state

The state to be used in the neural network. For time, use t

min_init

The minimum value of activation point for the neural network, (i.e., minimal expected state value)

max_init

The maximum value of activation point for the NN (i.e. maximum expected state value)

n_hidden

The number of hidden layers in the neural network (default 5)

act

activation in the hidden layer, ReLU and Softplus implemented. Default is ReLU.

time_nn

defines if the neural network is time dependent and consequently all weights from inputs to hidden layer should be strictly negative (default is FALSE)

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

pop

(boolean) If the generated nlmixr model function should be a fit without (TRUE) or with (FALSE). Default is FALSE.

eta_model

(string)

  • “prop” is of form W = lW * EXP(etaW)

  • “add” is of form W = lW + etaW

theta_scale

(numeric) Scale in which typical NN parameter values are initialized, default is 0.1, i.e., weights are initialized between -0.3 and 0.3

eta_scale

(numeric) Initial standard deviation of random effects on NN parameters, default is 0.1

pre_fixef

(named vector) Specific initial values for typical parameters, can be obtained from a run nlmixr model (e.g., run_1) through run_1$fixef

iniDf

iniDf

Value

A list with the before and replace elements and iniDf to allow integration in the rxode2/nlmixr2 language directly.

Author(s)

Matthew L Fidler (uses the same functions 'nn_generator_nlmixr', written by Dominic Bräm)

Examples

## Not run: 
 if (requireNamespace("rxode2", quietly = TRUE)) {

# Called directly, this isn't that interesting, but can show what
# is produced for rxode2 integration

library(rxode2)

NN(1, state="t", min_init=0.1, max_init=24, pop=TRUE)

# This can be used in the rxode2 language as follows:

f_ode_pop <- function(){
  ini({
    lV <- 1
    prop.err <- 0.1
  })
  model({
    V <- lV
    d/dt(centr)  =  NN(1, state=centr,min_init=0,max_init=300)
    cp = centr / V
    cp ~ prop(prop.err)
  })
}

# but it expands to the complete model:

f_ode_pop()

# This is because pmxNODE uses the extensible user model interface
# in rxode2.  This only works if you load rxode2/nlmixr2 and pmxNODE

}

## End(Not run)

Change a population Neural Network model to a model with between subject variability

Description

This only changes the Neural Network model to add between subject variability. It assumes the following parameter structure

Usage

NNbsv(ui, val = 0.1, str = "%s <- l%s*exp(eta.%s)", warn = FALSE)

Arguments

ui

– nlmixr2 fit or rxode2 model function to modify and add between subject variabilities to the neural network.

val

– initial value for the added etas

str

– String used to construct the eta expressions. The default is " to the 'eta' variable. If desired you can try different forms for the between subject variables.

warn

– boolean; Should you warn or error if the element is not a nlmixr2 fit

Value

modified model with between subject variabilities added for neural-network components.

Author(s)

Matthew L. Fidler

Examples

## Not run: 
f_ode_pop <- function(){
  ini({
    lV <- 1
    prop.err <- 0.1
  })
  model({
    V <- lV
    d/dt(centr)  =  NN(1, state=centr,min_init=0,max_init=300)
    cp = centr / V
    cp ~ prop(prop.err)
  })
}

f_ode_pop() %>% NNbsv(.2, warn=TRUE)

## End(Not run)

Copy examples to your folder

Description

This function allows to copy one or multiple examples (data and model files) to a directory of your choice.
Either examples, example_nr, example_software, or example_nr + example_software must be given.

Usage

copy_examples(
  target_folder,
  examples = NULL,
  example_nr = NULL,
  example_software = NULL,
  pkg_name = "pmxNODE"
)

Arguments

target_folder

(string) Path to the folder the examples should be copied to

examples

(vector of strings) Explicit names of example data and/or model files to be copied. Must be in the example list obtained by get_example_list()

example_nr

(numeric) Number of example data and model to be copied. If example_software is not specified, examples with example_nr for all software will be copied.

example_software

(string) Software of example data and model to be copied. Either “Monolix” or “NONMEM” available. If example_nr is not specified, all examples for this software will be copied.

pkg_name

(string) Only required in development phase

Value

Copied examples in specified folder.

Author(s)

Dominic Bräm

Examples

## Not run: 
copy_examples("path/to/target/folder",
              examples = c("data_example1_mlx.csv","mlx_example1_model.txt"))
copy_examples("path/to/target/folder",example_nr = 1)
copy_examples("path/to/target/folder",example_software = "Monolix")
copy_examples("path/to/target/folder",example_nr = 1, example_software = "NONMEM")

## End(Not run)

Generate Derivative versus State Plot (Monolix)

Description

This functions allows to generate a derivative versus state plot for a neural network from a NODE in Monolix.

Usage

der_state_plot_mlx(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  mlx_file = NULL,
  time_nn = FALSE,
  act = "ReLU",
  length_out = 100,
  plot_type = c("base", "ggplot"),
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

length_out

(numeric) Number of points between min_state and max_state

plot_type

(string) What plot type should be used; "base" or "ggplot"

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

Displaying derivative versus state plot; returns ggplot-object if plot_type="ggplot"

Author(s)

Dominic Bräm

Examples

mlx_path <- system.file("extdata","mlx_example1_ind.mlxtran",package="pmxNODE")
der_state_plot <- der_state_plot_mlx(nn="c",
                                     min_state=0,max_state=10,
                                     mlx_file=mlx_path,
                                     plot_type="ggplot")

Generate Derivative versus State Plot (nlmixr2)

Description

This functions allows to generate a derivative versus state plot for a neural network from a NODE in nlmixr2

Usage

der_state_plot_nlmixr(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  fit_obj = NULL,
  length_out = 100,
  time_nn = FALSE,
  act = "ReLU",
  plot_type = c("base", "ggplot"),
  beta = 20
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through fit$fixef. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...). For optionality, see Details.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

plot_type

(string) What plot type should be used; "base" or "ggplot"

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Either est_parms or fit_obj must be given. If both arguments are given, est_parms is prioritized.

Value

Displaying derivative versus state plot; returns ggplot-object if plot_type="ggplot"

Author(s)

Dominic Bräm

Examples

## Not run: 
pop_fit <- nlmixr2(node_model_pop,data=data,est="bobyqa")
der_state_plot <- der_state_plot_nlmixr(nn="c",
                                        min_state=0,max_state=10,
                                        fit_obj=pop_fit,
                                        plot_type="ggplot")

## End(Not run)

Generate Derivative versus State Plot (NONMEM)

Description

This functions allows to generate a derivative versus state plot for a neural network from a NODE in NONMEM. Can also be used for nlmixr2.

Usage

der_state_plot_nm(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  nm_res_file = NULL,
  length_out = 100,
  time_nn = FALSE,
  act = "ReLU",
  plot_type = c("base", "ggplot"),
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_nm function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

plot_type

(string) What plot type should be used; "base" or "ggplot"

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or nm_res_file must be given. If both arguments are given, est_parms is prioritized.

Value

Displaying derivative versus state plot; returns ggplot-object if plot_type="ggplot"

Author(s)

Dominic Bräm

Examples

res_path <- system.file("extdata","nm_example1_model_converted_ind.res",package="pmxNODE")
der_state_plot <- der_state_plot_nm(nn="c",
                                    min_state=0,max_state=10,
                                    nm_res_file=res_path,
                                    plot_type="ggplot")

Generate Derivative versus State (Monolix)

Description

This functions allows to generate derivative versus state data for a neural network from a NODE in Monolix.

Usage

der_vs_state_mlx(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  mlx_file = NULL,
  length_out = 100,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the state and the corresponding derivatives

Author(s)

Dominic Bräm


Generate Derivative versus State (nlmixr2)

Description

This functions allows to generate derivative versus state data for a neural network from a NODE in nlmixr2.

Usage

der_vs_state_nlmixr(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  fit_obj = NULL,
  length_out = 100,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) Named vector of estimated parameters form fit$fixef. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...). For optionality, see Details.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Either est_parms or fit_obj must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the state and the corresponding derivatives

Author(s)

Dominic Bräm


Generate Derivative versus State (NONMEM)

Description

This functions allows to generate derivative versus state data for a neural network from a NODE in NONMEM. Can also be used for nlmixr2.

Usage

der_vs_state_nm(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  nm_res_file = NULL,
  length_out = 100,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or nm_res_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the state and the corresponding derivatives

Author(s)

Dominic Bräm


Internal: Calculate the derivatives from a NN in Monolix

Description

Calculate the derivatives from a NN for derivative versus state plots

Usage

derivative_calc_mlx(
  nn_name,
  parms,
  inputs,
  n_hidden = 5,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

parms

(named vector) Named vector of estimated parameters from the NN; Namings are e.g. Wc_11 for the weight from input to the first hidden unit of NN called "c"

inputs

(vector) Vector cointain the state values for which the derivatives should be calculated

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

time_nn

(boolean) Whether the NN is a time-dependent NN and negative weights should be applied from input to hidden layer. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Value

A vector of derivatives of the NN for the state values

Author(s)

Dominic Bräm


Internal: Calculate the derivatives from a NN in NONMEM

Description

Calculate the derivatives from a NN for derivative versus state plots. Can also be used for nlmixr2.

Usage

derivative_calc_nm(
  nn_name,
  parms,
  inputs,
  n_hidden = 5,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

parms

(named vector) Named vector of estimated parameters from the NN; Namings are e.g. Wc_11 for the weight from input to the first hidden unit of NN called "c"

inputs

(vector) Vector cointain the state values for which the derivatives should be calculated

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

time_nn

(boolean) Whether the NN is a time-dependent NN and negative weights should be applied from input to hidden layer. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Value

A vector of derivatives of the NN for the state values

Author(s)

Dominic Bräm


Finde path to NONMEM nmfe file

Description

To run a NONMEM model, a NONMEM nmfeXX file is required, with XX the NONMEM version. When opening the NONMEM command prompt, working directory is usually set to folder, where the nmfe file is located. When running NONMEM from R (with the run_nm function), the path and the nmfe file must be provided (as the nm_path argument). To facilitate the search for the nmfe file, this function can be used.

Usage

find_nmfe(root = "C:/")

Arguments

root

(string) Path to the root where NONMEM was installed. Default is "C:/", working if NONMEM was installed directly into the C drive.

Details

This function assumes that the path to the nmfe file is "root/nmXXXX/run/nmfeXX, with XXXX as the NONMEM version. If any special installation settings were applied, this function might not be working.

Value

Path and name of NONMEM nmfe file, that can directly be used as nm_path argument in the run_nm function.

Author(s)

Dominic Bräm

Examples

## Not run: 
nmfe_path <- find_nmfe()
run_nm(ctl_file="./test/nm_test.ctl",nm_path=nmfe_path,create_dir=FALSE)

## End(Not run)

List of examples available

Description

Get a list of examples available in this package

Usage

get_example_list(pkg_name = "pmxNODE")

Arguments

pkg_name

(string) Only required in development phase

Details

Value

A list of all examples available

Author(s)

Dominic Bräm

Examples

example_list <- get_example_list()

Generate Derivative versus State Plot for individual parameter estimates (Monolix)

Description

This functions allows to generate a derivative versus state plot for a neural network from a NODE in Monolix with individual parameter estimates (EBEs).

Usage

ind_der_state_plot_mlx(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  mlx_file = NULL,
  time_nn = FALSE,
  act = "ReLU",
  ribbon = TRUE,
  length_out = 100,
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

ribbon

(boolean) Whether individual derivatives versus states should be summarise in a ribbon (TRUE) or displayed as individual spaghetti plot (FALSE)

length_out

(numeric) Number of points between min_state and max_state

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

Displaying derivative versus state plot

Author(s)

Dominic Bräm

Examples

mlx_path <- system.file("extdata","mlx_example1_ind.mlxtran",package="pmxNODE")
der_state_plot <- ind_der_state_plot_mlx(nn="c",
                                         min_state=0,max_state=10,
                                         mlx_file=mlx_path)


Generate Derivative versus State Plot for individual parameter estimates (nlmixr2)

Description

This functions allows to generate a derivative versus state plot for a neural network from a NODE in nlmixr2 with individual parameter estimates (EBEs).

Usage

ind_der_state_plot_nlmixr(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  fit_obj = NULL,
  length_out = 100,
  time_nn = FALSE,
  ribbon = TRUE,
  act = "ReLU",
  beta = 20
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nlmixr function. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...), fitted with IIV. For optionality, see Details.

length_out

(numeric) Number of points between min_state and max_state

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

ribbon

(boolean) Whether individual derivatives versus states should be summarise in a ribbon (TRUE) or displayed as individual spaghetti plot (FALSE)

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Either est_parms or fit_obj must be given. If both arguments are given, est_parms is prioritized.

Value

Displaying derivative versus state plot

Author(s)

Dominic Bräm

Examples

## Not run: 
ind_fit <- nlmxir2(node_model_ind,data=data,est="saem")
der_state_plot <- ind_der_state_plot_nlmixr(nn="c",min_state=0,max_state=10,
                                            fit_obj=ind_fit)

## End(Not run)

Generate Derivative versus State Plot for individual parameter estimates (NONMEM)

Description

This functions allows to generate a derivative versus state plot for a neural network from a NODE in NONMEM with individual parameter estimates (EBEs).

Usage

ind_der_state_plot_nm(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  nm_res_file = NULL,
  nm_phi_file = NULL,
  length_out = 100,
  time_nn = FALSE,
  ribbon = TRUE,
  act = "ReLU",
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nm function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

nm_phi_file

(string; semi-optional) (path)/name of the phi file of a NONMEM run, must include file extension “.phi”. For optionality, see Details.

length_out

(numeric) Number of points between min_state and max_state

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

ribbon

(boolean) Whether individual derivatives versus states should be summarise in a ribbon (TRUE) or displayed as individual spaghetti plot (FALSE)

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or nm_res_file and nm_phi_file must be given. If both arguments are given, est_parms is prioritized.

Value

Displaying derivative versus state plot

Author(s)

Dominic Bräm

Examples

res_path <- system.file("extdata","nm_example1_model_converted_ind.res",package="pmxNODE")
phi_path <- system.file("extdata","nm_example1_model_converted_ind.phi",package="pmxNODE")
der_state_plot <- ind_der_state_plot_nm(nn="c",min_state=0,max_state=10,
                                        nm_res_file=res_path,
                                        nm_phi_file=phi_path)

Generate Derivative versus State with individual parameters (Monolix)

Description

This functions allows to generate derivative versus state data for a neural network from a NODE in Monolix with individual parameters.

Usage

ind_der_vs_state_mlx(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  mlx_file = NULL,
  time_nn = FALSE,
  length_out = 100,
  act = "ReLU",
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the state and the corresponding individual derivatives

Author(s)

Dominic Bräm


Generate Derivative versus State with individual parameters (nlmixr)

Description

This functions allows to generate derivative versus state data for a neural network from a NODE in nlmixr2 with individual parameters.

Usage

ind_der_vs_state_nlmixr(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  fit_obj = NULL,
  length_out = 100,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nlmixr function. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...), fitted with IIV. For optionality, see Details.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Either est_parms or nm_res_file and nm_phi_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the state and the corresponding individual derivatives

Author(s)

Dominic Bräm


Generate Derivative versus State with individual parameters (NONMEM)

Description

This functions allows to generate derivative versus state data for a neural network from a NODE in NONMEM with individual parameters.

Usage

ind_der_vs_state_nm(
  nn_name,
  min_state = NULL,
  max_state = NULL,
  inputs = NULL,
  est_parms = NULL,
  nm_res_file = NULL,
  nm_phi_file = NULL,
  length_out = 100,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20,
  transform = NULL
)

Arguments

nn_name

(string) Name of the NN, e.g., “c” for NNc(...)

min_state

(numeric) Value of minimal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

max_state

(numeric) Value of maximal state for which the derivative should be calculated (optional if inputs is given, ignored if inputs is defined)

inputs

(numeric vector) Vector of input values for which derivatives should be calculated (optional if min_state and max_state is given)

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nm function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

nm_phi_file

(string; semi-optional) (path)/name of the phi file of a NONMEM run, must include file extension “.phi”. For optionality, see Details.

length_out

(numeric) Number of states between min_state and max_state for derivative calculations.

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

transform

(string) Mathematical exression as string to transform the NN output. Independent variable must be called NN, e.g., "1/(1+exp(-NN))" for sigmoidal transformation.

Details

Either est_parms or nm_res_file and nm_phi_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the state and the corresponding individual derivatives

Author(s)

Dominic Bräm


Generate individual Right-hand side data (Monolix)

Description

This functions allows to generate right-hand side data for multiple individuals with individual parameter sets, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

ind_rhs_calc_mlx(
  rhs,
  inputs,
  group,
  est_parms = NULL,
  mlx_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

group

(string) Name of column in inputs dataframe defining groups/individuals.

est_parms

(dataframe; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the inputs and the combined right-hand side data.

Author(s)

Dominic Bräm


Generate individual Right-hand side data (nlmixr2)

Description

This functions allows to generate right-hand side data for multiple individuals with individual parameter sets, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

ind_rhs_calc_nlmixr(
  rhs,
  inputs,
  group,
  est_parms = NULL,
  fit_obj = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

group

(string) Name of column in inputs dataframe defining groups/individuals.

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nlmixr function. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...), fitted with IIV. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or fit_obj must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the inputs and the combined right-hand side data.

Author(s)

Dominic Bräm


Generate individual Right-hand side data (NONMEM)

Description

This functions allows to generate right-hand side data for multiple individuals with individual parameter sets, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

ind_rhs_calc_nm(
  rhs,
  inputs,
  group,
  est_parms = NULL,
  nm_res_file = NULL,
  nm_phi_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

group

(string) Name of column in inputs dataframe defining groups/individuals.

est_parms

(dataframe; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nm function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

nm_phi_file

(string; semi-optional) (path)/name of the phi file of a NONMEM run, must include file extension “.phi”. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or nm_res_file and nm_phi_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the inputs and the combined right-hand side data.

Author(s)

Dominic Bräm


Generate individual Right-hand side data plot (Monolix)

Description

This functions allows to generate a right-hand side plot with multiple subjects, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

ind_rhs_plot_mlx(
  rhs,
  x_var,
  inputs,
  group,
  est_parms = NULL,
  mlx_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

x_var

(string) Name of the variable in inputs against which the right-hand data should be plotted.

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

group

(string) Name of column in inputs dataframe defining groups/individuals.

est_parms

(dataframe; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

ggplot of right-hand side plot for all individuals

Author(s)

Dominic Bräm

Examples

# Generate individual rhs-plot for predicted observations

mlx_path <- system.file("extdata","mlx_example1_ind.mlxtran",package="pmxNODE")
data_path <- system.file("extdata","mlx_example1_ind","predictions.txt",package="pmxNODE")

est_parms <- indparm_extractor_mlx(mlx_path)

input_data <- read.table(data_path,sep=",",header=TRUE)[,c("id","indivPred_mode","time")]
colnames(input_data) <- c("id","NNc","NNct")
                  
rhs_plot <- ind_rhs_plot_mlx(rhs="NNc + NNct",
                             x_var = "NNc",
                             group = "id",
                             inputs = input_data,
                             est_parms = est_parms,
                             time_nn = c(FALSE, TRUE))

Generate individual Right-hand side data plot (nlmixr2)

Description

This functions allows to generate a right-hand side plot with multiple subjects, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

ind_rhs_plot_nlmixr(
  rhs,
  x_var,
  inputs,
  group,
  est_parms = NULL,
  fit_obj = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

x_var

(string) Name of the variable in inputs against which the right-hand data should be plotted.

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

group

(string) Name of column in inputs dataframe defining groups/individuals.

est_parms

(named vector; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nlmixr function. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...), fitted with IIV. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or fit_obj must be given. If both arguments are given, est_parms is prioritized.

Value

ggplot of right-hand side for all individuals.

Author(s)

Dominic Bräm

Examples

## Not run: 
ind_fit <- nlmxir2(node_model_ind,data=data,est="saem")
rhs_plot <- ind_rhs_plot_mlx(rhs="NNc + NNct",
                             x_var = "NNc",
                             group = "id",
                             inputs = input_data,
                             fit_obj = ind_fit)

## End(Not run)

Generate individual Right-hand side data plot (NONMEM)

Description

This functions allows to generate a right-hand side plot with multiple subjects, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

ind_rhs_plot_nm(
  rhs,
  x_var,
  inputs,
  group,
  est_parms = NULL,
  nm_res_file = NULL,
  nm_phi_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

x_var

(string) Name of the variable in inputs against which the right-hand data should be plotted.

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

group

(string) Name of column in inputs dataframe defining groups/individuals.

est_parms

(dataframe; semi-optional) A data frame with estimated individual parameters from the NN extracted through the indparm_extractor_nm function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

nm_phi_file

(string; semi-optional) (path)/name of the phi file of a NONMEM run, must include file extension “.phi”. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

ggplot of right-hand side plot for all individuals

Author(s)

Dominic Bräm

Examples

# Generate individual rhs-plot for predicted observations

res_path <- system.file("extdata","nm_example1_model_converted_ind.res",package="pmxNODE")
phi_path <- system.file("extdata","nm_example1_model_converted_ind.phi",package="pmxNODE")
data_path <- system.file("extdata","nm_example1.tab",package="pmxNODE")

est_parms <- indparm_extractor_nm(res_path,phi_path)

input_data <- read.table(data_path,skip=1,header=TRUE)[,c("ID","IPRED","TIME")]
colnames(input_data) <- c("ID","NNc","NNt")
                  
rhs_plot <- ind_rhs_plot_nm(rhs="NNc + NNt",
                             x_var = "NNc",
                             inputs = input_data,
                             group = "ID",
                             est_parms=est_parms,
                             time_nn = c(FALSE, TRUE))

Monolix individual estimations extractor

Description

When the Monolix model has been run, this function allows to extract the estimated individual parameters (EBEs) from the Monolix run folder.

Usage

indparm_extractor_mlx(model_name)

Arguments

model_name

(string) Name of the Monolix run. Must include “.mlxtran”

Value

Data frame with individual parameter estimates (EBEs)

Author(s)

Dominic Bräm

Examples

mlx_path <- system.file("extdata","mlx_example1_ind.mlxtran",package="pmxNODE")
est_parms <- indparm_extractor_mlx(mlx_path)

nlmixr individual estimations extractor

Description

When the nlmixr model has been run, this function allows to extract the estimated individual parameters for NN parameters by combining fixed effects and random effects

Usage

indparm_extractor_nlmixr(fit_obj)

Arguments

fit_obj

Nlmixr fit object with random effects on NN parameters

Value

Data frame with individual parameter estimates for NN parameters

Author(s)

Dominic Bräm

Examples

## Not run: 
fit_ind <- nlmixr(model_with_iiv,data=data,est="saem")
est_parms <- indparm_extractor_nlmixr(fit_ind)

## End(Not run)

NONMEM individual estimations extractor

Description

When the NOMEM model has been run, this function allows to extract the estimated individual parameters for NN parameters by combining information from the .res and the .phi file

Usage

indparm_extractor_nm(res_file, phi_file)

Arguments

res_file

(Path/)Name of the results file of a NONMEM run, must include file extension, e.g., “.res”

phi_file

(Path/)Name of the phi file of a NONMEM run, must include file extension, e.g., “.phi”

Value

Data frame with individual parameter estimates for NN parameters

Author(s)

Dominic Bräm

Examples

res_path <- system.file("extdata","nm_example1_model_converted_ind.res",package="pmxNODE")
phi_path <- system.file("extdata","nm_example1_model_converted_ind.phi",package="pmxNODE")
est_parms <- indparm_extractor_nm(res_path,phi_path)

Internal: Monolix file initializer

Description

Initializes a .mlxtran file based on a converted model file, data, and initial values

Usage

mlx_model_initializer(
  model_name,
  model_file,
  data_file,
  header_types,
  parm_names,
  parm_inis,
  theta_names,
  theta_inis,
  pop = FALSE,
  omega_inis = NULL,
  pre_fixef = NULL,
  obs_types = NULL,
  mapping = NULL
)

Arguments

model_name

(string) (Path/)Name of generated .mlxtran file

model_file

(string) (Path/)Name of converted structural model

data_file

(string) (Path/)Name of data file to be fitted

header_types

(vector) Vector of strings describing column types of data

parm_names

(list) List of names of non-NN parameters in the model

parm_inis

(list) List of initial values of non-NN parameters

theta_names

(list) List of names of NN parameters in the model, i.e., weights and biases

theta_inis

(list) List of initial values of NN parameters

pop

(boolean) If only population fit without inter-individual variability (TRUE) or individual fits with inter-individual variability (FALSE) should be used

omega_inis

(numeric) Initial standard deviation of random effects on NN parameters; standard 0.1 from nn_converter_mlx

pre_fixef

(named vector) Named vector of all initial values to be used for NN and non-NN parameters

obs_types

(list) List of types of observations, e.g., “continuous”; only required if non-continuous observations

mapping

(list) List of mapping between model outputs and observation IDs

Details

If no specific file name was given to nn_converter_mlx through the mlx_name argumen, the file is standardized to name of model file_mlx_file_pop/ind where pop if pop=TRUE or ind if pop=FALSE in nn_converter_mlx.

Value

No return value, saving a Monolix .mlxtran file.

Author(s)

Dominic Bräm


Internal: Extract model parameters

Description

Extract model parameters and corresponding initial values from the model input line

Usage

model_parm_extractor_mlx(text)

Arguments

text

(list of strings) The Monolix model witch each line as element of list

Value

Author(s)

Dominic Bräm


Internal: Update input line

Description

Update a Monolix model input to define non-NN and NN parameters as model inputs

Usage

model_parm_updater_mlx(text, model_parm_names, nn_thetas)

Arguments

text

(list of strings) The Monolix model with each line as element of a list

model_parm_names

(list of strings) A list of all non-NN parameters

nn_thetas

(list of strings) A list of all NN parameters

Value

The Monolix model including all non-NN and NN parameters in input = ...

Author(s)

Dominic Bräm


Internal: Extract activation function of a NN

Description

Extract the activation function to be used for a NN given as the act argument in the NN function

Usage

nn_act_extractor(text)

Arguments

text

(string) String of NN in form of NN1(state=C,min_init=1,max_init=5,act=ReLU)

Value

Activation function to be used for a NN

Author(s)

Dominic Bräm


NN converter for Monolix

Description

This function converts a Monolix model file that includes pseudo-functions for NNs as described in Details into a model that can be used in Monolix. An example Monolix model can be opened with the function open_mlx_example(). In addition, it allows to generate a Monolix .mlxtran file with automatically initialized parameters and estimation settings.

Usage

nn_converter_mlx(
  mlx_path,
  pop_only = FALSE,
  theta_scale = 0.1,
  eta_scale = 0.1,
  pre_fixef = NULL,
  gen_mlx_file = FALSE,
  mlx_name = NULL,
  data_file = NULL,
  header_types = NULL,
  obs_types = NULL,
  mapping = NULL,
  seed = 1908
)

Arguments

mlx_path

(string) (Path/)Name of the unconverted Monolix model file

pop_only

(boolean) If the generated Monolix .mlxtran file should be a fit without (TRUE) or with (FALSE) inter-individual variability on NN parameters

theta_scale

(numeric) Scale in which typical NN parameter values are initialized, default is 0.1, i.e., weights are initialized between -0.3 and 0.3

eta_scale

(numeric) Initial standard deviation of random effects on NN parameters, default is 0.1

pre_fixef

(named vector) Specific initial values for typical parameters, can be optained with the pre_fixef_extractor_mlx function from a previous Monolix run

gen_mlx_file

(boolean) If a Monolix .mlxtran file with already initialized parameters and estimation settigs should be generated

mlx_name

(string) Optional, name of the generated Monolix file (mlx_name.mlxtran). If no name is given and gen_mlx_file=TRUE, name of the Monolix file will be unconverted_model_name_mlx_file_pop/ind.mlxtran, with pop or ind depending whether pop=TRUE or pop=FALSE,respectively.

data_file

(string) Required if gen_mlx_file=TRUE, (Path/)Name of the data file to be used

header_types

(vector) Required if gen_mlx_file=TRUE, Vector of strings describing column types of data. Possible header types: ignore, id, time, observation, amount, contcov, catcov, occ, evid, mdv, obsid, cens, limit, regressor, nominaltime, admid, rate, tinf, ss, ii, addl, date

obs_types

(list) List of types of observations, e.g., “continuous”; only required if non-continuous observations

mapping

(list) List of mapping between model outputs and observation IDs

seed

(numeric) Seed for random parameter initialization.

Details

An example of model file could look like following

DESCRIPTION:
A Monolix model for conversion
[LONGITUDINAL]
input = {V=2}
PK:
depot(target=C)
EQUATION:
ddt_C = NN1(state=C,min_init=1,max_init=300) +
                amtDose * NN2(state=t,min_init=0.5,max_init=50,time_nn=TRUE)
Cc = C/V
OUTPUT:
output = Cc

Note: Converted Monolix model file will be saved under unconverted_file_converted.txt

Value

Saving a converted Monolix model file under mlx_path_converted.txt and optionally a Monolix file (mlx_name.mlxtran) if gen_mlx_file=TRUE

Author(s)

Dominic Bräm

Examples

## Not run: 
nn_converter_mlx("mlx_model2.txt",
                 pop_only=TRUE,gen_mlx_file=TRUE,
                 data_file="TMDD_dataset.csv",
                 header_types=c("id","time","amount","observation"))

est_parms <- pre_fixef_extractor_mlx("mlx_model2_time_nn_mlx_file_pop.mlxtran")

nn_converter_mlx("mlx_model2.txt",
                 pop_only=FALSE,gen_mlx_file=TRUE,
                 data_file="TMDD_dataset.csv",
                 header_types=c("id","time","amount","observation"),
                 pre_fixef=est_parms)

## End(Not run)

NN converter for nlmixr

Description

This function converts a nlmixr model function that includes pseudo-functions for NNs as described in Details into a model function that can be used in the nlmixr function.

Usage

nn_converter_nlmixr(
  f_ode,
  pop_only = FALSE,
  theta_scale = 0.1,
  eta_scale = 0.1,
  pre_fixef = NULL,
  seed = 1908
)

Arguments

f_ode

(nlmixr model function) Model function of nlmixr type with NN functions

pop_only

(boolean) If the generated nlmixr model function should be a fit without (TRUE) or with (FALSE) inter-individual variability on NN parameters

theta_scale

(numeric) Scale in which typical NN parameter values are initialized, default is 0.1, i.e., weights are initialized between -0.3 and 0.3

eta_scale

(numeric) Initial standard deviation of random effects on NN parameters, default is 0.1

pre_fixef

(named vector) Specific initial values for typical parameters, can be obtained from a run nlmixr model (e.g., run_1) through run_1$fixef

seed

(numeric) Seed for random parameter initialization.

Details

Value

A converted nlmixr model function

Author(s)

Dominic Bräm

Examples

## Not run: 
f_ode_pop <- function(){
ini({
  lV <- 1
  prop.err <- 0.1
})
model({
  V <- lV
  d/dt(centr)  =  NN1(state=centr,min_init=0,max_init=300)
  cp = centr / V
  cp ~ prop(prop.err)
  })
}

f_new_pop <- nn_converter_nlmixr(f_ode_pop,pop_only = TRUE)

fit_pop <- nlmixr2(f_new_pop,data,est="bobyqa")

f_ode <- function(){
  ini({
    lV <- 1
    eta.V ~ 0.1
    prop.err <- 0.1
  })
  model({
    V <- lV * exp(eta.V)
    d/dt(centr)  =  NN1(state=centr,min_init=0,max_init=300)
    cp = centr / V
    cp ~ prop(prop.err)
  })
}

f_new <- nn_converter_nlmixr(f_ode,pop_only = FALSE, pre_fixef = fit_pop$fixef)

## End(Not run)

NN converter for NONMEM

Description

This function converts a NONMEM model file that includes pseudo-functions for NNs as described in Details into a model that can be used in NONMEM. An example NONMEM model can be opened with the function open_nm_example().

Usage

nn_converter_nm(
  ctl_path,
  pop_only = FALSE,
  theta_scale = 0.1,
  eta_scale = 0.001,
  pre_fixef = NULL,
  seed = 1908
)

Arguments

ctl_path

(string) (Path/)Name of the unconverted NONMEM model file

pop_only

(boolean) If the generated NONMEM model file should be a fit without (TRUE) or with (FALSE) inter-individual variability on NN parameters

theta_scale

(numeric) Scale in which typical NN parameter values are initialized, default is 0.1, i.e., weights are initialized between -0.3 and 0.3

eta_scale

(numeric) Initial standard deviation of random effects on NN parameters, default is 0.1

pre_fixef

(named vector) Specific initial values for typical parameters, can be optained with the nn_prefix_extractor_nm function from the results file of a previous NONMEM run

seed

(numeric) Seed for random parameter initialization.

Details

An example of model file could look like following

$SIZES LVR=80 LNP4=40000
$PROB RUN
$INPUT C ID TIME AMT DV DOSE EVID
$DATA data_example1_nm.csv IGNORE=C
$SUBROUTINES ADVAN13
$MODEL
COMP(Centr)
$PK
lV = THETA(1)
V = lV * EXP(ETA(1))
$DES
DADT(1) = NNc(state=A(1),min_init=0.5,max_init=5) +
               DOSE * NNt(state=T,min_init=1,max_init=5,time_nn=TRUE)
$ERROR
Cc = A(1)/V
Y=Cc*(1+EPS(1)) + EPS(2)
$THETA
2 ; [V]
$OMEGA
0.1 ; [V]
$SIGMA
0.1
0.1
$ESTIMATION METHOD=1 MAXEVAL=9999 INTER PRINT=5
$TABLE ID TIME DV IPRED=CIPRED AMT NOPRINT FILE=nm_example1.tab

Note: Converted NONMEM model file will be saved under unconverted_file_converted.ctl

Value

Saving a converted NONMEM model file under ctl_path_converted.ctl

Author(s)

Dominic Bräm

Examples

## Not run: 
nn_converter_nm("nm_example_model.ctl",pop_only = TRUE)

est_parms <- pre_fixef_extractor_nm("nm_example_model_converted.res")

nn_converter_nm("nm_example_model.ctl",pop_only = FALSE,pre_fixef=est_parms)

## End(Not run)

Internal: Error for incomplete NNs

Description

Raises error if one or more NNs are not complete, i.e., not all required arguments are given

Usage

nn_errors(nn_tests)

Arguments

nn_tests

(list of strings) List of missing arguments for each NN, “None” if no arguments are missing for a NN

Details

Currently required arguments are: NN-name NNX(), state (state=), minimal (min_init=) and maximal (max_init=) activation points

Value

Error: Missing argument; NNX: missing arguments

Author(s)

Dominic Bräm


Internal: Define NN ETAs in NONMEM

Description

Define random effects of NN parameters as ETAs used in the $PK section in NONMEM

Usage

nn_eta_def_nm(number, eta_start, n_hidden = 5, time_nn = FALSE)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

eta_start

(numeric) Number with which to start the ETA count of NN parameters

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

Details

Parameter definition in form of etaW = ETA(X) with X the next number of ETA
e.g., if
etaV = ETA(1)
etakel = ETA(2)
X is equal to 3

Value

Vector with all NN parameter ETA definitions for a NN

Author(s)

Dominic Bräm


Internal: Initialize random effects on NN parameters in nlmixr

Description

Define the standard deviation of random effects on NN parameters for the ini section of the nlmixr model

Usage

nn_eta_initializer_nlmixr(
  number,
  n_hidden = 5,
  eta_scale = 0.1,
  time_nn = FALSE
)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

eta_scale

(numeric) Initial standard deviation of random effects on NN parameters

time_nn

(boolean) Definition whether NN is time-dependent (TRUE) or not (FALSE)

Value

Vector of initial random effects on NN parameters for one specific NN

Author(s)

Dominic Bräm


Internal: Set initial ETA estimates in NONMEM

Description

Set the initial ETA estimates for the $OMEGA block in the NONMEM model file

Usage

nn_eta_initializer_nm(
  number,
  theta_inis,
  pop = FALSE,
  n_hidden = 5,
  eta_scale = 0.1,
  time_nn = FALSE
)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

theta_inis

(list of string) THETA initial values generated in nn_theta_initializer_nm

pop

(boolean) Whether population fit without inter-individual variability is performed (TRUE) or whether model is fitted with inter-individual variability (FALSE)

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

eta_scale

(numeric) Initial standard deviation of random effects, default value is 0.1

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

Details

ETAs are fixed to 0 if

Value

Vector of initial NN parameter ETA values for one specific NN

Author(s)

Dominic Bräm


Internal: Extract NN function from model

Description

Extract the entire NN functions from a model file

Usage

nn_extractor(text)

Arguments

text

(string) Line of model code as string

Value

NN function as string in form of "NN1(state=t,min_init=1,max_init=5)"

Author(s)

Dominic Bräm


Internal: Generate NN code for Monolix

Description

Generate the explicit code for a NN in Monolix

Usage

nn_generator_mlx(
  number,
  state,
  n_hidden = 5,
  act = "ReLU",
  time_nn = FALSE,
  beta = 20
)

Arguments

number

(string) Name of the NN

state

(string) State to be used as input of the NN

n_hidden

(numeric) Number of units in the hidden layer; currently not implemented for the NN function

act

(string) Activation function to be used in the hidden layer of the NN (currently ReLU and Softplus implemented), default is ReLU

time_nn

(boolean) If NN should be set up specifically as a time-dependent NN with strictly negative weights from input to hidden layer through w'=-w^2

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Structure of one unit in the hidden layer:
h1 = max(0,W1 * state + b1)
h2 = max(0,W2 * state + b2)
...
NN = h1 + h2 + ...

Value

Explicit NN code in Monolix as list of lines in Monolix model file

Author(s)

Dominic Bräm


Internal: Generate NN code for nlmixr

Description

Generate the explicit code for a NN in nlmixr

Usage

nn_generator_nlmixr(
  number,
  state,
  n_hidden = 5,
  act = "ReLU",
  time_nn = FALSE,
  beta = 20
)

Arguments

number

(string) Name of the NN

state

(string) State to be used as input of the NN

n_hidden

(numeric) Number of units in the hidden layer, default is 5

act

(string) Activation function to be used in the hidden layer of the NN (currently ReLU and Softplus implemented), default is ReLU

time_nn

(boolean) If NN should be set up specifically as a time-dependent NN with strictly negative weights from input to hidden layer through w'=-w^2

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Structure of one unit in the hidden layer:
h1 = W1 * state + b1
if(h1 < 0) {h1 <- 0}
h2 = W2 * state + b2
...
NN = h1 + h2 + ...

Value

Explicit NN code in nlmixr as list of lines in nlmixr model file

Author(s)

Dominic Bräm


Internal: Generate NN code for NONMEM

Description

Generate the explicit code for a NN in NONMEM

Usage

nn_generator_nm(
  number,
  state,
  n_hidden = 5,
  act = "ReLU",
  time_nn = FALSE,
  beta = 20
)

Arguments

number

(string) Name of the NN

state

(string) State to be used as input of the NN

n_hidden

(numeric) Number of units in the hidden layer; currently not implemented for the NN function

act

(string) Activation function to be used in the hidden layer of the NN (currently ReLU and Softplus implemented), default is ReLU

time_nn

(boolean) If NN should be set up specifically as a time-dependent NN with strictly negative weights from input to hidden layer through w'=-w^2

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Structure of one unit in the hidden layer:
h1 = 0
h1_thres = W1 * state + b1
IF (h1_thres.GT.h1) h1 = h1_thres
h2 = 0
...
NN = h1 + h2 + ...

Value

Explicit NN code in NONMEM as list of lines in NONMEM model file

Author(s)

Dominic Bräm


Internal: Extract maximal activation point of NN

Description

Extract the maximal activation point of a NN given as the max_init argument in the NN function

Usage

nn_maxini_extractor(text)

Arguments

text

(string) String of NN in form of NN1(state=C,min_init=1,max_init=5)

Value

Maximal activation point for a NN

Author(s)

Dominic Bräm


Internal: Extract minimal activation point of NN

Description

Extract the minimal activation point of a NN given as the min_init argument in the NN function

Usage

nn_minini_extractor(text)

Arguments

text

(string) String of NN in form of NN1(state=C,min_init=1,max_init=5)

Value

Maximal activation point for a NN

Author(s)

Dominic Bräm


Internal: Extracting number of units in hidden layer

Description

Extracts the number of units in the hidden layer of a NN given as the n_hidden argument in the NN function

Usage

nn_nhidden_extractor(text)

Arguments

text

(string) String of NN in form of NN1(state=C,min_init=1,max_init=5,n_hidden=6)

Details

Not yet in use

Value

Number of units in the hidden layer for a specific NN

Author(s)

Dominic Bräm


Internal: Extract name of a NN

Description

Extract the name of a NN given as the NNX argument

Usage

nn_number_extractor(text)

Arguments

text

(string) String of NN in form of NN1(state=C,min_init=1,max_init=5)

Details

Potentially be moved to argument in NN function in form of NN(name=1,state=C,min_init=1,max_init=5) at a later stage

Value

Name of the NN

Author(s)

Dominic Bräm


Internal: Definition of NN parameters in nlmixr

Description

Define NN parameters consisting of typical parameter and potentially random effects in the model section of a nlmixr model

Usage

nn_parm_setter_nlmixr(
  number,
  pop = FALSE,
  n_hidden = 5,
  eta_model = c("prop", "add"),
  time_nn = FALSE
)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

pop

(boolean) Whether population fit without inter-individual variability is performed (TRUE) or whether model is fitted with inter-individual variability (FALSE)

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

eta_model

(string)

  • “prop” is of form W = lW * EXP(etaW)

  • “add” is of form W = lW + etaW

Defaul value is “prop”

time_nn

(boolean) Definition whether NN is time-dependent (TRUE) or not (FALSE)

Details

eta_model is currently set to proportional as previous investigations showed better stability of fit with this setting

Value

List of parameter definition to be used in the model section of the nlmixr model

Author(s)

Dominic Bräm


Internal: Definition of NN parameters in NONMEM

Description

Define NN parameters consisting of typical parameter and potentially random effects in the $PK section

Usage

nn_parm_setter_nm(
  number,
  pop = FALSE,
  n_hidden = 5,
  eta_model = c("prop", "add"),
  time_nn = FALSE
)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

pop

(boolean) Whether population fit without inter-individual variability is performed (TRUE) or whether model is fitted with inter-individual variability (FALSE)

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

eta_model

(string)

  • “prop” is of form W = lW * EXP(etaW)

  • “add” is of form W = lW + etaW

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

Details

eta_model is currently set to proportional as previous investigations showed better stability of fit with this setting in NONMEM

Value

List of parameter definition to be used in the $PK section of the NONMEM model

Author(s)

Dominic Bräm


Internal: Reduces NN function in model file

Description

Converts NN functions of form NN1(state=C,min_init=1,max_init=5) to model usable form of NN1.

Usage

nn_reducer(text)

Arguments

text

(list of strings) Model file read by readLines, with each line of the model as element of the list

Value

Converted model with NN1(state=C,min_init=1,max_init=5) expressed as NN1

Author(s)

Dominic Bräm


Internal: Extract state of a NN

Description

Extract the state to be used for a NN given as the state argument in the NN function

Usage

nn_state_extractor(text)

Arguments

text

(string) String of NN in form of NN1(state=C,min_init=1,max_init=5)

Value

State to be used for a NN

Author(s)

Dominic Bräm


Internal: Test NNs for completeness

Description

Tests whether all required arguments are given to each NN

Usage

nn_tester(text)

Arguments

text

NN function from the un-converted model file, e.g., NN1(state=C,min_init=1,max_init=5)

Details

Currently required arguments are: NN-name NNX(), state (state=), minimal (min_init=) and maximal (max_init=) activation points

Value

Missing arguments of a NN, “None” if all arguments are given

Author(s)

Dominic Bräm


Internal: Define NN parameters names

Description

Get parameter names for one specific NN in the model, i.e., weight and bias names

Usage

nn_theta_def_mlx(number, n_hidden = 5, time_nn = FALSE)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

Value

Vector with all NN parameter names

Author(s)

Dominic Bräm


Internal: Define NN THETAs in NONMEM

Description

Define NN THETAS used in the $PK section in NONMEM

Usage

nn_theta_def_nm(number, theta_start, n_hidden = 5, time_nn = FALSE)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

theta_start

(numeric) Number with which to start the THETA count of NN parameters

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

time_nn

(boolean) Whether the neural network to analyze is a time-dependent neural network or not. Default values is FALSE.

Details

Parameter definition in form of lW = THETA(X) with X the next number of THETA
e.g., if
lV = THETA(1)
lkel = THETA(2)
X is equal to 3

Value

Vector with all NN parameter THETA definitions for a NN

Author(s)

Dominic Bräm


Internal: Calculate initial NN parameter values

Description

Calculate the initial NN parameter values, such that activation points are within the range between min_init and max_init defined in the un-converter Monolix model file

Usage

nn_theta_initializer_mlx(
  number,
  xmini,
  xmaxi,
  n_hidden = 5,
  theta_scale = 0.1,
  pre_fixef = NULL,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20
)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

xmini

(numeric) minimal activation point

xmaxi

(numeric) maximal activation point

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

theta_scale

(numeric) Scale for input-hidden-weights initialization

pre_fixef

(named vector) Vector of pre-defined initial values

time_nn

(boolean) Definition whether NN is time-dependent (TRUE) or not (FALSE)

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Value

Vector of initial NN parameter values for one specific NN

Author(s)

Dominic Bräm


Internal: Initialize typical NN parameter in nlmixr

Description

Calculate the initial typical NN parameter values, such that activation points are within the range between min_init and max_init defined in the un-converter NONMEM model file, and define the the typical NN parameters for the ini section of the nlmixr model

Usage

nn_theta_initializer_nlmixr(
  number,
  xmini,
  xmaxi,
  n_hidden = 5,
  theta_scale = 0.1,
  pre_fixef = NULL,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20
)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

xmini

(numeric) minimal activation point

xmaxi

(numeric) maximal activation point

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

theta_scale

(numeric) Scale for input-hidden-weights initialization

pre_fixef

(named vector) Vector of pre-defined initial values

time_nn

(boolean) Definition whether NN is time-dependent (TRUE) or not (FALSE)

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Value

Vector of initial typical NN parameters for one specific NN

Author(s)

Dominic Bräm


Internal: Calculate initial NN parameter values in NONMEM

Description

Calculate the initial NN parameter values, such that activation points are within the range between min_init and max_init defined in the un-converter NONMEM model file

Usage

nn_theta_initializer_nm(
  number,
  xmini,
  xmaxi,
  n_hidden = 5,
  theta_scale = 0.1,
  pre_fixef = NULL,
  time_nn = FALSE,
  act = "ReLU",
  beta = 20
)

Arguments

number

(string) Name of the NN, e.g., “1” for NN1(...)

xmini

(numeric) minimal activation point

xmaxi

(numeric) maximal activation point

n_hidden

(numeric) Number of neurons in the hidden layer, default value is 5

theta_scale

(numeric) Scale for input-hidden-weights initialization

pre_fixef

(named vector) Vector of pre-defined initial values

time_nn

(boolean) Definition whether NN is time-dependent (TRUE) or not (FALSE)

act

(string) Activation function used in the NN. Currently "ReLU" and "Softplus" available.

beta

(numeric) Beta value for the Softplus activation function, only applicable if act="Softplus"; Default to 20.

Details

Value

Vector of initial NN parameter THETA values for one specific NN

Author(s)

Dominic Bräm


Internal: Extracting time-NN argument

Description

Extracts, whether a NN should be treated as time-dependent NN

Usage

nn_time_nn_extractor(text)

Arguments

text

(list of strings) List of strings of NN in form of
NN1(state=t,min_init=1,max_init=5,time_nn=TRUE)

Details

Time-dependent NNs have different model structures, i.e., weights from input to hidden layer are set to negative through w'=-w^2

Value

List of boolean expression whether NN should be treated as time-NN (TRUE) or not (FALSE)

Author(s)

Dominic Bräm


Open Monolix example model

Description

Opens unconverted Monolix example model with NN functions

Usage

open_mlx_example(model_nr = 1)

Arguments

model_nr

(number) What example number should be read (1-4 available).

Details

Example numbers 1-4 currently available.

Value

Returns example model text.

Author(s)

Dominic Bräm


Open NONMEM example model

Description

Opens unconverted NONMEM example model with NN functions

Usage

open_nm_example(model_nr = 1)

Arguments

model_nr

(number) What example number should be read (1-4 available).

Details

Example numbers 1-4 currently available.

Value

Returns example model text.

Author(s)

Dominic Bräm


Monolix estimations extractor

Description

When the Monolix model has been run, e.g., with only population estimation, this function allows to extract the estimated parameters from the Monolix run folder. This function is meant, e.g., to get initial values for a Monolix run with inter-individual variability and to be then used as pre_fixef argument in the nn_converter_mlx function

Usage

pre_fixef_extractor_mlx(model_name)

Arguments

model_name

(string) Name of the Monolix run. Must include “.mlxtran”

Value

Named vector of Monolix parameter estimations

Author(s)

Dominic Bräm

Examples

mlx_path <- system.file("extdata","mlx_example1_ind.mlxtran",package="pmxNODE")
est_parms <- pre_fixef_extractor_mlx(mlx_path)

THETA extraction from results file

Description

Function to extract THETA estimates from a results file of an already run NONMEM file.

Usage

pre_fixef_extractor_nm(res_path)

Arguments

res_path

(string) (Path/)Name of the results file of a NONMEM run, must include file extension, e.g., “.res”

Details

Can be used, e.g., to initialize THETAs of a run with inter-individual variability with estimated THETAs of a previous population run without inter-individual variability. Parameters, for which final gradient is equal to 0 are fixed to 0, because a gradient of 0 indicates that corresponding neuron was inactivated during parameter estimation.

Value

Named vector with parameter estimates from the previous run

Author(s)

Dominic Bräm

Examples

res_path <- system.file("extdata","nm_example1_model_converted_ind.res",package="pmxNODE")
pre_fixef <- pre_fixef_extractor_nm(res_path)

Generate Right-hand side data (Monolix)

Description

This functions allows to generate right-hand side data, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

rhs_calc_mlx(
  rhs,
  inputs,
  est_parms = NULL,
  mlx_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side, e.g., "NNc + WT * NNct"

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs, e.g., NNc, WT, and NNct).

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the inputs and the combined right-hand side data.

Author(s)

Dominic Bräm


Generate Right-hand side data (nlmixr2)

Description

This functions allows to generate right-hand side data, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

rhs_calc_nlmixr(
  rhs,
  inputs,
  est_parms = NULL,
  fit_obj = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side, e.g., "NNc + WT * NNct"

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs, e.g., NNc, WT, and NNct).

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...). For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or fit_obj must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the inputs and the combined right-hand side data.

Author(s)

Dominic Bräm


Generate Right-hand side data (NONMEM)

Description

This functions allows to generate right-hand side data, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

rhs_calc_nm(
  rhs,
  inputs,
  est_parms = NULL,
  nm_res_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side, e.g., "NNc + DOSE * NNct".

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs, e.g., for NNc, DOSE, and NNct).

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or nm_res_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the inputs and the combined right-hand side data.

Author(s)

Dominic Bräm


Generate Right-hand side data plot (Monolix)

Description

This functions allows to generate right-hand side plot, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

rhs_plot_mlx(
  rhs,
  x_var,
  inputs,
  est_parms = NULL,
  mlx_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

x_var

(string) Name of the variable in inputs against which the right-hand data should be plotted.

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

mlx_file

(string; semi-optional) (path)/name of the Monolix run. Must include ".mlxtran" and estimation bust have been run previously. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

ggplot of right-hand side data.

Author(s)

Dominic Bräm

Examples

mlx_path <- system.file("extdata","mlx_example1_ind.mlxtran",package="pmxNODE")
est_parms <- pre_fixef_extractor_mlx(mlx_path)
rhs_plot <- rhs_plot_mlx(rhs="NNc + WT * NNct",
                         x_var = "NNc",
                         inputs = data.frame(NNc = 1:100,
                                             NNct = seq(0,10,length.out=100),
                                             WT = rep(50,100)),
                         est_parms=est_parms,
                         time_nn = c(FALSE, TRUE))

Generate Right-hand side data plot (nlmixr2)

Description

This functions allows to generate right-hand side plot, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

rhs_plot_nlmixr(
  rhs,
  x_var,
  inputs,
  est_parms = NULL,
  fit_obj = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

x_var

(string) Name of the variable in inputs against which the right-hand data should be plotted.

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

fit_obj

(nlmixr fit object; semi-optional) The fit-object from nlmixr2(...). For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or mlx_file must be given. If both arguments are given, est_parms is prioritized.

Value

Dataframe with columns for the inputs and the combined right-hand side data.

Author(s)

Dominic Bräm

Examples

## Not run: 
pop_fit <- nlmixr2(node_model,data=data,est="bobyqa")
rhs_plot <- rhs_plot_nlmixr(rhs="NNc + WT * NNct",
                         x_var = "NNc",
                         inputs = data.frame(NNc = 1:100,
                                             NNct = seq(0,10,length.out=100),
                                             WT = rep(50,100)),
                         est_parms=pop_fit$fixef)

## End(Not run)

Generate Right-hand side data plot (NONMEM)

Description

This functions allows to generate right-hand side plot, i.e., combined derivative data of multiple NNs and base-R operations.

Usage

rhs_plot_nm(
  rhs,
  x_var,
  inputs,
  est_parms = NULL,
  nm_res_file = NULL,
  time_nn = NULL,
  act = NULL,
  beta = 20
)

Arguments

rhs

(string) String of right-hand side

x_var

(string) Name of the variable in inputs against which the right-hand data should be plotted.

inputs

(dataframe) Dataframe of inputs, with corresponding columns (including matching column names for each variable in rhs.

est_parms

(named vector; semi-optional) Named vector of estimated parameters from the NN extracted through the pre_fixef_extractor_mlx function. For optionality, see Details.

nm_res_file

(string; semi-optional) (path)/name of the results file of a NONMEM run, must include file extension, e.g., “.res”. For optionality, see Details.

time_nn

(boolean vector) Vector for each NN in rhs defining whether the neural network is a time-dependent neural network or not. Default value for all NN is FALSE.

act

(character vector) Vector for each NN in rhs defining the activation function used in the NN. Default value for all NN is "ReLU".

beta

(numeric) Beta value for the Softplus activation function, only applicable if any act is softplus; Default to 20.

Details

Either est_parms or nm_res_file must be given. If both arguments are given, est_parms is prioritized.

Value

ggplot of right-hand side data.

Author(s)

Dominic Bräm

Examples

res_path <- system.file("extdata","nm_example1_model_converted_ind.res",package="pmxNODE")
est_parms <- pre_fixef_extractor_nm(res_path)
rhs_plot <- rhs_plot_nm(rhs="NNc + DOSE * NNt",
                         x_var = "NNc",
                         inputs = data.frame(NNc = 1:100,
                                             NNt = seq(0,10,length.out=100),
                                             DOSE = rep(50,100)),
                         est_parms=est_parms,
                         time_nn = c(FALSE, TRUE))

Run Monolix from R

Description

Runs Monolix from R

Usage

run_mlx(mlx_file)

Arguments

mlx_file

(string) Absolute or relative Path/Name of Monolix file to run. Must be in R-style, i.e., path must be with slashes. File must be given with file extension, e.g., monolix_file.mlxtran

Details

All paths must be given in R-style, i.e., slashes instead of backslashes. Paths can be absolute or relative.

Value

No return value, running the specified model in Monolix via lixoftConnectors.

Author(s)

Dominic Bräm

Examples

## Not run: 
run_mlx("mlx_file.mlxtran")

## End(Not run)

Run NONMEM from R

Description

Runs NONMEM from R

Usage

run_nm(
  ctl_file,
  nm_path,
  parralel_command = NULL,
  create_dir = TRUE,
  data_file = NULL
)

Arguments

ctl_file

(string) Absolute or relative Path/Name of NONMEM file to run. Must be in R-style, i.e., path must be with slashes. File must be given with file extension, e.g., nonmem_file.ctl

nm_path

(string) Absolute or relative Path/Name of NONMEM to be executed,
e.g., "C:/nm75g64/run/nmfe75".

parralel_command

(string) (Optional) Command for parralel NONMEM execution,
e.g., "-parafile=C:/nm75g64/run/mpiwini8.pnm [nodes]=30"

create_dir

(boolean) If NONMEM file should be run and saved in new directory. If TRUE, new directory of type path_to_ctl_file/ctl_name will be created. Default is TRUE.

data_file

(string) Absolute or relative Path/Name of data file to be used in the NONMEM run. Required if create_dir=TRUE as data file will be copied to new directory.

Details

All paths must be given in R-style, i.e., slashes instead of backslashes. Paths can be absolute or relative.

Value

No return value, running the specified model in NONMEM via command line.

Author(s)

Dominic Bräm

Examples

## Not run: 
run_nm("./test/nm_test.ctl","c:/nm75g64/run/nmfe75",
       parralel_command = "-parafile=C:/nm75g64/run/mpiwini8.pnm [nodes]=30",
       data_file="~/Test/test/test_data.csv")

## End(Not run)

Initialize software (Suspended)

Description

Initialize the pharmacometric software you want to use (Monolix, nlmixr or NONMEM). Must be used before nn_converter functions can be used for Monolix and nlmixr.

Usage

software_initializer(
  software = c("Monolix", "nlmixr", "NONMEM"),
  mlx_path = NULL
)

Arguments

software

(string) The software to be used for NN convertion; "Monolix","nlmixr", or "NONMEM"

mlx_path

(string) Required if software="Monolix"; path to Monolix location (under Windows usually C:/ProgramData/Lixoft/MonolixSuiteXXXX with XXXX as the version)

Details

For Monolix, the lixoftConnectors package is loaded. For loading, the path to the Monolix location (under Windows usually C:/ProgramData/Lixoft/MonolixSuiteXXXX with XXXX as the version) is required. Note: nlmixr2 and lixoftConnectors share function getData. If both, nlmixr and Monolix, get initialized, getData will be used from the package initialized second

Value

Initialization of software

Author(s)

Dominic Bräm

Examples

## Not run: 
software_initializer(software="NONMEM")
software_initializer(software="nlmixr")
software_initializer(software="Monolix",mlx_path="C:/ProgramData/Lixoft/MonolixSuite2021R2")

## End(Not run)

Internal: Correct NONMEM states

Description

For NNs to be handled correctly, the state argument may not include brackets. state_correcter_nm translates argument state=A(1) to state=A1 and A1=A(1)

Usage

state_correcter_nm(text)

Arguments

text

(string) NN of form “NN1(state=A(1),min_init=1,max_init=5)”

Value

Author(s)

Dominic Bräm