R: Check consistency and Laplace accuracy

checkConsistency {TMB} | R Documentation

## Check consistency and Laplace accuracy

### Description

Check consistency of various parts of a TMB implementation. Requires that user has implemented simulation code for the data and optionally random effects. (Beta version; may change without notice)

### Usage

    checkConsistency(obj, par = NULL, hessian = FALSE, n = 100)

### Arguments

`obj` | Object from `MakeADFun`
`par` | Parameter vector (θ) for simulation. If unspecified use the best encountered parameter of the object.
`hessian` | Calculate the hessian matrix for each replicate ?
`n` | Number of simulations

### Details

This function checks that the simulation code of random effects and data is consistent with the implemented negative log-likelihood function. It also checks whether the approximate marginal score function is central indicating whether the Laplace approximation is suitable for parameter estimation.

Denote by u the random effects, θ the parameters and by x the data. The main assumption is that the user has implemented the joint negative log likelihood f_{θ}(u,x) satisfying

\int \int \exp( -f_{θ}(u,x) ) \:du\:dx = 1

It follows that the joint and marginal score functions are central:

1. E_{u,x}≤ft[\nabla_{θ}f_{θ}(u,x)\right]=0

2. E_{x}≤ft[\nabla_{θ}-\log≤ft( \int \exp(-f_{θ}(u,x))\:du \right) \right]=0

For each replicate of u and x joint and marginal gradients are calculated. Appropriate centrality tests are carried out by `summary.checkConsistency`. An asymptotic χ^2 test is used to verify the first identity. Power of this test increases with the number of simulations `n`. The second identity holds approximately when replacing the marginal likelihood with its Laplace approximation. A formal test would thus fail eventually for large `n`. Rather, the gradient bias is transformed to parameter scale (using the estimated information matrix) to provide an estimate of parameter bias caused by the Laplace approximation.

### Value

List with gradient simulations (joint and marginal)

### See Also

`summary.checkConsistency`, `print.checkConsistency`

### Examples

    ## Not run:
    runExample("simple")
    chk <- checkConsistency(obj)
    chk
    ## Get more details
    s <- summary(chk)
    s$marginal$p.value  ## Laplace exact for Gaussian models
    ## End(Not run)

[Package TMB version 1.9.0 Index]