# simulate data
family <- 5 # Frank copula
n <- 1000
x <- runif(n) # covariate values
eta_fun <- function(x) 2*cos(12*pi*x) # copula dependence parameter
eta_true <- eta_fun(x)
par_true <- BiCopEta2Par(family, eta = eta_true)
udata <- VineCopula::BiCopSim(n, family=family,
par = par_true$par)
# local likelihood estimation
x0 <- seq(min(x), max(x), len = 100)
band <- .02
system.time({
eta_hat <- CondiCopLocFit(u1 = udata[,1], u2 = udata[,2],
family = family, x = x, x0 = x0, band = band)
})
# custom optimization routine using stats::optim (gradient-free)
my_optim <- function(obj) {
opt <- stats::optim(par = obj$par, fn = obj$fn, method = "Nelder-Mead")
return(opt$par[1]) # always return constant term, even if degree > 0
}
system.time({
eta_hat2 <- CondiCopLocFit(u1 = udata[,1], u2 = udata[,2],
family = family, x = x, x0 = x0, band = band,
optim_fun = my_optim)
})
plot(x0, BiCopEta2Tau(family, eta = eta_fun(x0)), type = "l",
xlab = expression(x), ylab = expression(tau(x)))
lines(x0, BiCopEta2Tau(family, eta = eta_hat$eta), col = "red")
lines(x0, BiCopEta2Tau(family, eta = eta_hat2$eta), col = "blue")
legend("bottomright", fill = c("black", "red", "blue"),
legend = c("True", "optim_default", "Nelder-Mead"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.