gamlss.gH {mgcv}R Documentation

Calculating derivatives of log-likelihood wrt regression coefficients

Description

Mainly intended for internal use with location scale model families. Given the derivatives of the log-likelihood wrt the linear predictor, this function obtains the derivatives and Hessian wrt the regression coefficients and derivatives of the Hessian w.r.t. the smoothing parameters. For input derivative array packing conventions see trind.generator.

Usage

gamlss.gH(X, jj, l1, l2, i2, l3 = 0, i3 = 0, l4 = 0, i4 = 0, d1b = 0,
  d2b = 0, deriv = 0, fh = NULL, D = NULL,sandwich=FALSE)

Arguments

X

matrix containing the model matrices of all the linear predictors.

jj

list of index vectors such that X[,jj[[i]]] is the model matrix of the i-th linear predictor.

l1

array of 1st order derivatives of each element of the log-likelihood wrt each parameter.

l2

array of 2nd order derivatives of each element of the log-likelihood wrt each parameter.

i2

two-dimensional index array, such that l2[,i2[i,j]] contains the partial w.r.t. params indexed by i,j with no restriction on the index values (except that they are in 1,...,ncol(l1)).

l3

array of 3rd order derivatives of each element of the log-likelihood wrt each parameter.

i3

third-dimensional index array, such that l3[,i3[i,j,k]] contains the partial w.r.t. params indexed by i,j,k.

l4

array of 4th order derivatives of each element of the log-likelihood wrt each parameter.

i4

third-dimensional index array, such that l4[,i4[i,j,k,l]] contains the partial w.r.t. params indexed by i,j,k,l.

d1b

first derivatives of the regression coefficients wrt the smoothing parameters.

d2b

second derivatives of the regression coefficients wrt the smoothing parameters.

deriv

if deriv==0 only first and second order derivatives will be calculated. If deriv==1 the function return also the diagonal of the first derivative of the Hessian, if deriv==2 it return the full 3rd order derivative and if deriv==3 it provides also 4th order derivatives.

fh

eigen-decomposition or Cholesky factor of the penalized Hessian.

D

diagonal matrix, used to provide some scaling.

sandwich

set to TRUE to return sandwich estimator 'filling', as opposed to the Hessian, in l2.

Value

A list containing lb - the grad vector w.r.t. coefs; lbb - the Hessian matrix w.r.t. coefs; d1H - either a list of the derivatives of the Hessian w.r.t. the smoothing parameters, or a single matrix whose columns are the leading diagonals of these dervative matrices; trHid2H - the trace of the inverse Hessian multiplied by the second derivative of the Hessian w.r.t. all combinations of smoothing parameters.

Author(s)

Simon N. Wood <simon.wood@r-project.org>.

See Also

trind.generator


[Package mgcv version 1.9-1 Index]