-
Notifications
You must be signed in to change notification settings - Fork 0
/
pol_psy_04_2_ergm_undir.R
149 lines (120 loc) · 4.59 KB
/
pol_psy_04_2_ergm_undir.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
139
140
141
142
143
144
145
146
147
148
149
load("data/nw_df.RData")
library(tidyverse)
library(tidygraph)
library(ggraph)
library(network)
library(ergm)
library(ergm.userterms)
nw_obj <- nw_df %>% as_tbl_graph(directed = FALSE)
nw_edges <- nw_df
nw_names <- as_tibble(nw_obj) %>% select(name)
nw_nodes <- nw_names
## undirected
nw_ud <- as.network(nw_df,
vertices = nw_nodes,
directed = FALSE, multiple = TRUE)
# edges + triangles -------------------------------------------------------
summary(nw_ud ~ edges + triangles)
# edges triangle
# 8943 2594
set.seed(666)
mod_edges_triangles <- ergm(nw_ud ~ edges
+ triangles,
control = control.ergm(
parallel = 6,
parallel.type = "PSOCK",
MCMLE.maxit = 15,
MCMLE.effectiveSize = NULL)
)
mcmc.diagnostics(mod_edges_triangles)
summary(mod_edges_triangles)
# edges + gwesp -----------------------------------------------------------
summary(nw_ud ~ edges + gwesp(0.3, fixed = TRUE))
# edges gwesp.fixed.0.3
# 8943.000 3710.822
set.seed(666)
mod_edges_gwesp <- ergm(nw_ud ~ edges
+ gwesp(0.3, fixed = TRUE),
control = control.ergm(
parallel = 6,
parallel.type = "PSOCK",
MCMLE.maxit = 15,
MCMLE.effectiveSize = NULL)
)
mcmc.diagnostics(mod_edges_gwesp)
summary(mod_edges_gwesp)
# edges + 2 degrees -------------------------------------------------------
summary(nw_ud ~ edges + degree(2))
# edges degree2
# 8943 655
set.seed(666)
mod_edges_2degrees <- ergm(nw_ud ~ edges
+ degree(2),
control = control.ergm(
parallel = 6,
parallel.type = "PSOCK",
MCMLE.maxit = 100,
MCMLE.effectiveSize = NULL)
)
mcmc.diagnostics(mod_edges_2degrees)
summary(mod_edges_2degrees)
# edges + 3 degrees --------------------------------------------------------
summary(nw_ud ~ edges + degree(3))
# edges degree3
# 8943 206
set.seed(666)
mod_edges_3degrees <- ergm(nw_ud ~ edges
+ degree(3),
control = control.ergm(
parallel = 6,
parallel.type = "PSOCK",
MCMLE.maxit = 100,
MCMLE.effectiveSize = NULL)
)
mcmc.diagnostics(mod_edges_3degrees)
summary(mod_edges_3degrees)
# edges + min 2 degrees ---------------------------------------------------
summary(nw_ud ~ edges + mindegree(2))
# edges mindegree2
# 8943 1729
set.seed(666)
mod_edges_min2degrees <- ergm(nw_ud ~ edges
+ mindegree(2),
control = control.ergm(
parallel = 6,
parallel.type = "PSOCK",
MCMLE.maxit = 40,
MCMLE.effectiveSize = NULL)
)
mcmc.diagnostics(mod_edges_min2degrees)
summary(mod_edges_min2degrees)
# edges + min 3 degrees ---------------------------------------------------
summary(nw_ud ~ edges + mindegree(3))
# edges mindegree3
# 8943 1074
set.seed(666)
mod_edges_min3degrees <- ergm(nw_ud ~ edges
+ mindegree(3),
control = control.ergm(
parallel = 6,
parallel.type = "PSOCK",
MCMLE.maxit = 30,
MCMLE.effectiveSize = NULL)
)
mcmc.diagnostics(mod_edges_min3degrees)
summary(mod_edges_min3degrees)
# mcmc and god diagnostics ------------------------------------------------
mcmc.diagnostics(mod_edges_triangles)
mcmc.diagnostics(mod_edges_gwesp)
mcmc.diagnostics(mod_edges_2degrees)
mcmc.diagnostics(mod_edges_3degrees)
mcmc.diagnostics(mod_edges_min2degrees)
mcmc.diagnostics(mod_edges_min3degrees)
set.seed(666)
mod_edges_2degrees_gof <- gof(mod_edges_2degrees,
control = control.gof.formula(nsim = 10))
plot(mod_edges_2degrees_gof)
set.seed(666)
mod_edges_3degrees_gof <- gof(mod_edges_3degrees,
control = control.gof.formula(nsim = 10))
plot(mod_edges_3degrees_gof)