-
Notifications
You must be signed in to change notification settings - Fork 0
/
nw function.R
138 lines (109 loc) · 2.76 KB
/
nw function.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
getnw <- function(type, half = FALSE){
# For all models, nw_b should fit better than nw_a.
# The first models are the models from the proposal.
# The models with a 2 are alternative models that should be similar.
if(type == "degree"){
nw <- matrix(0, 8, 8)
nw[1, 2] <- nw[1, 5] <-
nw[2, 3] <- nw[2, 6] <-
nw[2, 7] <- nw[3, 4] <-
nw[3, 7] <- nw[4, 7] <-
nw[5, 6] <- nw[6, 7] <-
nw[7, 8] <- 1
nw_a <- nw
nw_a[2, 6] <- 0
nw_b <- nw
nw_b[3, 7] <- 0
}
if(type == "close"){
nw <- matrix(0, 7, 7)
nw[1, 2] <- nw[1, 5] <-
nw[2, 3] <- nw[2, 6] <-
nw[3, 4] <- nw[3, 7] <-
nw[4, 7] <- nw[5, 6] <-
nw[6, 7] <- 1
nw_a <- nw
nw_a[3, 7] <- 0
nw_b <- nw
nw_b[2, 6] <- 0
}
if(type == "between"){
nw <- matrix(0, 7, 7)
nw[1, 5] <- nw[2, 3] <-
nw[2, 6] <- nw[2, 7] <-
nw[3, 7] <- nw[4, 5] <-
nw[5, 6] <- nw[6, 7] <- 1
nw_a <- nw
nw_a[5, 6] <- 0
nw_b <- nw
nw_b[2, 7] <- 0
}
if(type == "alt"){
nw <- matrix(0,6,6)
nw[1, 2] <- nw[1, 4] <-
nw[2, 3] <- nw[2, 5] <-
nw[3, 5] <- nw[3, 6] <-
nw[4, 5] <- nw[5, 6] <- 1
nw_a <- nw
nw_a[1, 2] <- 0
nw_b <- nw
nw_b[3, 6] <- 0
}
if(type == "degree2"){
nw <- matrix(0, 8, 8)
nw[1, 2] <- nw[2, 3] <-
nw[2, 4] <- nw[2, 5] <-
nw[3, 6] <- nw[5, 6] <-
nw[6, 7] <- nw[7, 8] <- 1
nw_a <- nw
nw_a[5, 6] <- 0
nw_b <- nw
nw_b[2, 5] <- 0
}
if(type == "close2"){
nw <- matrix(0, 7, 7)
nw[1, 5] <- nw[2, 3] <- nw[2, 5] <-
nw[2, 6] <- nw[3, 4] <- nw[3, 7] <-
nw[5, 6] <- nw[4,7] <-
nw[6, 7] <- 1
nw_a <- nw
nw_a[3, 7] <- 0
nw_b <- nw
nw_b[2, 6] <- 0
}
if(type == "between2"){
nw <- matrix(0, 8, 8)
nw[1, 5] <- nw[2, 3] <-
nw[2, 6] <- nw[2, 7] <-
nw[3, 7] <- nw[4, 8] <-
nw[5, 6] <- nw[6, 7] <-
nw[7, 8] <- 1
nw_a <- nw
nw_a[7, 8] <- 0
nw_b <- nw
nw_b[2, 6] <- 0
}
if(type == "alt2"){
nw <- matrix(0,6,6)
nw[1, 4] <- nw[2, 3] <-
nw[2, 4] <- nw[2, 5] <-
nw[3, 5] <- nw[3, 6] <-
nw[4, 5] <- nw[5, 6] <- 1
nw_a <- nw
nw_a[4, 5] <- 0
nw_b <- nw
nw_b[2, 5] <- 0
}
# For the Preacher method we need the full matrices.
# For the mimicry method we need half the matrices.
if(half == FALSE){
nw[lower.tri(nw)] <- t(nw)[lower.tri(nw)]
nw_a[lower.tri(nw_a)] <- t(nw_a)[lower.tri(nw_a)]
nw_b[lower.tri(nw_b)] <- t(nw_b)[lower.tri(nw_b)]
}
# Put all the models in a list
nwmodels <- list(full = nw,
a = nw_a,
b = nw_b)
return(nwmodels)
}