Lecture causality - r assignment
3 important questions on Lecture causality - r assignment
How can you fit a network model using the mgm package?
library(mgm)
library(qgraph)
# fit a network. type indicates what variables there are, categorical poisson and gaussian.
# levels indicate how many groups there are (only relevant for categorical variables)
my_mgm <- mgm(data = as.matrix(dat_1), type = c("c", "p", "g"), level = c(2,1,1))
qgraph(my_mgm$pairwise$wadj, labels = colnames(dat_1), edge.color = my_mgm$pairwise$edgecolor)
the resulting network is a regularized network of partial correlations, some edges thus do not show up because they're not strong enough.
How can you make a bayesian directed network with the pc algorithm in r?
library(bnlearn)
#pc.stable does not accept integers, change the variables to numbers.
dat_1$week12 <- as.numeric(dat_1$week12)
dat_1$CSsum <- as.numeric(dat_1$CSsum)
bnpc <- bnlearn::pc.stable(dat_1)
qgraph(bnpc)
What is blacklisting and how can you do it in r?
blacklisting is telling the algorithm to not make the connection stated in the blacklist argument. It is then forced to find an alternative model.
bnpc_bl <- pc.stable(dat_1, blacklist = data.frame("from" = "week12", "to" = "CSsum"))
qgraph(bnpc_bl)
The question on the page originate from the summary of the following study material:
- A unique study and practice tool
- Never study anything twice again
- Get the grades you hope for
- 100% sure, 100% understanding