Skip to contents

profile_cross_rho() formalises a fixed-kernel sensitivity workflow for cross-lineage kernels. It rebuilds K_star with make_cross_kernel() over a user-supplied rho grid, calls a caller-supplied refit(K, rho, ...) function for each grid value, and returns a tidy likelihood table.

This is a fixed-kernel profile workflow for comparing defended rho values. Note its limits: rho is not a TMB parameter, this helper does not estimate rho, and it does not produce confidence intervals or null calibration.

Usage

profile_cross_rho(
  A_H,
  A_P,
  W,
  rho,
  refit,
  metrics = NULL,
  eps = 1e-08,
  keep_fits = FALSE,
  ...
)

Arguments

A_H, A_P, W

Inputs passed to make_cross_kernel().

rho

Numeric vector of fixed rho values to evaluate.

refit

Function called as refit(K = K_rho, rho = rho_i, ...). It should return a fitted object with a logLik() method.

metrics

Optional function called as metrics(fit = fit_i, K = K_rho, rho = rho_i). It may return a named list or one-row data frame of additional scalar summaries, such as a Gamma correlation or a component norm.

eps

Positive numerical floor passed to make_cross_kernel().

keep_fits

Logical; if TRUE, fitted objects are attached as a "fits" attribute. Default FALSE keeps the returned object light.

...

Additional arguments passed to refit.

Value

A data frame of class gllvmTMB_cross_rho_profile with columns rho, logLik, relative_logLik, delta_deviance, is_best, convergence, pd_hessian, status, and error, plus any metric columns returned by metrics.

Examples

A_H <- diag(2)
A_P <- diag(2)
rownames(A_H) <- colnames(A_H) <- c("H1", "H2")
rownames(A_P) <- colnames(A_P) <- c("P1", "P2")
W <- matrix(c(1, 0.2, 0.2, 1), 2, 2)
dimnames(W) <- list(rownames(A_H), rownames(A_P))
dat <- data.frame(y = c(1, 2, 3, 4), x = c(0, 1, 0, 1))
profile_cross_rho(
  A_H, A_P, W,
  rho = c(0, 0.25),
  refit = function(K, rho) stats::lm(y ~ x, data = dat)
)
#>    rho    logLik relative_logLik delta_deviance is_best convergence pd_hessian
#> 1 0.00 -5.675754               0              0    TRUE          NA         NA
#> 2 0.25 -5.675754               0              0   FALSE          NA         NA
#>   status error
#> 1     ok  <NA>
#> 2     ok  <NA>