Hi! I've been working with your package, and have come across an issue. Sometimes when I estimate a model using the vinecop() function, some of the variable type pairs encoded in each bicop() object, are in the wrong order. If I refit the model using the structure found in the first instance, all of the variable type pairs seem to be in the right order. Since all the pair copulas have the same rotations and parameters, in both cases, I assume that the issue is just the label in the bicop() object, see example below.
# Compile data
x <- cbind(MASS::Boston[, c(4, 1, 6, 7)], discr_medv=1*(MASS::Boston[, 14] > 20))
x_type <- apply(x, 2,
function(z) switch (1 + (length(unique(z)) > 2),
"d",
"c"))
names(x_type) <- c()
margins <- apply(x, 2, ecdf)
u <- cbind(sapply(1:ncol(x), function(j) margins[[j]](x[, j])
* nrow(x)/(nrow(x) + 1)),
sapply(which(x_type=="d"),
function(j) margins[[j]](x[, j] - 0.0000001)
* nrow(x)/(nrow(x) + 1)))
# fit model
model_x <- rvinecopulib::vinecop(u, x_type, family_set = c("gaussian", "clayton", "gumbel"))
model_mat <- rvinecopulib::as_rvine_matrix(model_x$structure)
# Compile a vector that lists the variable types of the margins in each copula
actual_var_types <- rbind(t(sapply(1:(5 - 1),
function(e) x_type[model_mat[c(5 + 1 - e, 1),
e]])),
t(sapply(1:(5 - 2),
function(e) x_type[model_mat[c(5 + 1 - e, 2),
e]])),
t(sapply(1:(5 - 3),
function(e) x_type[model_mat[c(5 + 1 - e, 3),
e]])),
t(sapply(1:(5 - 4),
function(e) x_type[model_mat[c(5 + 1 - e, 4),
e]])))
e]])))
summ <- summary(model_x)
summ$act_var_type <- apply(actual_var_types, 1,
function(x) paste(x, collapse=","))
summ <- summ[, c(1:5, 12, 6:11)]
summ
# Output:
# # A data.frame: 10 x 12
# tree edge conditioned conditioning var_types act_var_type family rotation parameters df tau loglik
# 1 1 3, 5 d,c c,d gumbel 0 1.8 1 0.444 69.21
# 1 2 2, 4 c,c c,c gaussian 0 0.59 1 0.402 132.61
# 1 3 1, 5 d,d d,d gumbel 0 1.2 1 0.169 3.39
# 1 4 4, 5 d,c c,d gumbel 90 1.9 1 -0.469 84.37
# 2 1 3, 1 5 c,d c,d gumbel 0 1 1 0.028 0.42
# 2 2 2, 5 4 d,c c,d gaussian 0 -0.34 1 -0.220 13.18
# 2 3 1, 4 5 c,d d,c gaussian 0 0.2 1 0.128 3.59
# 3 1 3, 4 1, 5 c,c c,c clayton 270 0.12 1 -0.057 9.08
# 3 2 2, 1 5, 4 d,c c,d clayton 0 0.31 1 0.134 1.07
# 4 1 3, 2 4, 1, 5 c,c c,c clayton 270 0.21 1 -0.097 6.23
# Refit, but provide the structure as the one estimated the first time,
# and print summary (Now the variable types switches)
summary(vinecop(u, x_type, structure = model_x$structure,
family_set = c("gaussian", "clayton", "gumbel")))
# Output:
# # A data.frame: 10 x 11
# tree edge conditioned conditioning var_types family rotation parameters df tau loglik
# 1 1 3, 5 c,d gumbel 0 1.8 1 0.444 69.21
# 1 2 2, 4 c,c gaussian 0 0.59 1 0.402 132.61
# 1 3 1, 5 d,d gumbel 0 1.2 1 0.169 3.39
# 1 4 4, 5 c,d gumbel 90 1.9 1 -0.469 84.37
# 2 1 3, 1 5 c,d gumbel 0 1 1 0.028 0.42
# 2 2 2, 5 4 c,d gaussian 0 -0.34 1 -0.220 13.18
# 2 3 1, 4 5 d,c gaussian 0 0.2 1 0.128 3.59
# 3 1 3, 4 1, 5 c,c clayton 270 0.12 1 -0.057 9.08
# 3 2 2, 1 5, 4 c,d clayton 0 0.31 1 0.134 1.07
# 4 1 3, 2 4, 1, 5 c,c clayton 270 0.21 1 -0.097 6.23