通过再次阅读包里的示例看到了实现DVine拟合的办法。
原文如下:
# load data set
data(daxreturns)
# using only the first 4 variables and the first 250 observations
# we allow for the copula families: Gauss, t, Clayton, Gumbel, Frank and Joe
## determine the order of the nodes in a D-vine using the package TSP
library(TSP)
d <- dim(daxreturns)[2]
M <- 1 - abs(TauMatrix(daxreturns))
hamilton <- insert_dummy(TSP(M), label = "cut")
sol <- solve_TSP(hamilton, method = "repetitive_nn")
order <- cut_tour(sol, "cut")
DVM <- D2RVine(order, family = rep(0,d*(d-1)/2), par = rep(0, d*(d-1)/2))
RVineCopSelect(daxreturns, c(1:6), DVM$Matrix)
其中TSP是一个动态规划经典问题,即TSP(Traveling Salesman Problem)-----浅谈旅行商问题,可以参考一下https://www.cnblogs.com/dddyyy/p/10084673.html。
这个代码通过运用D2RVine函数将D结构转化为R结构,然后再使用RVineCopSelect函数计算D藤的最优结构。
本人的代码如下:
其中mpit为边缘分布残差标准化后的数据矩阵
library(TSP)
d <- dim(mpit)[2]#d为向量维度数
M <- 1 - abs(TauMatrix(mpit))
hamilton <- insert_dummy(TSP(M), label = "cut")
sol <- solve_TSP(hamilton, method = "repetitive_nn")
order <- cut_tour(sol, "cut")
DVM <- D2RVine(order, family = rep(0,d*(d-1)/2), par = rep(0, d*(d-1)/2))
DVM1=RVineCopSelect(mpit, c(1:10), DVM$Matrix)
summary(DVM1)#查看D藤的具体结构
RVineTreePlot(DVM1)#查看D藤结构图