chainrule {dsfa} | R Documentation |
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.
chainrule(f = NULL, g = NULL, deriv = 2, tri = NULL)
f |
vector of |
g |
matrix of |
deriv |
derivative of order |
tri |
optional, index arrays for upper triangular for g, generated by |
Mostly internal function, which is helpful in calculating the partial derivatives of the loglikelihood.
A list with partial derivatives. The index of the list corresponds to a matrix with all partial derivatives of that order.
x<-1 #For K=1, x_1 value is set to 1.
g<-1/x #g(x_1) = 1/x
attr(g,"gradient")<-matrix(-1/x^2,ncol=1)
attr(g,"hessian")<-matrix(2/x^3,ncol=1)
attr(g,"l3")<-matrix(-6/x^4,ncol=1)
attr(g,"l4")<-matrix(24/x^5,ncol=1)
zeta_g<-zeta(g, deriv=4) #f(g(x)) = zeta(g(x))
chainrule(f=zeta_g, g=g, deriv=4)