Last updated: 2020-12-01
Checks: 6 1
Knit directory: 2020_ODI_network/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20201008) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version 035fa50. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Unstaged changes:
Modified: analysis/3-report.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/3-report.Rmd) and HTML (docs/3-report.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.
| File | Version | Author | Date | Message |
|---|---|---|---|---|
| Rmd | 035fa50 | bernard-liew | 2020-11-30 | altered report graphics size |
| html | 035fa50 | bernard-liew | 2020-11-30 | altered report graphics size |
| html | 8bd4b9a | bernard-liew | 2020-11-04 | Build site. |
| Rmd | 502ad53 | bernard-liew | 2020-11-04 | build contents for web |
| html | 502ad53 | bernard-liew | 2020-11-04 | build contents for web |
| Rmd | 9e388e3 | Liew | 2020-11-03 | tidied reporting |
| Rmd | 5f1623a | bernard-liew | 2020-10-13 | initial network analysis |
if (!require("pacman")) install.packages("pacman")
Loading required package: pacman
Warning: package 'pacman' was built under R version 3.6.1
pacman::p_load(tidyverse,
qgraph,
stats,
bootnet,
igraph,
plotrix,
mgm,
NetworkComparisonTest,
rio,
furrr,
cowplot,
doParallel,
huge,
EGAnet)
# ODI custom figure
nodeLabels <- c("Pain Intensity", "Personal Care", "Lifting", "Walking", "Sitting",
"Standing", "Sleeping", "Social life", "Travelling", "Work/Housework")
ques <- paste0("Q", 1:10)
node_df <- data.frame("Item" = ques,
"Variable" = nodeLabels)
# Model with missing data as input
res <- readRDS("output/raw.RDS")
# Model with complete imputed data as input
#res <- readRDS("output/com.RDS")
Blue edges - positive correlation
Red edges - negative correlation
The thickness of the edges indicate the magnitude of correlation.
#tiff(width = 15, height = 15, units = "in", res = 100, file = "output/odi_network.tiff")
par (mfrow = c(2,3))
p1 <- plot (res$nw[[1]], title = "Baseline", label.cex = 1.5, vsize = 10)
plot (res$nw[[2]], title = "Week 5", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot (res$nw[[3]], title = "Week 10", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot (res$nw[[4]], title = "Week 26", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot (res$nw[[5]], title = "Week 52", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot.new()
addtable2plot(0,0,node_df,
xpad=1, ypad=1,
bty='o',
display.rownames = FALSE,
hlines = TRUE,
vlines = TRUE)

#dev.off()
See which edges differ from each other in size significantly (to answer the question is edge A significantly larger than edge B).
w_fig <- map (res$edgewts, plot, order = "sample")
w_fig <- map (w_fig, ~.x +
theme(text = element_text(size = 16)),
include = "all", print = FALSE, scale = "relative")
cowplot::plot_grid(plotlist = w_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = -1, ncol = 1)

wp_fig <- map (res$edgewts, plot, plot = "difference",
satistics = "edge", order = "sample", onlyNonZero = TRUE)
wp_fig <- map (wp_fig, ~.x +
theme(text = element_text(size = 16)),
include = "all", print = FALSE, scale = "relative")
cowplot::plot_grid(plotlist = wp_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = -1, ncol = 3)

High centrality nodes have strong connections to many other nodes, and act as hubs that connect otherwise disparate nodes to one another.
Low centrality nodes exist on the periphery of the network, with fewer and weaker connections to other nodes of the network.
Strength is the sum of the absolute value of its connections with other nodes in the network.
Degree can be straightforwardly generalized to weighted networks by considering the sum of the weights of the connections (in absolute value), instead of their number. This generalization is called strength.
Closeness centrality is defined as the inverse of the sum of the distances of the focal node from all the other nodes in the network. Closeness is the average shortest path between a given node and the remaining nodes in the network. Nodes with higher closeness are more proximally connected to the rest of the network.
Betweenness is the number of times in which a given node lies on the shortest path between two other nodes.
Expected influence is the sum of a node’s connections and represents the relative importance of a node in a network (Robinaugh et al., 2016) –relative because even in weakly connected networks (with overall low edge weights), there will always be a node with a high expected influence in case of standardized results.
The greater the value of centrality indices to one, the more important the variable.
# Plot centrality
c_fig <- map (res$nw, centralityPlot, include = "all", print = FALSE, scale = "relative")
c_fig <- map (c_fig, ~.x +
scale_x_continuous(breaks= c(0, 0.5, 1), lim = c(0, 1)) +
theme(text = element_text(size = 20),
axis.text.x = element_text(angle = 90, hjust = 1)),
include = "all", print = FALSE, scale = "relative")
#tiff(width = 15, height = 15, units = "in", res = 100, file = "output/odi_strength.tiff")
cowplot::plot_grid(plotlist = c_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = 0, ncol = 2)

#dev.off()
Is the centrality order stable?
# Plot centrality stability
s_fig <- map (res$centr_stb, plot, statistics = c("closeness", "strength", "betweenness"))
s_fig <- map (s_fig, ~.x +
ylab ("Ave Corr") +
theme(text = element_text(size = 20),
axis.text.x = element_text(angle = 90, hjust = 1)),
include = "all", print = FALSE, scale = "relative")
#tiff(width = 15, height = 15, units = "in", res = 100, file = "output/odi_stability.tiff")
cowplot::plot_grid(plotlist = s_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = -1, ncol = 2)

#dev.off()
The stability of centrality estimation, and results in a centrality-stability coefficient (CS-coefficient) that should not be lower than 0.25 and preferably above 0.5
cs_coef <- res %>%
select (time, cor_stb) %>%
unnest () %>%
ungroup() %>%
mutate (measure = rep (c("betweenness", "closeness", "edge", "expectedInfluence", "strength"), 5)) %>%
mutate (cor_stb = round (cor_stb, 2))
cs_coef %>%
knitr::kable (caption = "Stability of centrality indices")
| time | cor_stb | measure |
|---|---|---|
| 0 | 0.28 | betweenness |
| 0 | 0.44 | closeness |
| 0 | 0.59 | edge |
| 0 | 0.59 | expectedInfluence |
| 0 | 0.59 | strength |
| 5 | 0.21 | betweenness |
| 5 | 0.36 | closeness |
| 5 | 0.59 | edge |
| 5 | 0.67 | expectedInfluence |
| 5 | 0.59 | strength |
| 10 | 0.00 | betweenness |
| 10 | 0.13 | closeness |
| 10 | 0.52 | edge |
| 10 | 0.59 | expectedInfluence |
| 10 | 0.44 | strength |
| 26 | 0.00 | betweenness |
| 26 | 0.21 | closeness |
| 26 | 0.44 | edge |
| 26 | 0.67 | expectedInfluence |
| 26 | 0.21 | strength |
| 52 | 0.05 | betweenness |
| 52 | 0.21 | closeness |
| 52 | 0.44 | edge |
| 52 | 0.44 | expectedInfluence |
| 52 | 0.13 | strength |
Individualised PT coded as 1.
Advise coded as 0.
# Model with missing data as input
res <- readRDS("output/mgm_raw.RDS")
# Model with complete imputed data as input
#res <- readRDS("output/com.RDS")
nodes <- colnames (res$data[[1]])
Blue edges - positive correlation
Red edges - negative correlation
The thickness of the edges indicate the magnitude of correlation.
#tiff(width = 15, height = 15, units = "in", res = 100, file = "output/odi_network.tiff")
par (mfrow = c(2,3))
p1 <- plot (res$nw[[1]], title = "Baseline", label.cex = 1.5, vsize = 10)
plot (res$nw[[2]], title = "Week 5", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot (res$nw[[3]], title = "Week 10", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot (res$nw[[4]], title = "Week 26", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot (res$nw[[5]], title = "Week 52", layout = p1$layout, label.cex = 1.5, vsize = 10)
plot.new()
addtable2plot(0,0,node_df,
xpad=1, ypad=1,
bty='o',
display.rownames = FALSE,
hlines = TRUE,
vlines = TRUE)

#dev.off()
See which edges differ from each other in size significantly (to answer the question is edge A significantly larger than edge B).
w_fig <- map (res$edgewts, plot, order = "sample")
w_fig <- map (w_fig, ~.x +
theme(text = element_text(size = 16)),
include = "all", print = FALSE, scale = "relative")
cowplot::plot_grid(plotlist = w_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = -1, ncol = 1)

wp_fig <- map (res$edgewts, plot, plot = "difference",
satistics = "edge", order = "sample", onlyNonZero = TRUE)
wp_fig <- map (wp_fig, ~.x +
theme(text = element_text(size = 16)),
include = "all", print = FALSE, scale = "relative")
cowplot::plot_grid(plotlist = wp_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = -1, ncol = 3)

High centrality nodes have strong connections to many other nodes, and act as hubs that connect otherwise disparate nodes to one another.
Low centrality nodes exist on the periphery of the network, with fewer and weaker connections to other nodes of the network.
Strength is the sum of the absolute value of its connections with other nodes in the network.
Degree can be straightforwardly generalized to weighted networks by considering the sum of the weights of the connections (in absolute value), instead of their number. This generalization is called strength.
Closeness centrality is defined as the inverse of the sum of the distances of the focal node from all the other nodes in the network. Closeness is the average shortest path between a given node and the remaining nodes in the network. Nodes with higher closeness are more proximally connected to the rest of the network.
Betweenness is the number of times in which a given node lies on the shortest path between two other nodes.
Expected influence is the sum of a node’s connections and represents the relative importance of a node in a network (Robinaugh et al., 2016) –relative because even in weakly connected networks (with overall low edge weights), there will always be a node with a high expected influence in case of standardized results.
The greater the value of centrality indices to one, the more important the variable.
# Plot centrality
c_fig <- map (res$nw, centralityPlot, include = "all",
print = FALSE, scale = "relative", labels = nodes) %>%
map (~.x +
scale_x_continuous(breaks= c(0, 0.5, 1), lim = c(0, 1)) +
theme(text = element_text(size = 20),
axis.text.x = element_text(angle = 90, hjust = 1)),
include = "all", print = FALSE, scale = "relative")
#tiff(width = 15, height = 15, units = "in", res = 100, file = "output/odi_strength.tiff")
cowplot::plot_grid(plotlist = c_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = 0, ncol = 2)

#dev.off()
Is the centrality order stable?
# Plot centrality stability
s_fig <- map (res$centr_stb, plot, statistics = c("closeness", "strength", "betweenness"))
s_fig <- map (s_fig, ~.x +
ylab ("Ave Corr") +
theme(text = element_text(size = 20),
axis.text.x = element_text(angle = 90, hjust = 1)),
include = "all", print = FALSE, scale = "relative")
#tiff(width = 15, height = 15, units = "in", res = 100, file = "output/odi_stability.tiff")
cowplot::plot_grid(plotlist = s_fig, labels = c("Wk0","Wk 5", "Wk 10", "Wk 26", "wk52" ), vjust = 1, hjust = -1, ncol = 2)

#dev.off()
The stability of centrality estimation, and results in a centrality-stability coefficient (CS-coefficient) that should not be lower than 0.25 and preferably above 0.5
cs_coef <- res %>%
select (time, cor_stb) %>%
unnest () %>%
ungroup() %>%
mutate (measure = rep (c("betweenness", "closeness", "edge", "expectedInfluence", "strength"), 5)) %>%
mutate (cor_stb = round (cor_stb, 2))
cs_coef %>%
knitr::kable (caption = "Stability of centrality indices")
| time | cor_stb | measure |
|---|---|---|
| 0 | 0.00 | betweenness |
| 0 | 0.00 | closeness |
| 0 | 0.59 | edge |
| 0 | 0.67 | expectedInfluence |
| 0 | 0.59 | strength |
| 5 | 0.21 | betweenness |
| 5 | 0.21 | closeness |
| 5 | 0.59 | edge |
| 5 | 0.67 | expectedInfluence |
| 5 | 0.28 | strength |
| 10 | 0.05 | betweenness |
| 10 | 0.13 | closeness |
| 10 | 0.52 | edge |
| 10 | 0.75 | expectedInfluence |
| 10 | 0.28 | strength |
| 26 | 0.05 | betweenness |
| 26 | 0.28 | closeness |
| 26 | 0.52 | edge |
| 26 | 0.75 | expectedInfluence |
| 26 | 0.44 | strength |
| 52 | 0.00 | betweenness |
| 52 | 0.00 | closeness |
| 52 | 0.52 | edge |
| 52 | 0.75 | expectedInfluence |
| 52 | 0.59 | strength |
sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] EGAnet_0.9.6 huge_1.3.4.1
[3] doParallel_1.0.16 iterators_1.0.13
[5] foreach_1.5.1 cowplot_1.1.0
[7] furrr_0.2.1 future_1.20.1
[9] rio_0.5.16 NetworkComparisonTest_2.2.1
[11] mgm_1.2-10 plotrix_3.7-8
[13] igraph_1.2.6 bootnet_1.4.3
[15] qgraph_1.6.5 forcats_0.5.0
[17] stringr_1.4.0 dplyr_1.0.2
[19] purrr_0.3.4 readr_1.4.0
[21] tidyr_1.1.2 tibble_3.0.4
[23] ggplot2_3.3.2 tidyverse_1.3.0
[25] pacman_0.5.1
loaded via a namespace (and not attached):
[1] R.utils_2.10.1 tidyselect_1.1.0 htmlwidgets_1.5.2
[4] grid_3.6.0 munsell_0.5.0 codetools_0.2-18
[7] withr_2.3.0 colorspace_2.0-0 NetworkToolbox_1.4.0
[10] highr_0.8 knitr_1.30 rstudioapi_0.13
[13] stats4_3.6.0 listenv_0.8.0 labeling_0.4.2
[16] git2r_0.27.1 mnormt_2.0.2 farver_2.0.3
[19] rprojroot_2.0.2 parallelly_1.21.0 vctrs_0.3.5
[22] generics_0.1.0 xfun_0.19 R6_2.5.0
[25] smacof_2.1-1 assertthat_0.2.1 promises_1.1.1
[28] scales_1.1.1 nnet_7.3-14 gtable_0.3.0
[31] globals_0.14.0 weights_1.0.1 workflowr_1.6.2
[34] rlang_0.4.8 splines_3.6.0 wordcloud_2.6
[37] broom_0.7.2 checkmate_2.0.0 yaml_2.2.1
[40] reshape2_1.4.4 abind_1.4-5 modelr_0.1.8
[43] d3Network_0.5.2.1 backports_1.2.0 httpuv_1.5.4
[46] Hmisc_4.4-1 tools_3.6.0 psych_2.0.9
[49] lavaan_0.6-7 ellipsis_0.3.1 RColorBrewer_1.1-2
[52] polynom_1.4-0 Rcpp_1.0.5 plyr_1.8.6
[55] base64enc_0.1-3 rpart_4.1-15 pbapply_1.4-3
[58] haven_2.3.1 cluster_2.1.0 fs_1.5.0
[61] survey_4.0 magrittr_2.0.1 data.table_1.13.2
[64] openxlsx_4.2.3 reprex_0.3.0 tmvnsim_1.0-2
[67] mvtnorm_1.1-1 matrixcalc_1.0-3 whisker_0.4
[70] hms_0.5.3 evaluate_0.14 jpeg_0.1-8.1
[73] readxl_1.3.1 gridExtra_2.3 shape_1.4.5
[76] compiler_3.6.0 ellipse_0.4.2 mice_3.12.0
[79] crayon_1.3.4 R.oo_1.24.0 htmltools_0.5.0
[82] corpcor_1.6.9 later_1.1.0.1 Formula_1.2-4
[85] lubridate_1.7.9.2 DBI_1.1.0 relaimpo_2.2-3
[88] dbplyr_2.0.0 MASS_7.3-53 boot_1.3-25
[91] IsingSampler_0.2.1 Matrix_1.2-18 IsingFit_0.3.1
[94] car_3.0-10 cli_2.2.0 heplots_1.3-7
[97] mitools_2.4 R.methodsS3_1.8.1 gdata_2.18.0
[100] BDgraph_2.63 pkgconfig_2.0.3 foreign_0.8-71
[103] xml2_1.3.2 pbivnorm_0.6.0 rvest_0.3.6
[106] digest_0.6.27 rmarkdown_2.5 cellranger_1.1.0
[109] htmlTable_2.1.0 curl_4.3 gtools_3.8.2
[112] rjson_0.2.20 lifecycle_0.2.0 nlme_3.1-150
[115] glasso_1.11 jsonlite_1.7.1 carData_3.0-4
[118] fansi_0.4.1 pillar_1.4.7 lattice_0.20-41
[121] httr_1.4.2 survival_3.2-7 glue_1.4.2
[124] networktools_1.2.3 zip_2.1.1 fdrtool_1.2.15
[127] png_0.1-7 candisc_0.8-3 glmnet_4.0-2
[130] class_7.3-17 stringi_1.4.6 nnls_1.4
[133] latticeExtra_0.6-29 eigenmodel_1.11 e1071_1.7-4