Last updated: 2020-11-27
Checks: 6 1
Knit directory: 2020_cts_bn/
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(20200907)
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 c142098. 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/
Untracked files:
Untracked: output/bn_data.RData
Untracked: output/network_res.RDS
Unstaged changes:
Modified: analysis/3-network.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-network.Rmd
) and HTML (docs/3-network.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 |
---|---|---|---|---|
html | c142098 | bernard-liew | 2020-11-23 | Build site. |
Rmd | 2266d36 | bernard-liew | 2020-11-23 | added explanation to graphs |
html | a6948ce | bernard-liew | 2020-10-26 | initial analysis |
Rmd | 89af6df | bernard-liew | 2020-10-26 | initial commit |
Rmd | fe17d91 | bernard-liew | 2020-10-26 | initial 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,
mgm,
cowplot,
huge,
EGAnet)
if (file.exists("output/network_res.RDS")) {
dat <- readRDS("output/network_res.RDS")
list2env(dat ,.GlobalEnv)
skip_eval <- TRUE
} else {
dat <- readRDS ("output/dat.RDS")
skip_eval <- FALSE
}
if (skip_eval == FALSE) {
dat <- dat %>%
mutate (ppt_medn = (ppt_medn_aff_base + ppt_medn_naff_base)/2,
ppt_uln = (ppt_uln_aff_base + ppt_uln_naff_base)/2,
ppt_radn = (ppt_radn_aff_base + ppt_radn_naff_base)/2,
ppt_neck = (ppt_neck_aff_base + ppt_neck_naff_base)/2,
ppt_cts = (ppt_cts_aff_base + ppt_cts_naff_base)/2,
ppt_ta = (ppt_ta_aff_base + ppt_ta_naff_base)/2) %>%
select (-c(ppt_medn_aff_base:ppt_ta_naff_base))
}
if (skip_eval == FALSE) {
dat_base <- dat[, !grepl ("naff.*base", names (dat))]
dat_base <- dat_base[, grepl ("aff|base", names (dat_base))]
dat_base <- dat_base %>%
select (-worst_pain_base, - aff_side) %>%
rename (func = cts_func_base,
severity = cts_severe_base)
names (dat_base) <- str_remove_all (names(dat_base), "_base|mean_|_aff")
node_labs <- names(dat_base)
names(dat_base) <- paste0("V", 1:ncol(dat_base))
dat_base %>%
pivot_longer(cols = everything (),
names_to = "var",
values_to = "val") %>%
ggplot () +
geom_histogram (aes (val)) +
facet_wrap (~ var, ncol = 5, scales = "free_x")
}
if (skip_eval == FALSE) {
df <- dat_base
df <- huge.npn (df)
set.seed (1)
nw <- estimateNetwork(df,
default="EBICglasso",
corMethod = "cor",
tuning = 0.5,
lambda.min.ratio = 0.001,
corArgs =
list(method = "pearson",
use = "pairwise.complete.obs"))
}
Arcs in blue means a positive correlation between connecting variables.
Arcs in red means a netative correlation between connecting variables.
Thickness of arcs gives you a qualitative indication of correlation magnitude.
nw_plot <- plot (nw, nodeNames = node_labs, layout = "spring", legend = TRUE)
wts_df <- nw_plot$Edgelist %>%
bind_cols() %>%
select (from, to, weight) %>%
mutate_all (round, 2)
Reference for definition: Robinaugh, D. J., Millner, A. J., & McNally, R. J. (2016). Identifying highly influential nodes in the complicated grief network. Journal of Abnormal Psychology, 125(6), 747–757. doi:10.1037/abn0000181
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.
centr <- centralityPlot(nw,
include = "all",
scale = "relative",
labels = node_labs)
Note: relative centrality indices are shown on x-axis rather than raw centrality indices.
if (skip_eval == FALSE) {
edge_wts <- bootnet(nw,
nBoots = 2000,
nCores = 6,
statistics = "edge")
}
plot (edge_wts, satistics = "edge", order = "sample")
plot (edge_wts, plot = "difference", satistics = "edge", order = "sample", onlyNonZero = TRUE)
Expected significance level given number of bootstrap samples is approximately: 0.05
if (skip_eval == FALSE) {
stats2boot <- c("edge", "strength", "expectedInfluence", "closeness", "betweenness")
centr_stb <- bootnet(nw,
nBoots = 2000,
nCores = 6,
statistics = stats2boot,
type = "case")
cor_stb <- corStability (centr_stb)
}
plot (centr_stb, statistics = stats2boot[-1])
dat2save <- list ("df" = df,
"nw" = nw,
"nw_plot" = nw_plot,
"centr" = centr,
"centr_stb" = centr_stb,
"edge_wts" = edge_wts,
"cor_stb" = cor_stb,
"node_labs" = node_labs,
"stats2boot" = stats2boot
)
saveRDS(dat2save,
"output/network_res.RDS")
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] stats graphics grDevices utils datasets methods base
other attached packages:
[1] EGAnet_0.9.6 huge_1.3.4.1 cowplot_1.0.0 mgm_1.2-10
[5] igraph_1.2.4.2 bootnet_1.4.3 qgraph_1.6.5 forcats_0.4.0
[9] stringr_1.4.0 dplyr_1.0.2 purrr_0.3.3 readr_1.3.1
[13] tidyr_1.0.2 tibble_3.0.3 ggplot2_3.3.2 tidyverse_1.3.0
[17] pacman_0.5.1
loaded via a namespace (and not attached):
[1] readxl_1.3.1 backports_1.1.4 Hmisc_4.2-0
[4] BDgraph_2.63 workflowr_1.6.2 plyr_1.8.4
[7] splines_3.6.0 candisc_0.8-3 digest_0.6.19
[10] foreach_1.4.4 htmltools_0.4.0 matrixcalc_1.0-3
[13] gdata_2.18.0 fansi_0.4.0 magrittr_1.5
[16] checkmate_1.9.3 doParallel_1.0.15 cluster_2.0.9
[19] openxlsx_4.1.4 modelr_0.1.5 wordcloud_2.6
[22] R.utils_2.8.0 jpeg_0.1-8 colorspace_1.4-1
[25] blob_1.2.1 rvest_0.3.5 mitools_2.4
[28] haven_2.2.0 pan_1.6 xfun_0.7
[31] crayon_1.3.4 jsonlite_1.7.1 networktools_1.2.3
[34] lme4_1.1-21 survival_2.44-1.1 iterators_1.0.10
[37] glue_1.4.2 relaimpo_2.2-3 gtable_0.3.0
[40] NetworkToolbox_1.4.0 nnls_1.4 car_3.0-2
[43] weights_1.0.1 shape_1.4.4 jomo_2.6-7
[46] abind_1.4-5 scales_1.1.1 mvtnorm_1.0-10
[49] DBI_1.0.0 Rcpp_1.0.2 plotrix_3.7-5
[52] htmlTable_1.13.1 foreign_0.8-71 Formula_1.2-3
[55] survey_3.36 heplots_1.3-5 stats4_3.6.0
[58] glmnet_3.0-1 htmlwidgets_1.5.1 httr_1.4.1
[61] RColorBrewer_1.1-2 lavaan_0.6-5 acepack_1.4.1
[64] ellipsis_0.3.0 IsingFit_0.3.1 mice_3.7.0
[67] farver_2.0.3 pkgconfig_2.0.2 R.methodsS3_1.7.1
[70] nnet_7.3-12 dbplyr_1.4.4 labeling_0.3
[73] tidyselect_1.1.0 rlang_0.4.7 reshape2_1.4.3
[76] later_0.8.0 polynom_1.4-0 munsell_0.5.0
[79] cellranger_1.1.0 tools_3.6.0 cli_2.0.1
[82] generics_0.0.2 IsingSampler_0.2.1 broom_0.5.4
[85] fdrtool_1.2.15 evaluate_0.14 yaml_2.2.0
[88] knitr_1.27 fs_1.3.0 zip_2.0.4
[91] mitml_0.3-7 glasso_1.11 pbapply_1.4-0
[94] nlme_3.1-139 whisker_0.3-2 R.oo_1.22.0
[97] smacof_2.1-1 xml2_1.2.2 compiler_3.6.0
[100] rstudioapi_0.11 curl_4.3 png_0.1-7
[103] e1071_1.7-1 reprex_0.3.0 pbivnorm_0.6.0
[106] stringi_1.4.3 eigenmodel_1.11 lattice_0.20-38
[109] Matrix_1.2-17 psych_1.8.12 nloptr_1.2.1
[112] vctrs_0.3.4 pillar_1.4.3 lifecycle_0.2.0
[115] data.table_1.12.8 corpcor_1.6.9 httpuv_1.5.2
[118] R6_2.4.0 latticeExtra_0.6-28 promises_1.0.1
[121] rio_0.5.16 gridExtra_2.3 codetools_0.2-16
[124] boot_1.3-22 MASS_7.3-51.4 gtools_3.8.1
[127] assertthat_0.2.1 rprojroot_1.3-2 rjson_0.2.20
[130] withr_2.1.2 mnormt_1.5-5 parallel_3.6.0
[133] hms_0.5.3 grid_3.6.0 rpart_4.1-15
[136] class_7.3-15 minqa_1.2.4 rmarkdown_2.3
[139] carData_3.0-2 git2r_0.27.1 d3Network_0.5.2.1
[142] lubridate_1.7.4 base64enc_0.1-3 ellipse_0.4.1