# it might be helpful to use the function plot.hac to verify the
# results (see example 2)
# Example 1: 4-dim AC
Matrix = 2.5
Object = hac(AC_CLAYTON, X = Matrix, dim = 4)
# class(Object) # [1] "hac"
tree2str(Object) # [1] "(V1.V2.V3.V4)_2.5"
plot(Object, , ylim = c(-0.4, 1.25), l = 1, h = 0.35)
# Example 2: 4-dim HAC
Matrix1 = matrix(c(2, 0, 4, ~X1 + X4, ~X2, ~X3), nrow = 3, byrow = TRUE)
y = c(~X1 + X4, ~X3, ~X2)
theta = c(2, 4)
Matrix4 = matrix(c(2, 0, 0, 0, ~X1 + X4, 4, 0, 0, 0, 0, ~X2, ~X3),
nrow = 3, byrow = TRUE)
List = list(V1 = list(V1 = "X2", V2 = "X3", theta = 4), V2 = c("X1", "X4"),
theta = 2)
# Matrix2
# [,1] [,2] [,3] [,4]
# [1,] 2 0 0 0
# [2,] Expression 4 0 0
# [3,] 0 0 Expression Expression
Object1 = hac(HAC_CLAYTON, Matrix1)
Object2 = hac.full(HAC_CLAYTON, y, theta)
Object3 = as.hac(HAC_CLAYTON, List)
tree2str(Object1) == tree2str(Object2) # [1] TRUE
tree2str(Object3) == tree2str(Object1) # [1] TRUE
tree2str(Object1) # [1] "((X2.X3)_{4}.X1.X4)_{2}"
# Object1 and Object 2 contain identical information
Object4 = hac(HAC_CLAYTON, Matrix4)
# the plots show, that the Objects are mirrored
plot.hac(Object1)
plot.hac(Object3)
# Example 3: 6-dim HAC
Matrix = matrix(c(2, 0, 0, 0, 3, 4, 0, 0, ~X1 + X6, ~X2, ~X3, ~X4 + X5),
nrow = 3, byrow = TRUE)
List = list(V1= list(V1 = c("X1", "X6"), V2 = "X2", theta = 3), V2 = list(
V1 = "X3", V2 = c("X4", "X5"), theta = 4), theta = 2)
# Matrix
# [,1] [,2] [,3] [,4]
# [1,] 2 0 0 0
# [2,] 3 4 0 0
# [3,] Expression Expression Expression Expression
Object1 = hac(HAC_CLAYTON, Matrix)
Object2 = as.hac(HAC_CLAYTON, List)
tree2str(Object1) == tree2str(Object2) # [1] TRUE
plot.hac(Object1)
# Example 4: 5-dim HAC
Matrix1 = matrix(c(1, 0, 0, 0, 2, 3, 0, 0, ~X1,
4, ~X4, ~X5, 0, 0, ~X2, ~X3), nrow = 4, byrow = TRUE)
Matrix2 = matrix(c(1, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, ~X1,
4, ~X4, ~X5, 0, 0, 0, 0, 0, 0, ~X2, ~X3, 0, 0, 0, 0), nrow = 4,
byrow = TRUE)
List = list(V1= list(V1 = "X1", V2 = list(V1 = "X2", V2 = "X3",
theta = 4), theta = 2), V2 = list(V1 = "X4", V2 = "X5", theta = 3),
theta = 1)
# Matrix2
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
# [1,] 1 0 0 0 0 0 0 0
# [2,] 2 3 0 0 0 0 0 0
# [3,] Expression 4 Expression Expression 0 0 0 0
# [4,] 0 0 Expression Expression 0 0 0 0
Object1 = hac(HAC_CLAYTON, Matrix1)
Object2 = hac(HAC_CLAYTON, Matrix2)
Object3 = as.hac(HAC_CLAYTON, List)
tree2str(Object1) == tree2str(Object2) # [1] TRUE
tree2str(Object1) == tree2str(Object3) # [1] TRUE
Object1
plot(Object1)
# the previous result implies, that it is not necessary to include vectors
# of 0 in the matrix. Furthermore identical objects can be created by
# hac and as.hac.
Run the code above in your browser using DataLab