stocnet / manynet

Many Ways to Make, Manipulate, and Map Myriad Networks
https://stocnet.github.io/manynet/
Other
12 stars 0 forks source link

Weighted `node_degree()` with `alpha > 0` creates NaN's #84

Closed auzaheta closed 2 months ago

auzaheta commented 2 months ago

Describe the bug

The issue is rooted in the degree and strength combination force by the default value alpha = 1, though any alpha bigger than zero has the same effect. The formula computes the ratio strength/degree that, for some nodes, is 0 / 0 = NaN. Additionally, the default is normalization, then the maximum of the vector reproduces the NaNs for all the nodes.

To Reproduce

library(manynet)
#> Warning: package 'manynet' was built under R version 4.3.3
#> Registered S3 method overwritten by 'manynet':
#>   method          from     
#>   print.tbl_graph tidygraph
net0 <- matrix(
  c(
    0, 0, 0, 2, 0,
    0, 0, 4, 0, 0,
    0, 4, 0, 0, 0,
    2, 0, 0, 0, 0,
    0, 0, 0, 0, 0 
  ),
  nrow = 5, ncol = 5,
  dimnames = list(letters[seq(5)], letters[seq(5)])
)
netmn <- as_igraph(net0)
node_degree(netmn, normalized = TRUE)
#>       a     b     c     d     e
#> 1   NaN   NaN   NaN   NaN   NaN

Created on 2024-09-04 with reprex v2.1.1

Provide system information

─ Session info ─
 setting  value
 version  R version 4.3.1 (2023-06-16 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language EN
 collate  German_Switzerland.utf8
 ctype    German_Switzerland.utf8
 tz       Europe/Zurich
 date     2024-09-04
 rstudio  2024.04.1+748 Chocolate Cosmos (desktop)

─ Packages ──
 package        * version date (UTC) lib source
 cachem           1.0.8   2023-05-01 [1] CRAN (R 4.3.1)
 callr            3.7.3   2022-11-02 [1] CRAN (R 4.3.1)
 cli              3.6.2   2023-12-11 [1] CRAN (R 4.3.3)
 clipr            0.8.0   2022-02-22 [1] CRAN (R 4.3.1)
 coda             0.19-4  2020-09-30 [1] CRAN (R 4.3.1)
 colorspace       2.1-0   2023-01-23 [1] CRAN (R 4.3.1)
 crayon           1.5.2   2022-09-29 [1] CRAN (R 4.3.1)
 devtools         2.4.5   2022-10-11 [1] CRAN (R 4.3.1)
 digest           0.6.33  2023-07-07 [1] CRAN (R 4.3.1)
 dplyr            1.1.4   2023-11-17 [1] CRAN (R 4.3.3)
 ellipsis         0.3.2   2021-04-29 [1] CRAN (R 4.3.1)
 evaluate         0.23    2023-11-01 [1] CRAN (R 4.3.2)
 fansi            1.0.6   2023-12-08 [1] CRAN (R 4.3.3)
 farver           2.1.2   2024-05-13 [1] CRAN (R 4.3.3)
 fastmap          1.1.1   2023-02-24 [1] CRAN (R 4.3.1)
 fortunes         1.5-4   2016-12-29 [1] CRAN (R 4.3.0)
 fs               1.6.3   2023-07-20 [1] CRAN (R 4.3.1)
 generics         0.1.3   2022-07-05 [1] CRAN (R 4.3.1)
 ggforce          0.4.1   2022-10-04 [1] CRAN (R 4.3.1)
 ggplot2          3.5.1   2024-04-23 [1] CRAN (R 4.3.3)
 ggraph           2.1.0   2022-10-09 [1] CRAN (R 4.3.1)
 ggrepel          0.9.4   2023-10-13 [1] CRAN (R 4.3.1)
 glue             1.7.0   2024-01-09 [1] CRAN (R 4.3.3)
 graphlayouts     1.0.1   2023-09-19 [1] CRAN (R 4.3.1)
 gridExtra        2.3     2017-09-09 [1] CRAN (R 4.3.1)
 gtable           0.3.5   2024-04-22 [1] CRAN (R 4.3.3)
 htmltools        0.5.7   2023-11-03 [1] CRAN (R 4.3.2)
 htmlwidgets      1.6.2   2023-03-17 [1] CRAN (R 4.3.1)
 httpuv           1.6.12  2023-10-23 [1] CRAN (R 4.3.2)
 igraph           2.0.2   2024-02-17 [1] CRAN (R 4.3.3)
 knitr            1.45    2023-10-30 [1] CRAN (R 4.3.2)
 later            1.3.1   2023-05-02 [1] CRAN (R 4.3.1)
 lattice          0.21-8  2023-04-05 [1] CRAN (R 4.3.1)
 lifecycle        1.0.4   2023-11-07 [1] CRAN (R 4.3.2)
 magrittr         2.0.3   2022-03-30 [1] CRAN (R 4.3.1)
 manynet        * 1.0.5   2024-08-30 [1] CRAN (R 4.3.3)
 MASS             7.3-60  2023-05-04 [1] CRAN (R 4.3.1)
 memoise          2.0.1   2021-11-26 [1] CRAN (R 4.3.1)
 mime             0.12    2021-09-28 [1] CRAN (R 4.3.0)
 miniUI           0.1.1.1 2018-05-18 [1] CRAN (R 4.3.1)
 minMSE           0.5.1   2021-11-26 [1] CRAN (R 4.3.3)
 munsell          0.5.1   2024-04-01 [1] CRAN (R 4.3.3)
 network          1.18.1  2023-01-24 [1] CRAN (R 4.3.1)
 pillar           1.9.0   2023-03-22 [1] CRAN (R 4.3.1)
 pkgbuild         1.4.2   2023-06-26 [1] CRAN (R 4.3.1)
 pkgconfig        2.0.3   2019-09-22 [1] CRAN (R 4.3.1)
 pkgload          1.3.3   2023-09-22 [1] CRAN (R 4.3.1)
 polyclip         1.10-6  2023-09-27 [1] CRAN (R 4.3.1)
 prettyunits      1.2.0   2023-09-24 [1] CRAN (R 4.3.1)
 processx         3.8.2   2023-06-30 [1] CRAN (R 4.3.1)
 profvis          0.3.8   2023-05-02 [1] CRAN (R 4.3.1)
 promises         1.2.1   2023-08-10 [1] CRAN (R 4.3.1)
 ps               1.7.5   2023-04-18 [1] CRAN (R 4.3.1)
 purrr            1.0.2   2023-08-10 [1] CRAN (R 4.3.1)
 R6               2.5.1   2021-08-19 [1] CRAN (R 4.3.1)
 Rcpp             1.0.12  2024-01-09 [1] CRAN (R 4.3.3)
 remotes          2.4.2.1 2023-07-18 [1] CRAN (R 4.3.1)
 reprex         * 2.1.1   2024-07-06 [1] CRAN (R 4.3.3)
 rlang          * 1.1.4   2024-06-04 [1] CRAN (R 4.3.3)
 rmarkdown        2.25    2023-09-18 [1] CRAN (R 4.3.1)
 rstudioapi       0.15.0  2023-07-07 [1] CRAN (R 4.3.1)
 scales           1.3.0   2023-11-28 [1] CRAN (R 4.3.3)
 sessioninfo      1.2.2   2021-12-06 [1] CRAN (R 4.3.1)
 shiny            1.7.5   2023-08-12 [1] CRAN (R 4.3.1)
 statnet.common   4.9.0   2023-05-24 [1] CRAN (R 4.3.1)
 stringi          1.8.2   2023-11-23 [1] CRAN (R 4.3.1)
 stringr          1.5.1   2023-11-14 [1] CRAN (R 4.3.2)
 tibble           3.2.1   2023-03-20 [1] CRAN (R 4.3.1)
 tidygraph        1.2.3   2023-02-01 [1] CRAN (R 4.3.1)
 tidyr            1.3.0   2023-01-24 [1] CRAN (R 4.3.1)
 tidyselect       1.2.1   2024-03-11 [1] CRAN (R 4.3.3)
 tweenr           2.0.2   2022-09-06 [1] CRAN (R 4.3.1)
 urlchecker       1.0.1   2021-11-30 [1] CRAN (R 4.3.1)
 usethis          2.2.2   2023-07-06 [1] CRAN (R 4.3.1)
 utf8             1.2.4   2023-10-22 [1] CRAN (R 4.3.3)
 vctrs            0.6.5   2023-12-01 [1] CRAN (R 4.3.3)
 viridis          0.6.4   2023-07-22 [1] CRAN (R 4.3.1)
 viridisLite      0.4.2   2023-05-02 [1] CRAN (R 4.3.1)
 withr            3.0.0   2024-01-16 [1] CRAN (R 4.3.3)
 xfun             0.40    2023-08-09 [1] CRAN (R 4.3.1)
 xtable           1.8-4   2019-04-21 [1] CRAN (R 4.3.1)
 yaml             2.3.7   2023-01-23 [1] CRAN (R 4.3.0)

Expected behavior I don't know.

jhollway commented 2 months ago

This was due to there being an isolate in the weighted network. The bug has been fixed in a recent commit and will join the next version.