# We simulate from a conditional copula
set.seed(1)
N = 300
Z = rnorm(n = N, mean = 5, sd = 2)
conditionalTau = -0.9 + 1.8 * pnorm(Z, mean = 5, sd = 2)
simCopula = VineCopula::BiCopSim(N=N , family = 1,
par = VineCopula::BiCopTau2Par(1 , conditionalTau ))
X1 = qnorm(simCopula[,1])
X2 = qnorm(simCopula[,2])
newZ = seq(2,8,by = 0.1)
h = 0.1
estimatedCKT_tree <- CKT.estimate(
X1 = X1, X2 = X2, Z = Z,
newZ = newZ,
methodEstimation = "tree", h = h)
estimatedCKT_rf <- CKT.estimate(
X1 = X1, X2 = X2, Z = Z,
newZ = newZ,
methodEstimation = "randomForest", h = h)
estimatedCKT_GLM <- CKT.estimate(
X1 = X1, X2 = X2, Z = Z,
newZ = newZ,
methodEstimation = "logit", h = h,
listPhi = list(function(x){return(x)}, function(x){return(x^2)},
function(x){return(x^3)}) )
estimatedCKT_kNN <- CKT.estimate(
X1 = X1, X2 = X2, Z = Z,
newZ = newZ,
methodEstimation = "nearestNeighbors", h = h,
number_nn = c(50,80, 100, 120,200),
partition = 4
)
estimatedCKT_nNet <- CKT.estimate(
X1 = X1, X2 = X2, Z = Z,
newZ = newZ,
methodEstimation = "neuralNetwork", h = h,
)
estimatedCKT_kernel <- CKT.estimate(
X1 = X1, X2 = X2, Z = Z,
newZ = newZ,
methodEstimation = "kernel", h = h,
)
estimatedCKT_kendallReg <- CKT.estimate(
X1 = X1, X2 = X2, Z = Z,
newZ = newZ,
methodEstimation = "kendallReg", h = h)
# Comparison between true Kendall's tau (in black)
# and estimated Kendall's tau (in other colors)
trueConditionalTau = -0.9 + 1.8 * pnorm(newZ, mean = 5, sd = 2)
plot(newZ, trueConditionalTau , col="black",
type = "l", ylim = c(-1, 1))
lines(newZ, estimatedCKT_tree, col = "red")
lines(newZ, estimatedCKT_rf, col = "blue")
lines(newZ, estimatedCKT_GLM, col = "green")
lines(newZ, estimatedCKT_kNN, col = "purple")
lines(newZ, estimatedCKT_nNet, col = "coral")
lines(newZ, estimatedCKT_kernel, col = "skyblue")
lines(newZ, estimatedCKT_kendallReg, col = "darkgreen")
Run the code above in your browser using DataLab