foceiLikLoad: Load a general FOCE-family likelihood into memory

View source: R/foceiLik.R

foceiLikLoadR Documentation

Load a general FOCE-family likelihood into memory

Description

Compiles the inner (FOCEi sensitivity) model from an rxode2 UI model, preprocesses the data, and sets up the FOCEi inner problem in memory so that individual log-likelihoods can be evaluated repeatedly (in parallel per subject) at supplied etas without recompiling – the setup used internally by 'est="emvi"'/'est="fbvi"', 'est="vae"' and the f-SAEM fast kernel, exposed here for MCMC/SAMBA-style callers (issue #414).

Usage

foceiLikLoad(
  object,
  data,
  likelihood = c("focei", "focep", "foce"),
  rxControl = rxode2::rxControl(),
  ...
)

Arguments

object

An 'rxode2'/'nlmixr2' UI model (a model function or its compiled UI).

data

The estimation data (a data frame with the usual nlmixr2 columns).

likelihood

The individual likelihood type: '"focei"' (FOCE with interaction), '"focep"' (FOCE+, interaction off with the residual variance at the conditional eta) or '"foce"' (NONMEM-style FOCE, residual variance frozen at eta=0).

rxControl

An [rxode2::rxControl()] object for the ODE solving options.

...

Additional solving/model options passed to '.foceiLikControl' (e.g. 'optExpression', 'addProp', 'eventSens').

Details

Only one likelihood system may be loaded at a time; loading errors if one is already loaded. Use [foceiLikRun()] to evaluate and [foceiLikUnload()] to free.

Value

Invisibly, a handle list with the loaded system's dimensions: ‘initPar' (the estimation-scale parameter vector at the model’s initial estimates, a ready 'theta' for [foceiLikRun()]), 'npars', 'ntheta', 'neta', 'nid', 'thetaNames', 'etaNames', 'idLvl' and 'likelihood'.

Author(s)

Matthew L. Fidler

See Also

[foceiLikRun()], [foceiLikUnload()]

Examples




one.cmt <- function() {
  ini({
    tka <- 0.45
    tcl <- 1
    tv <- 3.45
    add.sd <- 0.7
    eta.ka ~ 0.6
    eta.cl ~ 0.3
    eta.v ~ 0.1
  })
  model({
    ka <- exp(tka + eta.ka)
    cl <- exp(tcl + eta.cl)
    v <- exp(tv + eta.v)
    linCmt() ~ add(add.sd)
  })
}

# Set the likelihood up in memory once; only one may be loaded at a time
h <- foceiLikLoad(one.cmt, theo_sd, "focei")

# The handle carries the dimensions and a ready starting parameter vector
h$nid
h$neta
h$initPar

# Individual joint log-likelihood at eta = 0, one value per subject
eta <- matrix(0, h$nid, h$neta)
foceiLikRun(h$initPar, eta)

# Free it when done (loading again before this errors)
foceiLikUnload()


nlmixr2est documentation built on Aug. 5, 2026, 1:11 a.m.