# The loglikelihood of a univariate Davidian curve is given by,
dc_LL <- function(phi, dat) {
sum(log(ddc(dat, phi)))
}
# dc_grad can be used for obtaining the gradient of this loglikelihood as follows:
dc_LL_GR <- function(phi, dat) {
colSums(dc_grad(dat, phi))
}
# This can be verified by numerical approximation.
# For instance, using numDeriv package:
if (FALSE) {
phi <- c(-5, 2.5, 10)
d <- runif(10, -5, 5)
dc_LL_GR(phi, d)
numDeriv::grad(dc_LL, x = phi, dat = d)
phi <- c(-5, 0, 10)
dc_LL_GR(phi, d)
}
Run the code above in your browser using DataLab