-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test.centrality only returns results for nodes[1] when multiple nodes are requested #37
Comments
Thanks for reporting the issue! Would it be possible to post a minimal code example that replicates the problem?
A PR would be very welcome! As you might have read in #32 (comment), there will be a few more things on our to-do list before we can merge your PR.
Yes, that's probably better. |
A reprex output is on the bottom of this post, hope it helps. The problem is that the test.centrality section ignores which nodes have been given, and instead always selects the first, second, third, and so on, nodes in colnames(data). This behaviour can be confirmed by comparing the results of centrality tests with nodes = "all" and nodes = c("n1", "n2", ...).
I'll submit a PR of it once #32 is merged, thanks! # Minimal code for reproducing issue #37 in NCT
# See more: https://github.com/cvborkulo/NetworkComparisonTest/issues/37
library("NetworkComparisonTest")
library("psych")
library("dplyr")
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
set.seed(12345)
sessionInfo()
#> R version 4.3.0 (2023-04-21 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#>
#> Matrix products: default
#>
#>
#> locale:
#> [1] LC_COLLATE=English_Finland.utf8 LC_CTYPE=English_Finland.utf8
#> [3] LC_MONETARY=English_Finland.utf8 LC_NUMERIC=C
#> [5] LC_TIME=English_Finland.utf8
#>
#> time zone: Europe/Kiev
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] dplyr_1.1.2 psych_2.3.3
#> [3] NetworkComparisonTest_2.2.1
#>
#> loaded via a namespace (and not attached):
#> [1] shape_1.4.6 gtable_0.3.3 xfun_0.39 ggplot2_3.4.2
#> [5] htmlwidgets_1.6.2 lattice_0.21-8 quadprog_1.5-8 vctrs_0.6.2
#> [9] tools_4.3.0 generics_0.1.3 stats4_4.3.0 parallel_4.3.0
#> [13] tibble_3.2.1 fansi_1.0.4 cluster_2.1.4 pkgconfig_2.0.3
#> [17] qgraph_1.9.5 Matrix_1.5-4.1 data.table_1.14.8 checkmate_2.2.0
#> [21] lifecycle_1.0.3 compiler_4.3.0 stringr_1.5.0 munsell_0.5.0
#> [25] mnormt_2.1.1 IsingFit_0.3.1 codetools_0.2-19 htmltools_0.5.5
#> [29] glasso_1.11 glmnet_4.1-7 fdrtool_1.2.17 yaml_2.3.7
#> [33] htmlTable_2.4.1 Formula_1.2-5 pillar_1.9.0 IsingSampler_0.2.1
#> [37] iterators_1.0.14 Hmisc_5.1-0 foreach_1.5.2 rpart_4.1.19
#> [41] abind_1.4-5 nlme_3.1-162 lavaan_0.6-15 gtools_3.9.4
#> [45] tidyselect_1.2.0 digest_0.6.31 stringi_1.7.12 reshape2_1.4.4
#> [49] splines_4.3.0 fastmap_1.1.1 grid_4.3.0 colorspace_2.1-0
#> [53] cli_3.6.1 magrittr_2.0.3 base64enc_0.1-3 survival_3.5-5
#> [57] utf8_1.2.3 pbivnorm_0.6.0 foreign_0.8-84 corpcor_1.6.10
#> [61] withr_2.5.0 scales_1.2.1 backports_1.4.1 rmarkdown_2.21
#> [65] jpeg_0.1-10 igraph_1.4.2 nnet_7.3-19 gridExtra_2.3
#> [69] png_0.1-8 pbapply_1.7-0 evaluate_0.21 knitr_1.42
#> [73] rlang_1.1.1 Rcpp_1.0.10 glue_1.6.2 reprex_2.0.2
#> [77] rstudioapi_0.14 R6_2.5.1 plyr_1.8.8 fs_1.6.2
data(bfi)
data1 <- bfi %>%
dplyr::filter(gender == 1) %>%
dplyr::select(1:25) %>%
na.omit()
data2 <- bfi %>%
dplyr::filter(gender == 2) %>%
dplyr::select(1:25) %>%
na.omit()
ResultSelect <- NCT(data1, data2,
test.centrality = TRUE,
nodes = c("A1", "A3"),
progressbar = FALSE)
ResultSelect2 <- NCT(data1, data2,
test.centrality = TRUE,
nodes = c("C2", "E1"),
progressbar = FALSE)
ResultSelect$diffcen.real == ResultSelect2$diffcen.real
#> strength expectedInfluence
#> A1 TRUE TRUE
#> A3 TRUE TRUE
# Should be FALSE Created on 2023-05-30 with reprex v2.0.2 |
Hello,
I noticed a bug in the centrality testing part of the NCT function. When I give it a list of nodes to centrality test (using test.centrality = TRUE and nodes = list()), the function only returns the results for the first element in the list. Regardless of how many nodes are given, and where in the data frame they are ordered, it always returns the first variable of the original data.
I found that the problem lies in an indexing bug, where instead of selecting every requested node and their corresponding centrality test values from an intermediate variable "diffcen.permtemp", it selects the first value only. This occurs twice in the current master branch.
I have implemented a fix for this, which I can PR if that is okay. However, I built the fix based on branch with hash a56712e by @pinusm, not based on the main branch (as I was using their multi-core implementation at the time). Would it be better if the pull request for that branch, #32, is first merged, and then I submit a pull request for discussion to fix this problem?
This is my first time submitting an issue and potentially a PR, so I hope I am following the correct procedure!
Br,
Oliver Saal
(EDIT: Fixed the hash for the commit I branched from.)
The text was updated successfully, but these errors were encountered: