chainrule {dsfa} R Documentation

## Chainrule

### Description

Calculates the partial derivatives of the function h(x_1,x_2,...,x_{K})=f(g(x_1,x_2,...,x_{K})) up to order four. Here K is the number of inputs for function g(\cdot). The function f(\cdot) can only have a single input. Alternatively chainrule can calculate the partial derivatives of h(x_1,x_2,...,x_{K})=f(g_1(x_1),g_2(x_2),...,g_K(x_{K})) up to order four. Here each g_k(\cdot) can only take a single input x_k. If x_i \neq x_j for i,j \in \{1,...,K \} then the input argument g can be a list with elements g_k(x_k). The function checks the number of inputs of f(\cdot) by counting the number of partial derivatives and then decides automatically how to proceed.

### Usage

chainrule(f = NULL, g = NULL, deriv = 2, tri = NULL)


### Arguments

 f vector of f(\cdot) evaluated at g(\cdot) with derivatives as attributes. g matrix of g(\cdot) with derivatives as attributes. Alternatively written as g(\cdot)=g_1(x_1),g_2(x_2),...,g_K(x_{K})). In this case, g can be a vector or a list of length k deriv derivative of order deriv. Available are 0,2 and 4. tri optional, index arrays for upper triangular for g, generated by trind.generator().

### Details

Mostly internal function, which is helpful in calculating the partial derivatives of the loglikelihood.

### Value

A list with partial derivatives. The index of the list corresponds to a matrix with all partial derivatives of that order.

### Examples

x<-1 #For K=1, x_1 value is set to 1.

g<-1/x #g(x_1) = 1/x