loglikeSTGrad {SpatioTemporal} | R Documentation

## Compute Gradient and Hessian for the Log-likelihood

### 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

    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

    ## 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)

[Package SpatioTemporal version 1.1.9.1 Index]