Learn R Programming

madness (version 0.1.0)

madness-class: Madness Class.

Description

An S4 class to enable forward differentiation of multivariate computations. Think of madness as multivariate automatic differentiation -ness. There is also a constructor method for madness objects, and a wrapper method.

Usage

## S3 method for class 'madness':
initialize(.Object, val, dvdx, xtag = NA_character_,
  vtag = NA_character_, varx = matrix(nrow = 0, ncol = 0))

madness(val, dvdx = NULL, vtag = NULL, xtag = NULL, varx = NULL)

Arguments

.Object
a madness object, or proto-object.
val
an array of some numeric value, of arbitrary dimension.
dvdx
a matrix of the derivative of (the vector of) val with respect to some independent variable, $X$.
xtag
an optional name for the $X$ variable.
vtag
an optional name for the $val$ variable.
varx
an optional variance-covariance matrix of the independent variable, $X$.

Value

  • An object of class madness.

Details

A madness object contains a (multidimensional) value, and the derivative of that with respect to some independent variable. The purpose is to simplify computation of multivariate derivatives, especially for use in the Delta method. Towards this usage, one may store the covariance of the independent variable in the object as well, from which the approximate variance-covariance matrix can easily be computed. See vcov.

Note that derivatives are all implicitly 'flattened'. That is, when we talk of the derivative of $i \times j$ matrix $Y$ with respect to $m \times n$ matrix $X$, we mean the derivative of the $ij$ vector $\mathrm{vec}\left(Y\right)$ with respect to the $mn$ vector $\mathrm{vec}\left(X\right)$. Moreover, derivatives follow the 'numerator layout' convention: this derivative is a $ij \times mn$ matrix whose first column is the derivative of $\mathrm{vec}\left(Y\right)$ with respect to $X_{1,1}$. Numerator layout feels unnatural because it makes a gradient vector of a scalar-valued function into a row vector. Despite this deficiency, it makes the product rule feel more natural. (2FIX: is this so?)

References

Petersen, Kaare Brandt and Pedersen, Michael Syskind. "The Matrix Cookbook." Technical University of Denmark (2012). http://www2.imm.dtu.dk/pubdb/p.php?3274

Magnus, Jan R. and Neudecker, H. "Matrix Differential Calculus with Applications in Statistics and Econometrics." 3rd Edition. Wiley Series in Probability and Statistics: Texts and References Section (2007). http://www.janmagnus.nl/misc/mdc2007-3rdedition

Examples

Run this code
obj <- new("madness", val=matrix(rnorm(10*10),nrow=10), dvdx=diag(100), xtag="foo", vtag="foo")
obj2 <- madness(val=matrix(rnorm(10*10),nrow=10), xtag="foo", vtag="foo^2")

Run the code above in your browser using DataLab