Learn R Programming

SuperGauss (version 1.0.2)

Snorm.grad: Gradient of the loglikelihood of a multivariate normal with Toeplitz variance matrix.

Description

Superfast evaluation of loglikelihood gradient.

Usage

Snorm.grad(X, mu, acf, dmu, dacf)

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.

Value

A length-p vector containing the gradient of the loglikelihood.

Examples

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

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

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

# likelihood gradient
Snorm.grad(X = X, mu = mu.fun(theta), dmu = dmu.fun(theta),
           acf = acf.fun(theta), dacf = dacf.fun(theta))
# }

Run the code above in your browser using DataLab