-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_BL_nw.R
80 lines (64 loc) · 2.62 KB
/
10_BL_nw.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
load("data/data_class.RData")
colnames(d)
library(tidyverse)
d <- d %>% select(2:4,6:9,66) %>%
mutate(sex = as.numeric(sex),
age_cat = as.numeric(age_cat),
education_cat = as.numeric(education_cat),
choice_of_party = as.numeric(choice_of_party),
marstat = as.numeric(marstat),
household = as.numeric(household),
class = as.numeric(class))
d <- data.frame(d)
blacklist <- readxl::read_excel("data/from_to_blacklist_covid_DE_cl.xlsx")
bl_mat <- as.matrix(blacklist)
library(parallel)
cl <- makeCluster(7)
library(bnlearn)
set.seed(666)
bn_op <- tabu(d, blacklist = bl_mat)
library(qgraph)
qgraph(bn_op, vsize = 15, label.cex = 3)
set.seed(666)
boot_res <- boot.strength(data = d,
R = 10000,
algorithm = "tabu",
algorithm.args = list(blacklist = bl_mat),
cluster = cl)
avgnet_threshold <- averaged.network(boot_res, threshold = .975)
Labels <- c("Gender", "Age Group", "Education Level",
"Party Choice", "Political Orientation",
"Marital Status", "# of People in Household",
"Latent Class")
qgraph(avgnet_threshold, vsize = 15, label.cex = 3, labels = Labels,
title = "Bayesian Belief Network Explaining the Mechanism for Voting Intention with Latent Class")
gdata::keep(cl, sure = T)
load("data/data_profile.RData")
colnames(d)
d <- d %>% select(2:4,6:9,42) %>%
mutate(sex = as.numeric(sex),
age_cat = as.numeric(age_cat),
education_cat = as.numeric(education_cat),
choice_of_party = as.numeric(choice_of_party),
marstat = as.numeric(marstat),
household = as.numeric(household),
profile = as.numeric(profile))
d <- data.frame(d)
blacklist <- readxl::read_excel("data/from_to_blacklist_covid_DE_pr.xlsx")
bl_mat <- as.matrix(blacklist)
set.seed(666)
bn_op <- tabu(d, blacklist = bl_mat)
qgraph(bn_op, vsize = 15, label.cex = 3)
set.seed(666)
boot_res <- boot.strength(data = d,
R = 10000,
algorithm = "tabu",
algorithm.args = list(blacklist = bl_mat),
cluster = cl)
avgnet_threshold <- averaged.network(boot_res, threshold = .975)
Labels <- c("Gender", "Age Group", "Education Level",
"Party Choice", "Political Orientation",
"Marital Status", "# of People in Household",
"Latent Profile")
qgraph(avgnet_threshold, vsize = 15, label.cex = 3, labels = Labels,
title = "Bayesian Belief Network Explaining the Mechanism for Voting Intention with Latent Profile")