pkern_nLL: Negative log-likelihood for parameter vector 'p'

View source: R/pkern_model.R

pkern_nLLR Documentation

Negative log-likelihood for parameter vector p

Description

Returns the negative log-likelihood of parameter vector p for the covariance model pars_fix, given data grid g_obs.

Usage

pkern_nLL(
  p,
  g_obs,
  pars_fix,
  X = 0,
  iso = FALSE,
  quiet = TRUE,
  log_scale = FALSE
)

Arguments

p

numeric vector of covariance parameters accepted by pkern_pars_update

g_obs

list of form returned by pkern_grid (with entries 'gdim', 'gres', 'gval')

pars_fix

list of form returned by pkern_pars (with entries 'y', 'x', 'eps', 'psill')

X

numeric, vector, matrix, or NA, the mean or its linear predictors, passed to pkern_LL

iso

logical, indicates to use identical kernels for x and y (pars$x is ignored)

quiet

logical indicating to suppress console output

Details

This is a wrapper for -pkern_LL() allowing parameters to be passed as a numeric vector instead of a list (for use in optimization etc). Parameters in p are copied to pars_fix and passed to the likelihood computer.

p is the vector of covariance parameters to test. Names in p are ignored; Its length and order should correspond with the pattern of NAs in pars_fix. Users should check that the desired parameter list is being constructed correctly by testing with: pkern_pars_update(pars_fix, p, iso=iso, na_omit=TRUE).

Value

numeric, the negative log-likelihood of p given g_obs

Examples

# set up example grid and data
g_obs = pkern_grid(10)
g_obs$gval = rnorm(10^2)

# get some default parameters and vectorize them
pars = pkern_pars(g_obs, 'gau')
p = pkern_pars_update(pars)
pkern_nLL(p, g_obs, pars)

# change a parameter and re-evaluate
p_compare = p
p_compare[1] = 2*p_compare[1]
pkern_nLL(p_compare, g_obs, pars)

# repeat by calling pkern_LL directly
pars_compare = pars
pars_compare$eps = 2*pars_compare$eps
-pkern_LL(pars_compare, g_obs)

# set up a subset of parameters for fitting
pars_fix = pars
pars_fix$eps = NA
pars_fix$y$kp = NA

# names in p_fit are for illustration only (only the order matters)
p_fit = c(eps=1, y.rho=1)
pkern_nLL(p_fit, g_obs, pars_fix)

# equivalently:
pars_fit = pars
pars_fit$eps = p_fit[1]
pars_fit$y$kp = p_fit[2]
-pkern_LL(pars_fit, g_obs)

# check an input specification
pkern_pars_update(pars_fix, p_fit, na_omit=TRUE)
pars_fit



deankoch/pkern documentation built on Oct. 26, 2023, 8:54 p.m.