loglikeSTGrad: Compute Gradient and Hessian for the Log-likelihood

Description Usage Arguments Value Warning Author(s) See Also Examples

View source: R/loglikeST_derivatives.R

Description

Computes finite difference gradients and hessians for the log-likelihood functions loglikeST and loglikeSTnaive.
Uses genGradient and genHessian to compute finite difference derivatives of the log-likelihood function in loglikeST and loglikeSTnaive.

Usage

1
2
3
4
5
6
7
8
9
loglikeSTGrad(x, STmodel, type = "p", x.fixed = NULL, h = 0.001,
  diff.type = 0)

loglikeSTHessian(x, STmodel, type = "p", x.fixed = NULL, h = 0.001)

loglikeSTnaiveGrad(x, STmodel, type = "p", x.fixed = NULL, h = 0.001,
  diff.type = 0)

loglikeSTnaiveHessian(x, STmodel, type = "p", x.fixed = NULL, h = 0.001)

Arguments

x

Point at which to compute the gradient or hessian, see loglikeST.

STmodel

STmodel object with the model for which to compute derivatives of the log-likelihood.

type

A single character indicating the type of log-likelihood to compute. Valid options are "f", "p", and "r", for full, profile or restricted maximum likelihood (REML).

x.fixed

Parameters to keep fixed, see loglikeST.

h, diff.type

Step length and type of finite difference to use when computing gradients, see genGradient.

Value

Returns the gradient or Hessian for the loglikeST and loglikeSTnaive functions.

Warning

loglikeSTnaiveGrad and loglikeSTnaiveHhessian may take very long time to run, use with extreme caution.

Author(s)

Johan Lindstrom

See Also

Other likelihood functions: loglikeST

Other numerical derivatives: genGradient

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
  ##load the data
  data(mesa.model)
  
  ##Compute dimensions for the data structure
  dim <- loglikeSTdim(mesa.model)
  
  ##Let's create random vectors of values
  x <- runif(dim$nparam.cov)
  x.all <- runif(dim$nparam)
 
  ##Compute the gradients
  Gf <- loglikeSTGrad(x.all, mesa.model, "f")
  Gp <- loglikeSTGrad(x, mesa.model, "p")
  Gr <- loglikeSTGrad(x, mesa.model, "r")
 
  ##And the Hessian, this may take some time...
  Hf <- loglikeSTHessian(x.all, mesa.model, "f")
  Hp <- loglikeSTHessian(x, mesa.model, "p")
  Hr <- loglikeSTHessian(x, mesa.model, "r")

## End(Not run)

SpatioTemporal documentation built on June 25, 2018, 9:03 a.m.