# Example 1:
# an object of the class hac is constructed, such that
# the values of the dependency parameters are closely
M = matrix(c(1.01, 0, 0, 0, ~X1 + X2, 1.02, 0, 0, 0, 0, ~X3 + X4, ~X5 + X6),
ncol = 4, byrow = TRUE)
Object = hac(HAC_GUMBEL, M)
# the function aggregate returns an AC_GUMBEL model, since the tree
# collapses to an Archimedean copulae
Object_ag = aggregate(Object, 0.1)
# if we choose epsilon smaller, e.g. 0.0001, nothing occurs and the
# model remains as it is
Object_not_ag = aggregate(Object, 0.0001)
# Example 2:
# consider a binary tree
Object = hac.full(y = c(~X1, ~X2, ~X3, ~X4, ~X5), theta = c(1.01, 1.02, 2, 2.01))
tree2str(Object) # [1] "((((X5.X4)_{2.01}.X3)_{2}.X2)_{1.02}.X1)_{1.01}"
# after the application of aggregate.hac, with epsilon = 0.011, two nodes remain
Object_ag = aggregate(Object, 0.011)
tree2str(Object_ag) # [1] "((X5.X4.X3)_{2.005}.X2.X1)_{1.015}"
# Example 3:
# consider the following deeply nested model
X = matrix(c(0.7, 0, 0, 0, 0, 0, 0, 0,
1, 0.75, 0, 0, 0, 0, 0, 0,
1.01, 1.02, ~X1, ~X2, 0, 0, 0, 0,
~X3, 2, 2.01, 2.02, 0, 0, 0, 0,
0, 0, ~X4, ~X5, ~X6, ~X7, ~X8, ~X9), nrow = 5, byrow = TRUE)
Object = hac(HAC_CLAYTON, X)
# to get an idea about the structure, plot Object
plot(Object)
# if aggregate.hac is applied with epsilon = 0.1, the object simplifies
# but the nodes with the parameter values 1.01 and 1.02 remain, since
# the upper node cannot host 3 nodes and 1 variable
Object_ag = aggregate(Object, 0.1)
plot(Object_ag)
Run the code above in your browser using DataLab