Learn R Programming

invivoPKfit (version 2.0.1)

logLik.pk: Log-likelihood

Description

Extract log-likelihood(s) from a fitted `pk` object

Usage

# S3 method for pk
logLik(
  object,
  newdata = NULL,
  model = NULL,
  method = NULL,
  negative = FALSE,
  force_finite = FALSE,
  exclude = TRUE,
  drop_obs = TRUE,
  ...
)

Value

A data.frame with coefficients and log-likelihood values calculated using `newdata`. There is one row for each model in `obj`'s [stat_model()] element and each [optimx::optimx()] method (specified in [settings_optimx()]).

Arguments

object

A `pk` object

newdata

Optional: A `data.frame` with new data for which to compute log-likelihood. If NULL (the default), then log-likelihoods will be computed for the data in `obj$data`. `newdata` is required to contain at least the following variables: `Time`, `Time.Units`, `Dose`, `Route`,`Media`, `Conc`, `Detect`, `Conc_SD`, `N_Subjects`. `Time` will be transformed according to the transformation in `obj$scales$time` before making predictions. `Conc` will be transformed according to the transformation in `obj$scales$conc`.

model

Optional: Specify one or more of the fitted models for which to calculate log-likelihood. If NULL (the default), log-likelihoods will be returned for all of the models in `obj$stat_model`.

method

Optional: Specify one or more of the [optimx::optimx()] methods for which to calculate log-likelihoods. If NULL (the default), log-likelihoods will be returned for all of the models in `obj$optimx_settings$method`.

negative

Logical: Whether to return the *negative* log-likelihood (i.e., the log-likelihood multiplied by negative 1). Default `FALSE`.

force_finite

Logical: Whether to force return of a finite value (e.g. as required by method `L-BFGS-B` in [optimx::optimx()]). Default FALSE. If TRUE, then if the log-likelihood works out to be non-finite, then it will be replaced with `.Machine$double.xmax`.

exclude

Logical: `TRUE` to compute the log-likelihood excluding any observations in the data marked for exclusion (if there is a variable `exclude` in the data, an observation is marked for exclusion when `exclude log-likelihood, regardless of exclusion status. Default `TRUE`.

drop_obs

Logical: `TRUE` to drop the observations column after calculating log-likelihood.

...

Additional arguments. Not in use currently.

Author

Caroline Ring, Gilberto Padilla Mercado

Details

For details on how the log-likelihood is calculated, see [log_likelihood()].

# New levels in `newdata`

The log-likelihood requires an error variance for each observation. Depending on the error model used for the model fit, each observation may have a different corresponding error variance, based on its unique combinations of levels of factor variables as specified in [stat_error_model()] when setting up the [pk()] object. (The error model specified in the `pk` object can be viewed using [get_error_group()]).

If you are supplying new data in `newdata`, then the unique combinations of the factor levels for the new observations will be used to find the matching error hyperparameter. If the new data contains new combinations of factor levels not found in the data used to fit the model, then the following procedure will be used to calculate the log-likelihood for the observations with new levels:

If there are \(i = 1, 2, ... G\) groups with unique combinations of the factor levels in the original data, then there are corresponding error standard deviations \(\sigma_i = \sigma_1, \sigma_2, ..., \sigma_G\).

Each observation with a new combination of factor levels will have \(G\) differerent log-likelihoods computed, as though it were part of each of the \(G\) existing groups. Then, the average of these \(G\) log-likelihoods will be taken and assigned to the observation. In effect, each observation with a new level is treated as though it is equally likely to belong to any of the existing groups.

# Scaling and transformation of concentration variables in `newdata`

This function differs from some of the other methods for a fitted [pk()] object that accept `newdata`, in that there is no `use_scale_conc` argument for [logLik.pk()]. You cannot specify a different scaling/transformation for concentration variables -- you have to use the same scaling/transformation that was used to fit the model. This is because the log-likelihood depends on the fitted values of the error variance hyperparameters, and those are valid only for the transformation of the concentration data that was used to fit the model.

See Also

Other fit evaluation metrics: AAFE.pk(), AFE.pk(), AIC.pk(), BIC.pk(), rmse.pk(), rsq.pk()

Other log likelihood functions: AIC.pk(), BIC.pk()

Other methods for fitted pk objects: AAFE.pk(), AFE.pk(), AIC.pk(), BIC.pk(), coef.pk(), coef_sd.pk(), eval_tkstats.pk(), get_fit.pk(), get_hessian.pk(), get_tkstats.pk(), predict.pk(), residuals.pk(), rmse.pk(), rsq.pk()