This function is used calculate the derivative values (first and second derivatives for Newton-Raphson method) and loglikelihood when updating A
derivatives(A, Gamma, Dmat, I, zy, refA)matrix with value from previous iteration
G matrix values
the coefficient matrix for the fixed variables,
a U by U incidence matrix with elements; I(i,j)=1 if state j can be accessed from state i in one step and 0 otherwise
the variable values for a given observation
a vector of reference categories
a list of outputs:
fird: the first derivative value
secd: the second derivative value
loglike: the loglikelihood