diff --git a/lighthergm/R/estimate_between_param.R b/lighthergm/R/estimate_between_param.R index 903f70c..1dfd2d4 100644 --- a/lighthergm/R/estimate_between_param.R +++ b/lighthergm/R/estimate_between_param.R @@ -47,12 +47,13 @@ estimate_between_param <- function(formula, network, block) { varnames <- statnet.common::list_rhs.formula(formula) %>% as.character() - dep_terms <- which(terms %>% purrr::map(function(t) { - dep <- t$dependence - is_dep <- is.null(dep) || dep - }) %>% unlist()) - between_rhs <- varnames[-dep_terms] - between_formula <- as.formula(paste("g_logit ~ ", paste(between_rhs, collapse = " + "))) + dep_terms <- + terms %>% purrr::map(function(t) { + dep <- t$dependence + is_dep <- is.null(dep) || dep + }) %>% unlist() + between_rhs <- varnames[!dep_terms] + between_formula <- as.formula(glue::glue("g_logit ~ {paste(between_rhs, collapse = '+')}")) # Estimate logit between_logit <- ergm( diff --git a/lighthergm/R/gof_lighthergm.R b/lighthergm/R/gof_lighthergm.R index 2ac389b..7f0d234 100644 --- a/lighthergm/R/gof_lighthergm.R +++ b/lighthergm/R/gof_lighthergm.R @@ -63,12 +63,12 @@ separate_formulas <- function(target_formula) { net <- get(str_net, envir = environment(target_formula)) terms <- ergm::ergm_model(target_formula)$terms varnames <- statnet.common::list_rhs.formula(target_formula) %>% as.character() - dep_terms <- which(terms %>% purrr::map(function(t) { - dep <- t$dependence - is_dep <- is.null(dep) || dep - }) %>% unlist()) - - between_rhs <- varnames[-dep_terms] + dep_terms <- + terms %>% purrr::map(function(t) { + dep <- t$dependence + is_dep <- is.null(dep) || dep + }) %>% unlist() + between_rhs <- varnames[!dep_terms] within_rhs <- varnames between_formula <- paste(str_net, "~", paste(between_rhs, collapse = " + ")) diff --git a/lighthergm/inst/extdata/initialized_cluster_data_by_infomap.clu b/lighthergm/inst/extdata/initialized_cluster_data_by_infomap.clu new file mode 100644 index 0000000..4c0fb8b --- /dev/null +++ b/lighthergm/inst/extdata/initialized_cluster_data_by_infomap.clu @@ -0,0 +1,1009 @@ +# v1.3.0 +# ./Infomap --flow-model undirected --preferred-number-of-modules 50 --clu inst/extdata/initialized_cluster_data_by_infomap.csv inst/extdata --seed 334 +# started at 2021-06-17 17:40:43 +# completed in 0.103162 s +# partitioned into 2 levels with 50 top modules +# codelength 9.45098 bits +# relative codelength savings 5.08335% +# module level 1 +# node_id module flow +171 1 0.00129468 +419 1 0.00125544 +179 1 0.00123583 +408 1 0.00121621 +172 1 0.00119659 +167 1 0.00117698 +410 1 0.00117698 +165 1 0.00115736 +413 1 0.00115736 +401 1 0.00115736 +407 1 0.00113775 +417 1 0.00111813 +412 1 0.00111813 +163 1 0.00109851 +404 1 0.0010789 +402 1 0.0010789 +420 1 0.0010789 +166 1 0.0010789 +416 1 0.00105928 +415 1 0.00105928 +170 1 0.00105928 +405 1 0.00105928 +178 1 0.00103966 +418 1 0.00100043 +164 1 0.00100043 +403 1 0.00100043 +175 1 0.00100043 +411 1 0.000980815 +168 1 0.000961199 +180 1 0.000961199 +406 1 0.000941583 +162 1 0.000921966 +169 1 0.000921966 +176 1 0.00090235 +173 1 0.000882734 +414 1 0.000882734 +161 1 0.000882734 +409 1 0.000843501 +174 1 0.000843501 +177 1 0.000784652 +336 2 0.00123583 +486 2 0.00123583 +334 2 0.00121621 +483 2 0.00121621 +484 2 0.00119659 +493 2 0.00117698 +488 2 0.00117698 +496 2 0.00115736 +326 2 0.00109851 +489 2 0.00105928 +329 2 0.00105928 +495 2 0.00103966 +339 2 0.00102005 +340 2 0.00102005 +337 2 0.00102005 +490 2 0.00100043 +492 2 0.00100043 +494 2 0.00100043 +338 2 0.00100043 +335 2 0.00100043 +333 2 0.00100043 +328 2 0.00100043 +327 2 0.00100043 +332 2 0.000980815 +497 2 0.000980815 +499 2 0.000980815 +321 2 0.000961199 +482 2 0.000961199 +485 2 0.000961199 +487 2 0.000961199 +330 2 0.000961199 +491 2 0.000941583 +481 2 0.000921966 +500 2 0.000921966 +331 2 0.00090235 +323 2 0.00090235 +322 2 0.00090235 +498 2 0.000882734 +324 2 0.000843501 +325 2 0.000823885 +4 3 0.00133391 +9 3 0.00123583 +3 3 0.00113775 +19 3 0.00113775 +2 3 0.00111813 +7 3 0.00109851 +14 3 0.00109851 +8 3 0.0010789 +17 3 0.0010789 +16 3 0.00105928 +12 3 0.00102005 +15 3 0.00102005 +13 3 0.00100043 +6 3 0.000980815 +20 3 0.000961199 +1 3 0.000961199 +11 3 0.000961199 +5 3 0.000941583 +18 3 0.000921966 +10 3 0.00090235 +954 4 0.00135353 +942 4 0.00123583 +951 4 0.00123583 +957 4 0.00117698 +945 4 0.00113775 +959 4 0.00113775 +944 4 0.0010789 +947 4 0.00105928 +960 4 0.00103966 +943 4 0.00102005 +953 4 0.00102005 +952 4 0.000980815 +955 4 0.000961199 +956 4 0.000961199 +941 4 0.000921966 +949 4 0.000921966 +958 4 0.000882734 +948 4 0.000882734 +950 4 0.000843501 +946 4 0.000765036 +108 5 0.00127506 +110 5 0.00121621 +113 5 0.00119659 +118 5 0.00117698 +104 5 0.0010789 +102 5 0.00105928 +103 5 0.00103966 +120 5 0.00102005 +116 5 0.00102005 +109 5 0.00102005 +112 5 0.00100043 +117 5 0.00100043 +105 5 0.00100043 +107 5 0.000980815 +114 5 0.000961199 +111 5 0.000941583 +119 5 0.000941583 +115 5 0.00090235 +106 5 0.000882734 +101 5 0.000784652 +464 6 0.00119659 +467 6 0.00113775 +480 6 0.00113775 +463 6 0.0010789 +476 6 0.0010789 +461 6 0.00105928 +474 6 0.00105928 +466 6 0.00103966 +469 6 0.00103966 +475 6 0.00103966 +478 6 0.00102005 +479 6 0.00100043 +470 6 0.00100043 +465 6 0.000980815 +473 6 0.000961199 +472 6 0.000961199 +468 6 0.000961199 +477 6 0.000961199 +462 6 0.00090235 +471 6 0.000843501 +311 7 0.00123583 +314 7 0.00115736 +318 7 0.00111813 +319 7 0.00109851 +305 7 0.00109851 +313 7 0.00109851 +312 7 0.0010789 +304 7 0.00103966 +303 7 0.00102005 +306 7 0.00102005 +302 7 0.00100043 +316 7 0.00100043 +307 7 0.000980815 +320 7 0.000980815 +309 7 0.000961199 +317 7 0.000961199 +308 7 0.000941583 +301 7 0.000921966 +310 7 0.000882734 +315 7 0.000823885 +261 8 0.00119659 +276 8 0.00119659 +272 8 0.00115736 +271 8 0.00113775 +266 8 0.00109851 +280 8 0.0010789 +265 8 0.0010789 +264 8 0.0010789 +269 8 0.00105928 +278 8 0.00100043 +275 8 0.000961199 +263 8 0.000961199 +279 8 0.000961199 +268 8 0.000941583 +270 8 0.000941583 +273 8 0.000941583 +277 8 0.000941583 +267 8 0.00090235 +274 8 0.000882734 +262 8 0.000863117 +734 9 0.00123583 +724 9 0.00117698 +723 9 0.00115736 +725 9 0.00111813 +731 9 0.00111813 +736 9 0.00109851 +729 9 0.0010789 +727 9 0.00103966 +739 9 0.00102005 +721 9 0.00100043 +738 9 0.00100043 +735 9 0.00100043 +728 9 0.000980815 +726 9 0.000941583 +732 9 0.000941583 +722 9 0.000921966 +733 9 0.000921966 +737 9 0.000882734 +740 9 0.000882734 +730 9 0.000843501 +971 10 0.00125544 +978 10 0.00121621 +974 10 0.00117698 +967 10 0.00115736 +965 10 0.00111813 +979 10 0.00109851 +964 10 0.0010789 +980 10 0.00105928 +972 10 0.00102005 +976 10 0.000980815 +963 10 0.000980815 +970 10 0.000961199 +966 10 0.000961199 +961 10 0.000961199 +973 10 0.000941583 +969 10 0.000921966 +968 10 0.000921966 +977 10 0.00090235 +975 10 0.000843501 +962 10 0.000784652 +581 11 0.00131429 +586 11 0.00125544 +582 11 0.00115736 +597 11 0.00113775 +595 11 0.00111813 +589 11 0.0010789 +594 11 0.0010789 +584 11 0.00103966 +599 11 0.000980815 +587 11 0.000980815 +592 11 0.000980815 +591 11 0.000961199 +583 11 0.000961199 +593 11 0.000941583 +600 11 0.000941583 +585 11 0.000921966 +598 11 0.000921966 +590 11 0.00090235 +588 11 0.000863117 +596 11 0.000765036 +642 12 0.00115736 +653 12 0.00115736 +649 12 0.00111813 +660 12 0.00109851 +659 12 0.0010789 +655 12 0.00105928 +651 12 0.00103966 +643 12 0.00103966 +656 12 0.00103966 +647 12 0.00102005 +657 12 0.00102005 +644 12 0.00100043 +641 12 0.00100043 +645 12 0.000961199 +652 12 0.000961199 +648 12 0.000941583 +654 12 0.000941583 +646 12 0.00090235 +650 12 0.000882734 +658 12 0.000843501 +211 13 0.00127506 +210 13 0.00119659 +202 13 0.00109851 +215 13 0.00109851 +201 13 0.0010789 +203 13 0.00105928 +214 13 0.00105928 +218 13 0.00103966 +219 13 0.00102005 +206 13 0.00100043 +212 13 0.00100043 +216 13 0.00100043 +217 13 0.00100043 +204 13 0.000980815 +205 13 0.000921966 +207 13 0.000921966 +209 13 0.000921966 +213 13 0.000882734 +220 13 0.000882734 +208 13 0.000765036 +282 14 0.00119659 +286 14 0.00119659 +283 14 0.00109851 +295 14 0.0010789 +294 14 0.0010789 +289 14 0.00105928 +293 14 0.00105928 +290 14 0.00105928 +288 14 0.00103966 +287 14 0.00103966 +284 14 0.00102005 +299 14 0.00100043 +296 14 0.000980815 +292 14 0.000941583 +281 14 0.000941583 +297 14 0.000941583 +300 14 0.000882734 +298 14 0.000882734 +291 14 0.000843501 +285 14 0.000823885 +190 15 0.00117698 +200 15 0.00113775 +196 15 0.00113775 +191 15 0.00111813 +198 15 0.00111813 +195 15 0.00111813 +194 15 0.0010789 +197 15 0.00105928 +186 15 0.00103966 +181 15 0.00100043 +193 15 0.00100043 +199 15 0.000980815 +183 15 0.000961199 +187 15 0.000941583 +189 15 0.000941583 +185 15 0.000921966 +184 15 0.00090235 +182 15 0.000882734 +188 15 0.000843501 +192 15 0.000784652 +248 16 0.00123583 +254 16 0.00113775 +255 16 0.00109851 +245 16 0.00109851 +250 16 0.00109851 +257 16 0.00105928 +242 16 0.00103966 +246 16 0.00103966 +260 16 0.00102005 +247 16 0.00100043 +256 16 0.00100043 +253 16 0.000980815 +244 16 0.000980815 +243 16 0.000980815 +258 16 0.000961199 +259 16 0.000961199 +249 16 0.000941583 +251 16 0.000882734 +252 16 0.000863117 +241 16 0.00074542 +65 17 0.00121621 +69 17 0.00121621 +73 17 0.00111813 +72 17 0.00109851 +79 17 0.0010789 +80 17 0.00105928 +70 17 0.00102005 +78 17 0.00100043 +74 17 0.00100043 +68 17 0.00100043 +71 17 0.000980815 +67 17 0.000980815 +76 17 0.000961199 +77 17 0.000961199 +66 17 0.000941583 +75 17 0.000941583 +63 17 0.000921966 +64 17 0.000882734 +62 17 0.000882734 +61 17 0.000863117 +85 18 0.00127506 +92 18 0.00117698 +86 18 0.00109851 +88 18 0.00109851 +97 18 0.00105928 +91 18 0.00105928 +81 18 0.00103966 +93 18 0.00102005 +100 18 0.00100043 +87 18 0.00100043 +83 18 0.00100043 +84 18 0.000980815 +95 18 0.000980815 +94 18 0.000941583 +96 18 0.000941583 +99 18 0.000941583 +98 18 0.000921966 +89 18 0.000863117 +82 18 0.000843501 +90 18 0.000823885 +984 19 0.00121621 +998 19 0.00111813 +999 19 0.00109851 +993 19 0.00109851 +982 19 0.0010789 +1000 19 0.0010789 +987 19 0.0010789 +983 19 0.0010789 +981 19 0.00102005 +991 19 0.00100043 +994 19 0.00100043 +996 19 0.000980815 +988 19 0.000961199 +997 19 0.000961199 +989 19 0.000921966 +985 19 0.00090235 +990 19 0.000882734 +992 19 0.000882734 +986 19 0.000863117 +995 19 0.000823885 +775 20 0.00129468 +767 20 0.00113775 +762 20 0.00105928 +763 20 0.00105928 +766 20 0.00103966 +774 20 0.00103966 +773 20 0.00103966 +771 20 0.000980815 +779 20 0.000980815 +761 20 0.000980815 +769 20 0.000980815 +768 20 0.000980815 +765 20 0.000980815 +772 20 0.000961199 +764 20 0.000961199 +776 20 0.000941583 +778 20 0.000941583 +780 20 0.000941583 +770 20 0.00090235 +777 20 0.000843501 +602 21 0.00125544 +620 21 0.00109851 +618 21 0.00109851 +601 21 0.0010789 +603 21 0.0010789 +607 21 0.0010789 +605 21 0.00105928 +608 21 0.00102005 +606 21 0.00102005 +614 21 0.00100043 +611 21 0.000980815 +604 21 0.000961199 +612 21 0.000941583 +616 21 0.000941583 +619 21 0.000941583 +609 21 0.000921966 +613 21 0.000921966 +610 21 0.00090235 +617 21 0.000882734 +615 21 0.000843501 +49 22 0.00119659 +52 22 0.00115736 +59 22 0.00115736 +44 22 0.00109851 +54 22 0.0010789 +58 22 0.00105928 +48 22 0.00105928 +45 22 0.00103966 +53 22 0.00103966 +57 22 0.00100043 +50 22 0.00100043 +47 22 0.000961199 +46 22 0.000961199 +41 22 0.000921966 +55 22 0.000921966 +42 22 0.000921966 +60 22 0.000882734 +51 22 0.000882734 +43 22 0.000863117 +56 22 0.000804269 +826 23 0.00133391 +837 23 0.00115736 +831 23 0.00115736 +824 23 0.00111813 +828 23 0.00111813 +830 23 0.00111813 +838 23 0.0010789 +832 23 0.00102005 +825 23 0.00100043 +840 23 0.000961199 +821 23 0.000961199 +822 23 0.000961199 +827 23 0.000921966 +823 23 0.000921966 +829 23 0.00090235 +834 23 0.000882734 +839 23 0.000882734 +833 23 0.000863117 +836 23 0.000863117 +835 23 0.000765036 +447 24 0.00129468 +458 24 0.00111813 +449 24 0.00109851 +453 24 0.00109851 +446 24 0.00105928 +452 24 0.00105928 +442 24 0.00103966 +444 24 0.00102005 +445 24 0.00100043 +441 24 0.000961199 +455 24 0.000961199 +454 24 0.000961199 +460 24 0.000941583 +450 24 0.000941583 +443 24 0.000941583 +456 24 0.000921966 +459 24 0.000921966 +457 24 0.00090235 +451 24 0.000863117 +448 24 0.000863117 +801 25 0.00115736 +811 25 0.00111813 +815 25 0.00109851 +813 25 0.0010789 +818 25 0.00105928 +807 25 0.00103966 +816 25 0.00103966 +803 25 0.00102005 +814 25 0.00102005 +819 25 0.00100043 +805 25 0.00100043 +808 25 0.00100043 +810 25 0.00100043 +812 25 0.000961199 +820 25 0.000941583 +804 25 0.000941583 +809 25 0.00090235 +817 25 0.00090235 +802 25 0.000863117 +806 25 0.000784652 +552 26 0.00115736 +541 26 0.00113775 +556 26 0.00109851 +546 26 0.00109851 +550 26 0.00109851 +560 26 0.0010789 +551 26 0.00103966 +559 26 0.00103966 +549 26 0.00100043 +554 26 0.00100043 +544 26 0.00100043 +548 26 0.000961199 +553 26 0.000961199 +543 26 0.000961199 +558 26 0.000941583 +542 26 0.000941583 +557 26 0.00090235 +555 26 0.000863117 +547 26 0.000843501 +545 26 0.000804269 +894 27 0.00121621 +881 27 0.00119659 +888 27 0.00115736 +900 27 0.00113775 +885 27 0.00111813 +897 27 0.00111813 +893 27 0.00105928 +886 27 0.00103966 +890 27 0.00103966 +899 27 0.00100043 +887 27 0.00100043 +882 27 0.000961199 +898 27 0.000941583 +889 27 0.00090235 +892 27 0.000863117 +896 27 0.000863117 +891 27 0.000843501 +884 27 0.000823885 +883 27 0.000823885 +895 27 0.000804269 +843 28 0.00113775 +858 28 0.00111813 +860 28 0.00109851 +854 28 0.00109851 +850 28 0.0010789 +845 28 0.00105928 +847 28 0.00102005 +848 28 0.00102005 +844 28 0.00100043 +849 28 0.00100043 +846 28 0.000980815 +841 28 0.000980815 +855 28 0.000980815 +851 28 0.000961199 +852 28 0.000961199 +857 28 0.000941583 +859 28 0.000921966 +853 28 0.000863117 +842 28 0.000843501 +856 28 0.000823885 +664 29 0.00115736 +674 29 0.00111813 +662 29 0.00109851 +669 29 0.00105928 +670 29 0.00105928 +663 29 0.00103966 +675 29 0.00103966 +667 29 0.00102005 +676 29 0.00100043 +673 29 0.00100043 +671 29 0.000980815 +679 29 0.000980815 +668 29 0.000980815 +666 29 0.000961199 +677 29 0.000961199 +661 29 0.000941583 +672 29 0.000921966 +678 29 0.00090235 +665 29 0.000863117 +680 29 0.000804269 +621 30 0.00113775 +631 30 0.00111813 +635 30 0.00111813 +626 30 0.00109851 +627 30 0.00109851 +624 30 0.00105928 +625 30 0.00105928 +638 30 0.00103966 +628 30 0.00102005 +639 30 0.00102005 +623 30 0.00100043 +634 30 0.00100043 +640 30 0.000961199 +629 30 0.000941583 +630 30 0.000921966 +632 30 0.00090235 +622 30 0.000882734 +633 30 0.000843501 +637 30 0.000843501 +636 30 0.000823885 +139 31 0.00127506 +130 31 0.00121621 +122 31 0.00117698 +135 31 0.00109851 +124 31 0.0010789 +128 31 0.00105928 +140 31 0.00103966 +129 31 0.00103966 +121 31 0.000980815 +133 31 0.000961199 +127 31 0.000941583 +131 31 0.000941583 +137 31 0.000941583 +123 31 0.000941583 +136 31 0.000882734 +132 31 0.000863117 +134 31 0.000863117 +138 31 0.000863117 +126 31 0.000843501 +125 31 0.000843501 +906 32 0.00115736 +903 32 0.00113775 +905 32 0.00113775 +917 32 0.00111813 +907 32 0.00105928 +916 32 0.00103966 +902 32 0.00102005 +909 32 0.00102005 +920 32 0.000980815 +914 32 0.000980815 +912 32 0.000980815 +910 32 0.000980815 +908 32 0.000980815 +913 32 0.000961199 +911 32 0.000941583 +904 32 0.000921966 +915 32 0.000882734 +919 32 0.000882734 +918 32 0.000843501 +901 32 0.000784652 +797 33 0.00115736 +793 33 0.00113775 +795 33 0.0010789 +789 33 0.0010789 +794 33 0.0010789 +796 33 0.00105928 +800 33 0.00102005 +799 33 0.00102005 +784 33 0.00102005 +798 33 0.00100043 +782 33 0.000980815 +787 33 0.000980815 +791 33 0.000961199 +781 33 0.000961199 +790 33 0.000941583 +785 33 0.000941583 +783 33 0.000882734 +788 33 0.000863117 +792 33 0.000843501 +786 33 0.000804269 +344 34 0.00115736 +341 34 0.00109851 +346 34 0.00109851 +358 34 0.00105928 +351 34 0.00105928 +353 34 0.00105928 +349 34 0.00103966 +348 34 0.00102005 +343 34 0.000980815 +360 34 0.000961199 +357 34 0.000961199 +355 34 0.000961199 +352 34 0.000961199 +347 34 0.000961199 +345 34 0.000961199 +342 34 0.000961199 +354 34 0.00090235 +350 34 0.000882734 +359 34 0.000882734 +356 34 0.000804269 +365 35 0.00113775 +372 35 0.00111813 +364 35 0.0010789 +371 35 0.0010789 +378 35 0.00105928 +376 35 0.00105928 +374 35 0.00105928 +380 35 0.00103966 +373 35 0.00102005 +366 35 0.00102005 +363 35 0.00100043 +379 35 0.00100043 +362 35 0.000961199 +370 35 0.000941583 +377 35 0.000941583 +369 35 0.000921966 +375 35 0.000882734 +361 35 0.000882734 +367 35 0.000784652 +368 35 0.00074542 +862 36 0.00129468 +874 36 0.00115736 +867 36 0.00115736 +871 36 0.00113775 +875 36 0.00111813 +865 36 0.00109851 +866 36 0.00105928 +863 36 0.00105928 +877 36 0.00105928 +879 36 0.00102005 +868 36 0.00100043 +873 36 0.00100043 +876 36 0.00100043 +861 36 0.000961199 +872 36 0.000961199 +878 36 0.000941583 +869 36 0.000921966 +864 36 0.00090235 +880 36 0.000882734 +396 37 0.00119659 +388 37 0.00117698 +399 37 0.00115736 +382 37 0.00113775 +381 37 0.00109851 +395 37 0.00105928 +400 37 0.00102005 +397 37 0.00102005 +394 37 0.00102005 +391 37 0.00100043 +389 37 0.000941583 +383 37 0.000941583 +390 37 0.00090235 +393 37 0.00090235 +385 37 0.00090235 +387 37 0.000863117 +384 37 0.000863117 +392 37 0.000823885 +398 37 0.000804269 +386 37 0.000784652 +141 38 0.00121621 +148 38 0.00117698 +150 38 0.00111813 +154 38 0.00109851 +145 38 0.0010789 +156 38 0.00103966 +146 38 0.00102005 +152 38 0.00102005 +143 38 0.000980815 +159 38 0.000980815 +144 38 0.000961199 +147 38 0.000961199 +149 38 0.000961199 +151 38 0.000941583 +155 38 0.000921966 +153 38 0.00090235 +158 38 0.000823885 +160 38 0.000804269 +157 38 0.000804269 +142 38 0.000804269 +429 39 0.00115736 +436 39 0.00109851 +433 39 0.0010789 +438 39 0.00105928 +422 39 0.00103966 +432 39 0.00103966 +430 39 0.00103966 +440 39 0.00102005 +439 39 0.00102005 +434 39 0.00102005 +428 39 0.00102005 +435 39 0.00100043 +425 39 0.000941583 +423 39 0.000941583 +427 39 0.000921966 +431 39 0.000882734 +426 39 0.000863117 +437 39 0.000843501 +421 39 0.000843501 +424 39 0.00074542 +504 40 0.00119659 +508 40 0.00113775 +502 40 0.00105928 +501 40 0.00103966 +511 40 0.00102005 +515 40 0.00102005 +510 40 0.000980815 +505 40 0.000980815 +513 40 0.000980815 +514 40 0.000980815 +503 40 0.000980815 +519 40 0.000961199 +507 40 0.000921966 +506 40 0.000921966 +520 40 0.000921966 +509 40 0.00090235 +512 40 0.000882734 +516 40 0.000882734 +517 40 0.000882734 +518 40 0.000882734 +21 41 0.00119659 +35 41 0.00115736 +39 41 0.00113775 +30 41 0.00105928 +38 41 0.00105928 +36 41 0.00105928 +40 41 0.00103966 +29 41 0.00103966 +23 41 0.000961199 +26 41 0.000961199 +33 41 0.000961199 +34 41 0.000961199 +27 41 0.000921966 +24 41 0.00090235 +22 41 0.000882734 +37 41 0.000882734 +25 41 0.000863117 +32 41 0.000843501 +31 41 0.000843501 +28 41 0.000784652 +534 42 0.00115736 +538 42 0.00113775 +528 42 0.00113775 +536 42 0.00111813 +539 42 0.00109851 +521 42 0.0010789 +524 42 0.00105928 +532 42 0.00103966 +530 42 0.00100043 +523 42 0.000980815 +531 42 0.000980815 +540 42 0.000941583 +535 42 0.00090235 +526 42 0.00090235 +522 42 0.00090235 +525 42 0.000863117 +533 42 0.000843501 +527 42 0.000804269 +537 42 0.000804269 +529 42 0.000647338 +692 43 0.00121621 +683 43 0.00109851 +684 43 0.0010789 +696 43 0.00105928 +693 43 0.00103966 +694 43 0.00103966 +688 43 0.00102005 +700 43 0.00100043 +689 43 0.00100043 +687 43 0.000980815 +681 43 0.000980815 +695 43 0.000980815 +698 43 0.000921966 +686 43 0.000921966 +690 43 0.000921966 +691 43 0.00090235 +697 43 0.000863117 +699 43 0.000823885 +682 43 0.000784652 +685 43 0.000765036 +718 44 0.00119659 +710 44 0.00109851 +701 44 0.0010789 +720 44 0.0010789 +712 44 0.0010789 +704 44 0.00105928 +715 44 0.00103966 +703 44 0.00102005 +702 44 0.000980815 +707 44 0.000980815 +716 44 0.000961199 +708 44 0.000941583 +719 44 0.00090235 +717 44 0.000882734 +711 44 0.000863117 +713 44 0.000863117 +714 44 0.000863117 +706 44 0.000863117 +705 44 0.000843501 +709 44 0.000784652 +744 45 0.00131429 +760 45 0.00113775 +745 45 0.0010789 +748 45 0.0010789 +757 45 0.00103966 +746 45 0.00102005 +742 45 0.000941583 +756 45 0.000941583 +741 45 0.000941583 +752 45 0.000921966 +747 45 0.000921966 +759 45 0.000921966 +749 45 0.00090235 +750 45 0.00090235 +743 45 0.000882734 +758 45 0.000882734 +755 45 0.000863117 +751 45 0.000823885 +753 45 0.000823885 +754 45 0.000784652 +236 46 0.00119659 +232 46 0.00117698 +226 46 0.00111813 +237 46 0.0010789 +230 46 0.0010789 +238 46 0.00105928 +228 46 0.00102005 +223 46 0.000980815 +231 46 0.000980815 +224 46 0.000921966 +229 46 0.00090235 +222 46 0.000863117 +235 46 0.000863117 +233 46 0.000863117 +221 46 0.000863117 +240 46 0.000843501 +234 46 0.000823885 +227 46 0.000823885 +239 46 0.000823885 +225 46 0.000725803 +562 47 0.00109851 +578 47 0.00109851 +563 47 0.0010789 +565 47 0.00100043 +561 47 0.00100043 +567 47 0.000980815 +579 47 0.000980815 +572 47 0.000980815 +573 47 0.000980815 +564 47 0.000961199 +570 47 0.000961199 +580 47 0.000941583 +574 47 0.000941583 +569 47 0.000882734 +577 47 0.000843501 +568 47 0.000843501 +566 47 0.000843501 +571 47 0.000823885 +576 47 0.000823885 +575 47 0.000765036 +922 48 0.00109851 +924 48 0.00109851 +939 48 0.0010789 +925 48 0.0010789 +937 48 0.0010789 +932 48 0.0010789 +935 48 0.00105928 +940 48 0.00102005 +938 48 0.00102005 +930 48 0.00102005 +934 48 0.00100043 +928 48 0.000961199 +927 48 0.000961199 +926 48 0.000941583 +921 48 0.00090235 +931 48 0.000863117 +933 48 0.000863117 +936 48 0.000843501 +923 48 0.000843501 +870 49 0.00102005 +929 50 0.000843501 diff --git a/lighthergm/src/RcppExports.cpp b/lighthergm/src/RcppExports.cpp index d698382..aaececa 100644 --- a/lighthergm/src/RcppExports.cpp +++ b/lighthergm/src/RcppExports.cpp @@ -6,6 +6,11 @@ using namespace Rcpp; +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + // eigenvectors_sparse arma::mat eigenvectors_sparse(const arma::sp_mat& X, int n_vec); RcppExport SEXP _lighthergm_eigenvectors_sparse(SEXP XSEXP, SEXP n_vecSEXP) { diff --git a/lighthergm/tests/testthat/test-estimate-params.R b/lighthergm/tests/testthat/test-estimate-params.R index 88c5e74..2fb23b7 100644 --- a/lighthergm/tests/testthat/test-estimate-params.R +++ b/lighthergm/tests/testthat/test-estimate-params.R @@ -1,83 +1,83 @@ -test_that("estimating between-block parameters by logit works", { - set.seed(334) - # Prepare data - edgelist <- - tibble::tribble( - ~head, ~tail, - 1, 9, - 2, 6, - 2, 7, - 2, 9, - 3, 5, - 3, 9, - 4, 7, - 4, 11, - 4, 15, - 5, 11, - 5, 15, - 7, 8, - 7, 16, - 9, 13, - 9, 14, - 9, 16, - 10, 14, - 11, 15, - 13, 15, - 13, 16 - ) - edgelist <- - as.matrix(edgelist) - attr(edgelist, "n") <- 16 - attr(edgelist, "vnames") <- - c( - "Acciaiuoli", "Albizzi", "Barbadori", "Bischeri", "Castellani", "Ginori", - "Guadagni", "Lamberteschi", "Medici", "Pazzi", "Peruzzi", "Pucci", "Ridolfi", - "Salviati", "Strozzi", "Tornabuoni" - ) - attr(edgelist, "directed") <- FALSE - attr(edgelist, "bipartite") <- FALSE - attr(edgelist, "loops") <- FALSE - attr(edgelist, "class") <- c("edgelist", "matrix") +set.seed(334) +# Prepare data +edgelist <- + tibble::tribble( + ~head, ~tail, + 1, 9, + 2, 6, + 2, 7, + 2, 9, + 3, 5, + 3, 9, + 4, 7, + 4, 11, + 4, 15, + 5, 11, + 5, 15, + 7, 8, + 7, 16, + 9, 13, + 9, 14, + 9, 16, + 10, 14, + 11, 15, + 13, 15, + 13, 16 + ) +edgelist <- + as.matrix(edgelist) +attr(edgelist, "n") <- 16 +attr(edgelist, "vnames") <- + c( + "Acciaiuoli", "Albizzi", "Barbadori", "Bischeri", "Castellani", "Ginori", + "Guadagni", "Lamberteschi", "Medici", "Pazzi", "Peruzzi", "Pucci", "Ridolfi", + "Salviati", "Strozzi", "Tornabuoni" + ) +attr(edgelist, "directed") <- FALSE +attr(edgelist, "bipartite") <- FALSE +attr(edgelist, "loops") <- FALSE +attr(edgelist, "class") <- c("edgelist", "matrix") - g <- network::network(edgelist, matrix.type = "edgelist", directed = FALSE) +g <- network::network(edgelist, matrix.type = "edgelist", directed = FALSE) - x1 <- as.integer(unlist(purrr::rbernoulli(n = g$gal$n))) - network::set.vertex.attribute(x = g, attrname = "x1", value = x1) +x1 <- as.integer(unlist(purrr::rbernoulli(n = g$gal$n))) +network::set.vertex.attribute(x = g, attrname = "x1", value = x1) - # Cluster - z_memb <- rep(1:4, each = 4) - network::set.vertex.attribute(x = g, attrname = "block", value = z_memb) +# Cluster +z_memb <- rep(1:4, each = 4) +network::set.vertex.attribute(x = g, attrname = "block", value = z_memb) - # Create dataset for test - g_link <- intergraph::asDF(g)$edges - g_attr <- intergraph::asDF(g)$vertexes +# Create dataset for test +g_link <- intergraph::asDF(g)$edges +g_attr <- intergraph::asDF(g)$vertexes - df_g <- - tibble::tibble( - head = 1:g$gal$n, - tail = 1:g$gal$n - ) %>% - tidyr::expand(tail, head) %>% - dplyr::filter(tail < head) %>% - dplyr::left_join(., g_attr, by = c("tail" = "intergraph_id")) %>% - dplyr::left_join(., g_attr, by = c("head" = "intergraph_id")) %>% - dplyr::mutate( - nodematch.x1 = ifelse(x1.x == x1.y, 1, 0), - same_block = ifelse(block.x == block.y, 1, 0) - ) %>% - dplyr::select(tail, head, nodematch.x1:same_block) %>% - dplyr::left_join(., g_link, by = c("tail" = "V1", "head" = "V2")) %>% - dplyr::mutate(connected = ifelse(is.na(na), 0, 1)) %>% - dplyr::select(-na) +df_g <- + tibble::tibble( + head = 1:g$gal$n, + tail = 1:g$gal$n + ) %>% + tidyr::expand(tail, head) %>% + dplyr::filter(tail < head) %>% + dplyr::left_join(., g_attr, by = c("tail" = "intergraph_id")) %>% + dplyr::left_join(., g_attr, by = c("head" = "intergraph_id")) %>% + dplyr::mutate( + nodematch.x1 = ifelse(x1.x == x1.y, 1, 0), + same_block = ifelse(block.x == block.y, 1, 0) + ) %>% + dplyr::select(tail, head, nodematch.x1:same_block) %>% + dplyr::left_join(., g_link, by = c("tail" = "V1", "head" = "V2")) %>% + dplyr::mutate(connected = ifelse(is.na(na), 0, 1)) %>% + dplyr::select(-na) - # Estimate the model - formula <- g ~ edges + nodematch("x1") + triangle + kstar(2) - est_between <- estimate_between_param( - formula = formula, - network = g, - block = z_memb - ) +# Estimate the model +formula <- g ~ edges + nodematch("x1") + triangle + kstar(2) +est_between <- estimate_between_param( + formula = formula, + network = g, + block = z_memb +) +test_that("estimating between-block parameters by logit works", { # Check if between-block connections are all zero. g_logit <- est_between$network edgelist <- intergraph::asDF(g_logit)$edges @@ -117,3 +117,14 @@ test_that("estimating between-block parameters by logit works", { method_second_step = "MPLE" ), NA) }) + +test_that("estimating between-block parameters using a formula without externality terms works", { + # Check if within-block parameter estiamtion works + expect_error( + estimate_between_param( + formula = g ~ edges + nodematch("x1"), + network = g, + block = z_memb + ), + NA) +}) diff --git a/lighthergm/tests/testthat/test-simulate_hergm.R b/lighthergm/tests/testthat/test-simulate_hergm.R index 39c512b..8998603 100644 --- a/lighthergm/tests/testthat/test-simulate_hergm.R +++ b/lighthergm/tests/testthat/test-simulate_hergm.R @@ -412,3 +412,31 @@ test_that("Yielding the same between-block network using the cpp function when t expect_false(all(adj1 == adj3)) expect_false(all(adj2 == adj3)) }) + + +test_that("Simulating networks using formula without externality terms works", { + K <- 10 + N <- 200 + formula_1 <- g ~ edges + nodematch("x") + x <- sample(c(1, 2), size = N, replace = TRUE) + block <- sample(1:K, size = N, replace = TRUE) + + nodes_data <- + tibble::tibble(x = x, node_id = as.character(1:N), block = block) + + coef_between <- c(-6.5, 0) + coef_within <- c(-4.5, 5) + + expect_error( + sim_net_1 <- lighthergm::simulate_hergm( + formula_for_simulation = formula_1, + data_for_simulation = nodes_data, + colname_vertex_id = 'node_id', + colname_block_membership = 'block', + coef_between_block = coef_between, + coef_within_block = coef_within, + n_sim = 1 + ), + NA + ) +}) diff --git a/lighthergm/tests/testthat/test-start-from-given-cluster.R b/lighthergm/tests/testthat/test-start-from-given-cluster.R index 078211b..f176480 100644 --- a/lighthergm/tests/testthat/test-start-from-given-cluster.R +++ b/lighthergm/tests/testthat/test-start-from-given-cluster.R @@ -70,7 +70,7 @@ test_that("starting EM iterations and parameter estimation from a given vector o # Check if starting from block memberships initialized Python's infomap works. expect_error(result2 <- lighthergm::hergm(g_sim ~ edges + nodematch("x") + nodematch("y") + triangles, - initialized_cluster_data = "initialized_cluster_data_by_infomap.clu", + initialized_cluster_data = system.file("extdata", "initialized_cluster_data_by_infomap.clu", package = "lighthergm"), n_em_step_max = 1, estimate_parameters = FALSE, verbose = 1