Last updated: 2020-12-17
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 e196111. 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: data/~$cts_dat.xlsx
Unstaged changes:
Modified: analysis/3-network.Rmd
Modified: output/network_res.RDS
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 |
---|---|---|---|---|
Rmd | e196111 | bernard-liew | 2020-12-16 | augmented reporting |
Rmd | 8a9ca68 | bernard-liew | 2020-11-27 | fine tuned network analysis |
html | 8a9ca68 | bernard-liew | 2020-11-27 | fine tuned network analysis |
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,
arsenal,
flextable,
officer,
cowplot,
huge)
if (file.exists("output/network_res.RDS")) {
dat2 <- readRDS("output/network_res.RDS")
list2env(dat2 ,.GlobalEnv)
skip_eval <- TRUE
} else {
dat <- readRDS ("output/dat.RDS")
skip_eval <- FALSE
}
# Helper for nice descriptive table
meanNsd_transform <- function (x) {
m <- round (x[[1]][1], 2)
s <- round (x[[1]][2], 2)
m_s <- paste0(m, "(", s, ")")
return (m_s)
}
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")
}
dat_sub <- dat %>%
dplyr::select (age,
pain_years,
mean_pain_base,
ppt_medn_aff_base,
ppt_uln_aff_base,
ppt_radn_aff_base,
ppt_neck_aff_base,
ppt_cts_aff_base,
ppt_ta_aff_base,
cts_func_base,
cts_severe_base,
dep_base)
names (dat_sub) <- str_remove_all (names(dat_sub), "_base|mean_|_aff")
tab1 <- tableby ( ~. , data = dat_sub, digits = 2, digits.p = 2)
summary (tab1)
Overall (N=105) | |
---|---|
age | |
Mean (SD) | 46.82 (9.17) |
Range | 21.00 - 64.00 |
pain_years | |
Mean (SD) | 3.24 (2.91) |
Range | 0.50 - 18.00 |
pain | |
Mean (SD) | 5.02 (1.75) |
Range | 0.00 - 8.00 |
ppt_medn | |
Mean (SD) | 194.32 (54.39) |
Range | 82.00 - 333.00 |
ppt_uln | |
Mean (SD) | 299.30 (80.82) |
Range | 93.00 - 498.00 |
ppt_radn | |
Mean (SD) | 226.43 (64.02) |
Range | 89.00 - 458.00 |
ppt_neck | |
Mean (SD) | 172.20 (48.47) |
Range | 63.00 - 307.00 |
ppt_cts | |
Mean (SD) | 352.77 (113.98) |
Range | 127.00 - 652.00 |
ppt_ta | |
Mean (SD) | 325.20 (88.15) |
Range | 101.00 - 544.00 |
cts_func | |
Mean (SD) | 2.35 (0.57) |
Range | 1.12 - 4.25 |
cts_severe | |
Mean (SD) | 2.63 (0.66) |
Range | 1.27 - 5.00 |
dep | |
Mean (SD) | 3.84 (2.37) |
Range | 0.00 - 9.00 |
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)
wts_df %>%
mutate (weight_abs = abs (weight)) %>%
slice_max (weight_abs, n = 10)
# A tibble: 10 x 4
from to weight weight_abs
<dbl> <dbl> <dbl> <dbl>
1 2 4 0.34 0.34
2 8 10 0.3 0.3
3 6 7 0.290 0.290
4 8 9 0.25 0.25
5 3 7 0.24 0.24
6 5 7 0.23 0.23
7 2 6 0.2 0.2
8 1 9 0.2 0.2
9 4 5 0.19 0.19
10 2 3 0.18 0.18
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.
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.
The greater the value of centrality indices to one, the more important the variable.
centr <- centralityPlot(nw,
include = c("Strength", "Closeness", "Betweenness"),
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", plot = "area", order = "sample", CIstyle = "SE")
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 = c("strength", "closeness", "betweenness"))
dat2save <- list ("dat" = dat,
"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,
"Sim" = Sim)
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] huge_1.3.4.1 cowplot_1.1.0 officer_0.3.15 flextable_0.5.11
[5] arsenal_3.5.0 igraph_1.2.6 bootnet_1.4.3 qgraph_1.6.5
[9] forcats_0.5.0 stringr_1.4.0 dplyr_1.0.2 purrr_0.3.4
[13] readr_1.4.0 tidyr_1.1.2 tibble_3.0.4 ggplot2_3.3.2
[17] tidyverse_1.3.0 pacman_0.5.1
loaded via a namespace (and not attached):
[1] utf8_1.1.4 R.utils_2.10.1 tidyselect_1.1.0
[4] htmlwidgets_1.5.2 grid_3.6.0 munsell_0.5.0
[7] codetools_0.2-18 withr_2.3.0 colorspace_2.0-0
[10] NetworkToolbox_1.4.0 highr_0.8 knitr_1.30
[13] uuid_0.1-4 rstudioapi_0.13 stats4_3.6.0
[16] labeling_0.4.2 git2r_0.27.1 mnormt_2.0.2
[19] farver_2.0.3 rprojroot_2.0.2 vctrs_0.3.5
[22] generics_0.1.0 xfun_0.19 R6_2.5.0
[25] doParallel_1.0.16 smacof_2.1-1 assertthat_0.2.1
[28] promises_1.1.1 scales_1.1.1 nnet_7.3-14
[31] gtable_0.3.0 weights_1.0.1 workflowr_1.6.2
[34] rlang_0.4.8 systemfonts_0.3.2 splines_3.6.0
[37] wordcloud_2.6 broom_0.7.2 checkmate_2.0.0
[40] yaml_2.2.1 reshape2_1.4.4 abind_1.4-5
[43] modelr_0.1.8 d3Network_0.5.2.1 backports_1.2.0
[46] httpuv_1.5.4 Hmisc_4.4-1 tools_3.6.0
[49] psych_2.0.9 lavaan_0.6-7 ellipsis_0.3.1
[52] RColorBrewer_1.1-2 polynom_1.4-0 Rcpp_1.0.5
[55] plyr_1.8.6 base64enc_0.1-3 rpart_4.1-15
[58] pbapply_1.4-3 haven_2.3.1 cluster_2.1.0
[61] fs_1.5.0 survey_4.0 magrittr_2.0.1
[64] data.table_1.13.2 openxlsx_4.2.3 reprex_0.3.0
[67] tmvnsim_1.0-2 mvtnorm_1.1-1 matrixcalc_1.0-3
[70] whisker_0.4 hms_0.5.3 evaluate_0.14
[73] rio_0.5.16 jpeg_0.1-8.1 readxl_1.3.1
[76] gridExtra_2.3 shape_1.4.5 compiler_3.6.0
[79] ellipse_0.4.2 mice_3.12.0 crayon_1.3.4
[82] R.oo_1.24.0 htmltools_0.5.0 corpcor_1.6.9
[85] later_1.1.0.1 Formula_1.2-4 lubridate_1.7.9.2
[88] DBI_1.1.0 relaimpo_2.2-3 mgm_1.2-10
[91] dbplyr_2.0.0 MASS_7.3-53 boot_1.3-25
[94] IsingSampler_0.2.1 Matrix_1.2-18 IsingFit_0.3.1
[97] car_3.0-10 cli_2.2.0 heplots_1.3-7
[100] mitools_2.4 R.methodsS3_1.8.1 gdata_2.18.0
[103] parallel_3.6.0 BDgraph_2.63 pkgconfig_2.0.3
[106] foreign_0.8-71 xml2_1.3.2 foreach_1.5.1
[109] pbivnorm_0.6.0 rvest_0.3.6 digest_0.6.27
[112] rmarkdown_2.5 cellranger_1.1.0 htmlTable_2.1.0
[115] gdtools_0.2.2 curl_4.3 gtools_3.8.2
[118] rjson_0.2.20 lifecycle_0.2.0 nlme_3.1-150
[121] glasso_1.11 jsonlite_1.7.1 carData_3.0-4
[124] fansi_0.4.1 pillar_1.4.7 lattice_0.20-41
[127] httr_1.4.2 plotrix_3.7-8 survival_3.2-7
[130] glue_1.4.2 networktools_1.2.3 zip_2.1.1
[133] fdrtool_1.2.15 png_0.1-7 iterators_1.0.13
[136] candisc_0.8-3 glmnet_4.0-2 class_7.3-17
[139] stringi_1.4.6 nnls_1.4 latticeExtra_0.6-29
[142] eigenmodel_1.11 e1071_1.7-4