| Title: | Log-Likelihood Functions for 'rxode2' |
|---|---|
| Description: | Provides the log-likelihoods with gradients from 'stan' (Carpenter et al (2015), <doi:10.48550/arXiv.1509.07164>) needed for generalized log-likelihood estimation in 'nlmixr2' (Fidler et al (2019) <doi:10.1002/psp4.12445>). This is split of to reduce computational burden of recompiling 'rxode2' (Wang, Hallow and James (2016) <doi:10.1002/psp4.12052>) which runs the 'nlmixr2' models during estimation. |
| Authors: | Matthew L. Fidler [aut, cre] (ORCID: <https://orcid.org/0000-0001-8538-6691>) |
| Maintainer: | Matthew L. Fidler <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 2.0.18 |
| Built: | 2026-10-15 11:18:18 UTC |
| Source: | https://github.com/nlmixr2/rxode2ll |
Hands a consumer package the addresses of every rxLlik* function and its
exact derivatives, so it can call them from C/C++ without an ABI dependency
on this package.
.rxode2llPtr().rxode2llPtr()
R_GetCCallable() is not sufficient for that. It drops the link-time
dependency, but the consumer still compiles in a typedef'd signature and
caches a raw address: updating rxode2ll then requires the consumer to be
rebuilt, and reloading rxode2ll leaves the cached pointers dangling. This is
the same external-pointer handshake rxode2, nlmixr2est, RcppTrust and n1qn1
already use, where the consumer re-reads the list in its own .onLoad() and
therefore picks up an updated rxode2ll instead of baking one in.
The returned list is APPEND-ONLY and its order is fixed; see
inst/include/rxode2llPtrs.h, which is the matching consumer header.
list of external pointers, in the order documented in
rxode2llPtrs.h
length(.rxode2llPtr())length(.rxode2llPtr())
Calculate the log likelihood of the binomial function (and its derivatives)
llikBeta(x, shape1, shape2, full = FALSE)llikBeta(x, shape1, shape2, full = FALSE)
x |
Observation |
shape1, shape2
|
non-negative parameters of the Beta distribution. |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with
dShape1 and dShape2 that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
x <- seq(1e-4, 1 - 1e-4, length.out = 21) llikBeta(x, 0.5, 0.5) llikBeta(x, 1, 3, TRUE)x <- seq(1e-4, 1 - 1e-4, length.out = 21) llikBeta(x, 0.5, 0.5) llikBeta(x, 1, 3, TRUE)
log likelihood of the BetaProportion distribution and its derivatives (from stan)
llikBetaProportion(x, mu, kappa, full = FALSE)llikBetaProportion(x, mu, kappa, full = FALSE)
x |
Observation |
mu |
distribution parameter |
kappa |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
Calculate the log likelihood of the binomial function (and its derivatives)
llikBinom(x, size, prob, full = FALSE)llikBinom(x, size, prob, full = FALSE)
x |
Number of successes |
size |
Size of trial |
prob |
probability of success |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the pdf value of with
dProb that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
llikBinom(46:54, 100, 0.5) llikBinom(46:54, 100, 0.5, TRUE)llikBinom(46:54, 100, 0.5) llikBinom(46:54, 100, 0.5, TRUE)
log likelihood of Cauchy distribution and it's derivatives (from stan)
llikCauchy(x, location = 0, scale = 1, full = FALSE)llikCauchy(x, location = 0, scale = 1, full = FALSE)
x |
Observation |
location, scale
|
location and scale parameters. |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with
dLocation and dScale that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
x <- seq(-3, 3, length.out = 21) llikCauchy(x, 0, 1) llikCauchy(x, 3, 1, full=TRUE)x <- seq(-3, 3, length.out = 21) llikCauchy(x, 0, 1) llikCauchy(x, 3, 1, full=TRUE)
log likelihood and derivatives for chi-squared distribution
llikChisq(x, df, full = FALSE)llikChisq(x, df, full = FALSE)
x |
variable that is distributed by chi-squared distribution |
df |
degrees of freedom (non-negative, but can be non-integer). |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dDf
that has the derivatives with respect to the df parameter
the observation time-point
Matthew L. Fidler
llikChisq(1, df = 1:3, full=TRUE) llikChisq(1, df = 6:9)llikChisq(1, df = 1:3, full=TRUE) llikChisq(1, df = 6:9)
log likelihood of the DblExp distribution and its derivatives (from stan)
llikDblExp(x, mu, sigma, full = FALSE)llikDblExp(x, mu, sigma, full = FALSE)
x |
Observation |
mu |
distribution parameter |
sigma |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood and derivatives for exponential distribution
llikExp(x, rate, full = FALSE)llikExp(x, rate, full = FALSE)
x |
variable that is distributed by exponential distribution |
rate |
vector of rates. |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dRate
that has the derivatives with respect to the rate parameter
the observation time-point
Matthew L. Fidler
llikExp(1, 1:3) llikExp(1, 1:3, full=TRUE)llikExp(1, 1:3) llikExp(1, 1:3, full=TRUE)
log likelihood and derivatives for F distribution
llikF(x, df1, df2, full = FALSE)llikF(x, df1, df2, full = FALSE)
x |
variable that is distributed by f distribution |
df1, df2
|
degrees of freedom. |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dDf1 and dDf2
that has the derivatives with respect to the df1/df2 parameters at
the observation time-point
Matthew L. Fidler
x <- seq(0.001, 5, length.out = 100) llikF(x^2, 1, 5)x <- seq(0.001, 5, length.out = 100) llikF(x^2, 1, 5)
log likelihood of the Frechet distribution and its derivatives (from stan)
llikFrechet(x, alpha, sigma, full = FALSE)llikFrechet(x, alpha, sigma, full = FALSE)
x |
Observation |
alpha |
distribution parameter |
sigma |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood and derivatives for Gamma distribution
llikGamma(x, shape, rate, full = FALSE)llikGamma(x, shape, rate, full = FALSE)
x |
variable that is distributed by gamma distribution |
shape |
this is the distribution's shape parameter. Must be positive. |
rate |
this is the distribution's rate parameters. Must be positive. |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dProb
that has the derivatives with respect to the prob parameters at
the observation time-point
Matthew L. Fidler
llikGamma(1, 1, 10)llikGamma(1, 1, 10)
log likelihood and derivatives for Geom distribution
llikGeom(x, prob, full = FALSE)llikGeom(x, prob, full = FALSE)
x |
variable distributed by a geom distribution |
prob |
probability of success in each trial. |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dProb
that has the derivatives with respect to the prob parameters at
the observation time-point
Matthew L. Fidler
llikGeom(1:10, 0.2)llikGeom(1:10, 0.2)
log likelihood of the Gumbel distribution and its derivatives (from stan)
llikGumbel(x, mu, beta, full = FALSE)llikGumbel(x, mu, beta, full = FALSE)
x |
Observation |
mu |
distribution parameter |
beta |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood of the InvChisq distribution and its derivatives (from stan)
llikInvChisq(x, nu, full = FALSE)llikInvChisq(x, nu, full = FALSE)
x |
Observation |
nu |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood of the InvGamma distribution and its derivatives (from stan)
llikInvGamma(x, alpha, beta, full = FALSE)llikInvGamma(x, alpha, beta, full = FALSE)
x |
Observation |
alpha |
distribution parameter |
beta |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood of the Lnorm distribution and its derivatives (from stan)
llikLnorm(x, meanlog, sdlog, full = FALSE)llikLnorm(x, meanlog, sdlog, full = FALSE)
x |
Observation |
meanlog |
distribution parameter |
sdlog |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood of the Logis distribution and its derivatives (from stan)
llikLogis(x, location, scale, full = FALSE)llikLogis(x, location, scale, full = FALSE)
x |
Observation |
location |
distribution parameter |
scale |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
Calculate the log likelihood of the negative binomial function (and its derivatives)
llikNbinom(x, size, prob, full = FALSE)llikNbinom(x, size, prob, full = FALSE)
x |
Number of successes |
size |
Dispersion parameter; may be non-integer |
prob |
probability of success |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the pdf value of with
dProb that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
llikNbinom(46:54, 100, 0.5) llikNbinom(46:54, 100, 0.5, TRUE)llikNbinom(46:54, 100, 0.5) llikNbinom(46:54, 100, 0.5, TRUE)
Calculate the log likelihood of the negative binomial function (and its derivatives)
llikNbinomMu(x, size, mu, full = FALSE)llikNbinomMu(x, size, mu, full = FALSE)
x |
Number of successes |
size |
Dispersion parameter; may be non-integer |
mu |
mu parameter for negative binomial |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the pdf value of with
dProb that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
llikNbinomMu(46:54, 100, 40) llikNbinomMu(46:54, 100, 40, TRUE)llikNbinomMu(46:54, 100, 40) llikNbinomMu(46:54, 100, 40, TRUE)
Log likelihood for normal distribution
llikNorm(x, mean = 0, sd = 1, full = FALSE)llikNorm(x, mean = 0, sd = 1, full = FALSE)
x |
Observation |
mean |
Mean for the likelihood |
sd |
Standard deviation for the likelihood |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the pdf value of with dMean and
dSd that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
llikNorm(0) llikNorm(seq(-2,2,length.out=10), full=TRUE)llikNorm(0) llikNorm(seq(-2,2,length.out=10), full=TRUE)
log likelihood of the Pareto distribution and its derivatives (from stan)
llikPareto(x, yMin, alpha, full = FALSE)llikPareto(x, yMin, alpha, full = FALSE)
x |
Observation |
yMin |
distribution parameter |
alpha |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood of the ParetoType2 distribution and its derivatives (from stan)
llikParetoType2(x, mu, lambda, alpha, full = FALSE)llikParetoType2(x, mu, lambda, alpha, full = FALSE)
x |
Observation |
mu |
distribution parameter |
lambda |
distribution parameter |
alpha |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log-likelihood for the Poisson distribution
llikPois(x, lambda, full = FALSE)llikPois(x, lambda, full = FALSE)
x |
non negative integers |
lambda |
non-negative means |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the pdf value of with
dLambda that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
log likelihood of the Rayleigh distribution and its derivatives (from stan)
llikRayleigh(x, sigma, full = FALSE)llikRayleigh(x, sigma, full = FALSE)
x |
Observation |
sigma |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
log likelihood of the ScaledInvChisq distribution and its derivatives (from stan)
llikScaledInvChisq(x, nu, sigma, full = FALSE)llikScaledInvChisq(x, nu, sigma, full = FALSE)
x |
Observation |
nu |
distribution parameter |
sigma |
distribution parameter |
full |
return the input parameters alongside the result |
data frame with fx and the derivative of each parameter
Log likelihood of T and it's derivatives (from stan)
llikT(x, df, mean = 0, sd = 1, full = FALSE)llikT(x, df, mean = 0, sd = 1, full = FALSE)
x |
Observation |
df |
degrees of freedom ( |
mean |
Mean for the likelihood |
sd |
Standard deviation for the likelihood |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dDf
dMean and dSd that has the derivatives with respect to the parameters at
the observation time-point
Matthew L. Fidler
x <- seq(-3, 3, length.out = 21) llikT(x, 7, 0, 1) llikT(x, 15, 0, 1, full=TRUE)x <- seq(-3, 3, length.out = 21) llikT(x, 7, 0, 1) llikT(x, 15, 0, 1, full=TRUE)
log likelihood and derivatives for Unif distribution
llikUnif(x, alpha, beta, full = FALSE)llikUnif(x, alpha, beta, full = FALSE)
x |
variable distributed by a uniform distribution |
alpha |
is the lower limit of the uniform distribution |
beta |
is the upper limit of the distribution |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dProb
that has the derivatives with respect to the prob parameters at
the observation time-point
Matthew L. Fidler
llikUnif(1, -2, 2)llikUnif(1, -2, 2)
log likelihood and derivatives for Weibull distribution
llikWeibull(x, shape, scale, full = FALSE)llikWeibull(x, shape, scale, full = FALSE)
x |
variable distributed by a Weibull distribution |
shape, scale
|
shape and scale parameters, the latter defaulting to 1. |
full |
Add the data frame showing x, mean, sd as well as the fx and derivatives |
data frame with fx for the log pdf value of with dProb
that has the derivatives with respect to the prob parameters at
the observation time-point
Matthew L. Fidler
llikWeibull(1, 1, 10)llikWeibull(1, 1, 10)