Learn R Programming

SuperGauss (version 1.0.2)

Snorm.hess: Hessian of the loglikelihood of a multivariate normal with Toeplitz variance matrix.

Description

Superfast evaluation of loglikelihood Hessian.

Usage

Snorm.hess(X, mu, acf, dmu, dacf, d2mu, d2acf)

Arguments

X

A length-N vector of multivariate normal observations.

mu

A scalar or length-N vector of means. If missing defaults to the vector of zeros.

acf

A Toeplitz object or length-N vector containing the first column of the Toeplitz variance matrix.

dmu

A length-p vector or N x p matrix of partial derivatives of mu along the columns. If missing defaults to a matrix of zeros.

dacf

An N x p matrix with the partial derivatives of acf along the columns.

d2mu

A p x p matrix or N x p x p array of second partial derivatives of mu. If missing defaults to zeros.

d2acf

A N x p x p array of second partial derivatives of acf.

Value

The p x p Hessian matrix of the loglikelihood.

Examples

Run this code
# NOT RUN {
# two parameter inference
acf.fun <- function(theta) theta[2]^2 * exp(-(1:N-1))
mu.fun <- function(theta) theta[1] * (1:N) + log(theta[2] + 1:N)

# partial derivatives
dacf.fun <- function(theta) {
  cbind(0, 2*theta[2] * exp(-(1:N-1)))
}
dmu.fun <- function(theta) cbind(1:N, 1/(theta[2] + 1:N))

# 2nd order partials
d2acf.fun <- function(theta) {
  H <- array(0, dim = c(N, 2, 2))
  H[,2,2] <- 2*exp(-(1:N-1))
  H
}
d2mu.fun <- function(theta) {
  H <- array(0, dim = c(N, 2, 2))
  H[,2,2] <- -1/(theta[2] + 1:N)^2
  H
}

# generate data
N <- 300
theta <- rexp(2)
X <- rSnorm(n = 1, acf = acf.fun(theta)) + mu.fun(theta)

# likelihood Hessian
Snorm.hess(X = X, mu = mu.fun(theta), acf = acf.fun(theta),
           dmu = dmu.fun(theta), dacf = dacf.fun(theta),
           d2mu = d2mu.fun(theta), d2acf = d2acf.fun(theta))
# }

Run the code above in your browser using DataLab