Create an undirected factor model graph
Source:R/undirected_factor_model.R
undirected_factor_model.Rd
An undirected factor model graph is an undirected
generalized Poisson random dot product graph. The edges
in this graph are assumed to be independent and Poisson
distributed. The graph is parameterized by its expected
adjacency matrix, which is E[A|X] = X S X'
. We do not recommend
that casual users use this function, see instead dcsbm()
and related functions, which will formulate common variants
of the stochastic blockmodels as undirected factor models
with lots of helpful input validation.
Usage
undirected_factor_model(
X,
S,
...,
expected_degree = NULL,
expected_density = NULL,
poisson_edges = TRUE,
allow_self_loops = TRUE
)
Arguments
- X
A
matrix()
orMatrix::Matrix()
representing real-valued latent node positions. Entries must be positive.- S
A
matrix()
orMatrix::Matrix()
mixing matrix.S
is symmetrized if it is not already, as this is the undirected case. Entries must be positive.- ...
Ignored. Must be empty.
- expected_degree
If specified, the desired expected degree of the graph. Specifying
expected_degree
simply rescalesS
to achieve this. Defaults toNULL
. Do not specify bothexpected_degree
andexpected_density
at the same time.- expected_density
If specified, the desired expected density of the graph. Specifying
expected_density
simply rescalesS
to achieve this. Defaults toNULL
. Do not specify bothexpected_degree
andexpected_density
at the same time.- poisson_edges
Logical indicating whether or not multiple edges are allowed to form between a pair of nodes. Defaults to
TRUE
. WhenFALSE
, sampling proceeds as usual, and duplicate edges are removed afterwards. Further, whenFALSE
, we assume thatS
specifies a desired between-factor connection probability, and back-transform thisS
to the appropriate Poisson intensity parameter to approximate Bernoulli factor connection probabilities. See Section 2.3 of Rohe et al. (2017) for some additional details.- allow_self_loops
Logical indicating whether or not nodes should be allowed to form edges with themselves. Defaults to
TRUE
. WhenFALSE
, sampling proceeds allowing self-loops, and these are then removed after the fact.
Value
An undirected_factor_model
S3 class based on a list
with the following elements:
X
: The latent positions as aMatrix::Matrix()
object.S
: The mixing matrix as aMatrix::Matrix()
object.n
: The number of nodes in the network.k
: The rank of expectation matrix. Equivalently, the dimension of the latent node position vectors.
Examples
n <- 100
k <- 5
X <- matrix(rpois(n = n * k, 1), nrow = n)
S <- matrix(runif(n = k * k, 0, .1), nrow = k)
ufm <- undirected_factor_model(X, S)
ufm
#> Undirected Factor Model
#> -----------------------
#>
#> Nodes (n): 100
#> Rank (k): 5
#>
#> X: 100 x 5 [dgeMatrix]
#> S: 5 x 5 [dgeMatrix]
#>
#> Poisson edges: TRUE
#> Allow self loops: TRUE
#>
#> Expected edges: 12303
#> Expected degree: 123
#> Expected density: 2.48555
ufm2 <- undirected_factor_model(X, S, expected_degree = 50)
ufm2
#> Undirected Factor Model
#> -----------------------
#>
#> Nodes (n): 100
#> Rank (k): 5
#>
#> X: 100 x 5 [dgeMatrix]
#> S: 5 x 5 [dgeMatrix]
#>
#> Poisson edges: TRUE
#> Allow self loops: TRUE
#>
#> Expected edges: 5000
#> Expected degree: 50
#> Expected density: 1.0101
svds(ufm2)
#> $d
#> [1] 57.6538304 3.4381554 2.6111020 0.5400835 0.2872029
#>
#> $u
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.09964174 0.142445332 0.089932486 0.211623998 -0.014246759
#> [2,] 0.06716158 0.070564578 -0.023357876 -0.081406807 0.116670736
#> [3,] 0.08753783 -0.078955289 -0.066213634 0.032259959 0.063206581
#> [4,] 0.06362401 0.094723163 -0.072089168 -0.037684790 -0.104541393
#> [5,] 0.01456548 0.055720563 -0.008993179 0.063653841 0.033273751
#> [6,] 0.03404917 -0.017191462 -0.018240288 0.096149798 0.037240632
#> [7,] 0.15559197 -0.084998552 -0.123180159 0.032023961 0.122446281
#> [8,] 0.10299588 -0.099842567 -0.108815461 0.177084609 0.039049296
#> [9,] 0.08717752 -0.058553271 -0.027495608 0.075018069 -0.057208782
#> [10,] 0.09402012 -0.093932567 0.132026456 0.004483579 -0.048703213
#> [11,] 0.08310769 0.021811138 -0.081336277 -0.005188833 -0.100574512
#> [12,] 0.11261124 -0.090236751 0.156387996 -0.044191272 0.012694704
#> [13,] 0.08999448 -0.041907820 0.098671736 0.116812272 -0.076827379
#> [14,] 0.12404364 -0.059099282 0.080431449 0.212962070 -0.039586747
#> [15,] 0.12238627 0.086652257 0.170990200 0.024771887 -0.238228001
#> [16,] 0.04539319 0.070625329 -0.135168735 -0.031768048 -0.045523947
#> [17,] 0.10259138 -0.051100888 -0.090583385 0.027307124 -0.096607631
#> [18,] 0.11349152 0.036242405 -0.171649310 0.160531548 0.028957317
#> [19,] 0.04539319 0.070625329 -0.135168735 -0.031768048 -0.045523947
#> [20,] 0.16166977 -0.051234150 0.093292007 -0.145529903 -0.125120440
#> [21,] 0.08225931 0.070079318 -0.027241678 0.106175953 -0.027901912
#> [22,] 0.09348786 -0.037726743 0.126917078 -0.119445339 0.129143186
#> [23,] 0.11956932 0.070006806 0.044822856 -0.017022316 -0.218609404
#> [24,] 0.11751717 -0.015782343 -0.138294590 0.048202855 0.057081483
#> [25,] 0.11157942 -0.260097885 -0.036996645 0.076356141 -0.082548770
#> [26,] 0.09156347 -0.130980036 -0.032858914 -0.080068734 0.091330747
#> [27,] 0.04369643 0.167161689 -0.026979538 0.190961524 0.099821252
#> [28,] 0.12610071 -0.176037660 -0.066475774 -0.052525612 -0.064516584
#> [29,] 0.07537253 0.133798275 -0.207249692 -0.015825152 -0.051649045
#> [30,] 0.09678060 0.154139543 -0.056720807 -0.022705800 -0.009869725
#> [31,] 0.06402850 0.045981484 -0.090321245 0.112092695 0.031115534
#> [32,] 0.05348867 -0.061763826 -0.047973346 -0.063889839 0.025965949
#> [33,] 0.15062958 0.071973698 -0.143412179 -0.129353750 0.136511587
#> [34,] 0.05719819 -0.121726217 0.044585349 0.059075172 -0.051083684
#> [35,] 0.06997853 0.087210029 0.102809468 -0.039612603 0.097052139
#> [36,] 0.06362401 0.094723163 -0.072089168 -0.037684790 -0.104541393
#> [37,] 0.06854222 -0.033909425 -0.072343098 -0.068842674 -0.133848263
#> [38,] 0.07176366 -0.066005654 0.035592170 0.122729014 -0.017809933
#> [39,] 0.08575270 0.074260394 0.001003664 -0.130081658 0.178068653
#> [40,] 0.01859112 0.003695816 0.024361540 -0.048674852 0.061397917
#> [41,] 0.05755849 -0.142128235 0.005867323 0.016317062 0.069331679
#> [42,] 0.14030588 -0.099915079 -0.036750928 0.053886339 -0.151658196
#> [43,] 0.07082691 0.038941849 0.048714869 -0.150977389 0.024379539
#> [44,] 0.14433152 -0.151939826 -0.003396208 -0.058442353 -0.123534029
#> [45,] 0.18013312 -0.040074190 0.094312094 -0.168356189 0.249780803
#> [46,] 0.03315660 0.059416379 0.015368361 0.014978990 0.094671668
#> [47,] 0.08579688 0.045920733 0.021489614 0.062453936 0.193310217
#> [48,] 0.03771450 -0.048814191 0.053832458 0.026579215 -0.055050565
#> [49,] 0.05264029 -0.013495646 0.006121253 0.047474947 0.098638549
#> [50,] 0.11261124 -0.090236751 0.156387996 -0.044191272 0.012694704
#> [51,] 0.03315660 0.059416379 0.015368361 0.014978990 0.094671668
#> [52,] 0.09852155 0.029263521 -0.144424055 -0.052899778 -0.139973361
#> [53,] 0.06362401 0.094723163 -0.072089168 -0.037684790 -0.104541393
#> [54,] 0.08820934 0.111307864 0.165889034 -0.045529345 0.038034693
#> [55,] 0.13856493 0.024960943 0.050952320 0.084080317 -0.021554560
#> [56,] 0.14514051 -0.249423185 -0.039860360 0.241112616 0.147779824
#> [57,] 0.12525233 -0.127769480 -0.012381176 0.058839174 0.008156016
#> [58,] 0.07033884 0.066808011 0.064091442 -0.082370713 0.217467502
#> [59,] 0.14071037 -0.148656759 -0.054983004 0.203663824 -0.016001269
#> [60,] 0.12273430 0.269337236 -0.162156484 0.105565789 -0.044118990
#> [61,] 0.10528057 -0.026991293 0.012242505 0.094949893 0.197277098
#> [62,] 0.15751636 0.008254741 0.036595834 -0.007352645 0.160258720
#> [63,] 0.08784903 0.131709882 0.204607060 -0.002771235 -0.082380670
#> [64,] 0.07453643 -0.021020541 0.141273564 -0.028012378 -0.052670094
#> [65,] 0.05666593 -0.065520393 0.039475972 -0.064853746 0.126762715
#> [66,] 0.16890458 0.067731871 -0.059846663 0.057265103 0.092735705
#> [67,] 0.07770141 0.178309889 -0.065705775 0.094575727 0.121820320
#> [68,] 0.06595289 0.139234777 0.069454748 0.072716090 0.068927973
#> [69,] 0.14259057 -0.027063804 0.084307039 -0.028248376 0.006569606
#> [70,] 0.08753783 -0.078955289 -0.066213634 0.032259959 0.063206581
#> [71,] 0.08995029 -0.013568158 0.078185786 -0.075723322 -0.092068943
#> [72,] 0.10487608 0.021750387 0.030474581 -0.054827591 0.061620171
#> [73,] 0.13941331 -0.023307238 -0.003142279 -0.027284469 -0.094227160
#> [74,] 0.08941803 0.042637665 0.073076409 -0.199652241 0.085777456
#> [75,] 0.06997853 0.087210029 0.102809468 -0.039612603 0.097052139
#> [76,] 0.06313593 0.122589325 -0.056712596 0.030921886 0.088546570
#> [77,] 0.12221432 0.122456063 0.127162796 -0.141915141 0.060033761
#> [78,] 0.07328355 0.075989318 0.213600239 -0.066425076 -0.115654421
#> [79,] 0.04624157 0.022357149 -0.189263333 -0.143132834 -0.118196547
#> [80,] 0.06684545 0.062626935 0.035846099 0.153886898 0.011496937
#> [81,] 0.06764965 0.042698416 -0.038734449 -0.150013483 -0.076417227
#> [82,] 0.10259138 -0.051100888 -0.090583385 0.027307124 -0.096607631
#> [83,] 0.15032574 -0.139050942 0.210220454 -0.017612057 -0.042355860
#> [84,] 0.13892524 0.004558925 0.012234294 0.041322207 0.098860803
#> [85,] 0.10697241 0.079199874 0.234077977 0.072482832 -0.198829152
#> [86,] 0.13570379 0.036655153 -0.095700974 -0.150249481 -0.017177527
#> [87,] 0.07118722 0.018539831 0.009996843 -0.193735500 0.144794902
#> [88,] 0.04821015 0.087270780 -0.009001391 0.010026155 -0.065142544
#> [89,] 0.06890252 -0.054311443 -0.111061124 -0.111600784 -0.013432900
#> [90,] 0.08503208 0.115064431 0.078439716 -0.044565438 -0.062762073
#> [91,] 0.08749364 -0.050615627 -0.086699583 -0.160275636 0.047965017
#> [92,] 0.13816044 0.073702622 0.069184396 -0.065697167 -0.157211487
#> [93,] 0.09120316 -0.110578018 0.005859112 -0.037310624 -0.029084616
#> [94,] 0.06720576 0.042224917 -0.002871927 0.111128788 0.131912300
#> [95,] 0.17060134 -0.028804489 -0.168035860 -0.165464469 -0.052609495
#> [96,] 0.11295435 0.295175755 0.153265982 0.236865141 -0.043957335
#> [97,] 0.08993801 0.189518839 -0.216242871 0.047828689 -0.018375295
#> [98,] 0.10666121 -0.131465296 -0.036742716 0.107514026 -0.053241901
#> [99,] 0.03807481 -0.069216209 0.015114432 -0.016178895 0.065364798
#> [100,] 0.13252653 0.040411720 -0.183150292 -0.149285574 -0.117974293
#>
#> $v
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.09964174 0.142445332 -0.089932486 0.211623998 0.014246759
#> [2,] 0.06716158 0.070564578 0.023357876 -0.081406807 -0.116670736
#> [3,] 0.08753783 -0.078955289 0.066213634 0.032259959 -0.063206581
#> [4,] 0.06362401 0.094723163 0.072089168 -0.037684790 0.104541393
#> [5,] 0.01456548 0.055720563 0.008993179 0.063653841 -0.033273751
#> [6,] 0.03404917 -0.017191462 0.018240288 0.096149798 -0.037240632
#> [7,] 0.15559197 -0.084998552 0.123180159 0.032023961 -0.122446281
#> [8,] 0.10299588 -0.099842567 0.108815461 0.177084609 -0.039049296
#> [9,] 0.08717752 -0.058553271 0.027495608 0.075018069 0.057208782
#> [10,] 0.09402012 -0.093932567 -0.132026456 0.004483579 0.048703213
#> [11,] 0.08310769 0.021811138 0.081336277 -0.005188833 0.100574512
#> [12,] 0.11261124 -0.090236751 -0.156387996 -0.044191272 -0.012694704
#> [13,] 0.08999448 -0.041907820 -0.098671736 0.116812272 0.076827379
#> [14,] 0.12404364 -0.059099282 -0.080431449 0.212962070 0.039586747
#> [15,] 0.12238627 0.086652257 -0.170990200 0.024771887 0.238228001
#> [16,] 0.04539319 0.070625329 0.135168735 -0.031768048 0.045523947
#> [17,] 0.10259138 -0.051100888 0.090583385 0.027307124 0.096607631
#> [18,] 0.11349152 0.036242405 0.171649310 0.160531548 -0.028957317
#> [19,] 0.04539319 0.070625329 0.135168735 -0.031768048 0.045523947
#> [20,] 0.16166977 -0.051234150 -0.093292007 -0.145529903 0.125120440
#> [21,] 0.08225931 0.070079318 0.027241678 0.106175953 0.027901912
#> [22,] 0.09348786 -0.037726743 -0.126917078 -0.119445339 -0.129143186
#> [23,] 0.11956932 0.070006806 -0.044822856 -0.017022316 0.218609404
#> [24,] 0.11751717 -0.015782343 0.138294590 0.048202855 -0.057081483
#> [25,] 0.11157942 -0.260097885 0.036996645 0.076356141 0.082548770
#> [26,] 0.09156347 -0.130980036 0.032858914 -0.080068734 -0.091330747
#> [27,] 0.04369643 0.167161689 0.026979538 0.190961524 -0.099821252
#> [28,] 0.12610071 -0.176037660 0.066475774 -0.052525612 0.064516584
#> [29,] 0.07537253 0.133798275 0.207249692 -0.015825152 0.051649045
#> [30,] 0.09678060 0.154139543 0.056720807 -0.022705800 0.009869725
#> [31,] 0.06402850 0.045981484 0.090321245 0.112092695 -0.031115534
#> [32,] 0.05348867 -0.061763826 0.047973346 -0.063889839 -0.025965949
#> [33,] 0.15062958 0.071973698 0.143412179 -0.129353750 -0.136511587
#> [34,] 0.05719819 -0.121726217 -0.044585349 0.059075172 0.051083684
#> [35,] 0.06997853 0.087210029 -0.102809468 -0.039612603 -0.097052139
#> [36,] 0.06362401 0.094723163 0.072089168 -0.037684790 0.104541393
#> [37,] 0.06854222 -0.033909425 0.072343098 -0.068842674 0.133848263
#> [38,] 0.07176366 -0.066005654 -0.035592170 0.122729014 0.017809933
#> [39,] 0.08575270 0.074260394 -0.001003664 -0.130081658 -0.178068653
#> [40,] 0.01859112 0.003695816 -0.024361540 -0.048674852 -0.061397917
#> [41,] 0.05755849 -0.142128235 -0.005867323 0.016317062 -0.069331679
#> [42,] 0.14030588 -0.099915079 0.036750928 0.053886339 0.151658196
#> [43,] 0.07082691 0.038941849 -0.048714869 -0.150977389 -0.024379539
#> [44,] 0.14433152 -0.151939826 0.003396208 -0.058442353 0.123534029
#> [45,] 0.18013312 -0.040074190 -0.094312094 -0.168356189 -0.249780803
#> [46,] 0.03315660 0.059416379 -0.015368361 0.014978990 -0.094671668
#> [47,] 0.08579688 0.045920733 -0.021489614 0.062453936 -0.193310217
#> [48,] 0.03771450 -0.048814191 -0.053832458 0.026579215 0.055050565
#> [49,] 0.05264029 -0.013495646 -0.006121253 0.047474947 -0.098638549
#> [50,] 0.11261124 -0.090236751 -0.156387996 -0.044191272 -0.012694704
#> [51,] 0.03315660 0.059416379 -0.015368361 0.014978990 -0.094671668
#> [52,] 0.09852155 0.029263521 0.144424055 -0.052899778 0.139973361
#> [53,] 0.06362401 0.094723163 0.072089168 -0.037684790 0.104541393
#> [54,] 0.08820934 0.111307864 -0.165889034 -0.045529345 -0.038034693
#> [55,] 0.13856493 0.024960943 -0.050952320 0.084080317 0.021554560
#> [56,] 0.14514051 -0.249423185 0.039860360 0.241112616 -0.147779824
#> [57,] 0.12525233 -0.127769480 0.012381176 0.058839174 -0.008156016
#> [58,] 0.07033884 0.066808011 -0.064091442 -0.082370713 -0.217467502
#> [59,] 0.14071037 -0.148656759 0.054983004 0.203663824 0.016001269
#> [60,] 0.12273430 0.269337236 0.162156484 0.105565789 0.044118990
#> [61,] 0.10528057 -0.026991293 -0.012242505 0.094949893 -0.197277098
#> [62,] 0.15751636 0.008254741 -0.036595834 -0.007352645 -0.160258720
#> [63,] 0.08784903 0.131709882 -0.204607060 -0.002771235 0.082380670
#> [64,] 0.07453643 -0.021020541 -0.141273564 -0.028012378 0.052670094
#> [65,] 0.05666593 -0.065520393 -0.039475972 -0.064853746 -0.126762715
#> [66,] 0.16890458 0.067731871 0.059846663 0.057265103 -0.092735705
#> [67,] 0.07770141 0.178309889 0.065705775 0.094575727 -0.121820320
#> [68,] 0.06595289 0.139234777 -0.069454748 0.072716090 -0.068927973
#> [69,] 0.14259057 -0.027063804 -0.084307039 -0.028248376 -0.006569606
#> [70,] 0.08753783 -0.078955289 0.066213634 0.032259959 -0.063206581
#> [71,] 0.08995029 -0.013568158 -0.078185786 -0.075723322 0.092068943
#> [72,] 0.10487608 0.021750387 -0.030474581 -0.054827591 -0.061620171
#> [73,] 0.13941331 -0.023307238 0.003142279 -0.027284469 0.094227160
#> [74,] 0.08941803 0.042637665 -0.073076409 -0.199652241 -0.085777456
#> [75,] 0.06997853 0.087210029 -0.102809468 -0.039612603 -0.097052139
#> [76,] 0.06313593 0.122589325 0.056712596 0.030921886 -0.088546570
#> [77,] 0.12221432 0.122456063 -0.127162796 -0.141915141 -0.060033761
#> [78,] 0.07328355 0.075989318 -0.213600239 -0.066425076 0.115654421
#> [79,] 0.04624157 0.022357149 0.189263333 -0.143132834 0.118196547
#> [80,] 0.06684545 0.062626935 -0.035846099 0.153886898 -0.011496937
#> [81,] 0.06764965 0.042698416 0.038734449 -0.150013483 0.076417227
#> [82,] 0.10259138 -0.051100888 0.090583385 0.027307124 0.096607631
#> [83,] 0.15032574 -0.139050942 -0.210220454 -0.017612057 0.042355860
#> [84,] 0.13892524 0.004558925 -0.012234294 0.041322207 -0.098860803
#> [85,] 0.10697241 0.079199874 -0.234077977 0.072482832 0.198829152
#> [86,] 0.13570379 0.036655153 0.095700974 -0.150249481 0.017177527
#> [87,] 0.07118722 0.018539831 -0.009996843 -0.193735500 -0.144794902
#> [88,] 0.04821015 0.087270780 0.009001391 0.010026155 0.065142544
#> [89,] 0.06890252 -0.054311443 0.111061124 -0.111600784 0.013432900
#> [90,] 0.08503208 0.115064431 -0.078439716 -0.044565438 0.062762073
#> [91,] 0.08749364 -0.050615627 0.086699583 -0.160275636 -0.047965017
#> [92,] 0.13816044 0.073702622 -0.069184396 -0.065697167 0.157211487
#> [93,] 0.09120316 -0.110578018 -0.005859112 -0.037310624 0.029084616
#> [94,] 0.06720576 0.042224917 0.002871927 0.111128788 -0.131912300
#> [95,] 0.17060134 -0.028804489 0.168035860 -0.165464469 0.052609495
#> [96,] 0.11295435 0.295175755 -0.153265982 0.236865141 0.043957335
#> [97,] 0.08993801 0.189518839 0.216242871 0.047828689 0.018375295
#> [98,] 0.10666121 -0.131465296 0.036742716 0.107514026 0.053241901
#> [99,] 0.03807481 -0.069216209 -0.015114432 -0.016178895 -0.065364798
#> [100,] 0.13252653 0.040411720 0.183150292 -0.149285574 0.117974293
#>
#> $niter
#> [1] 1
#>
#> $nops
#> [1] 45
#>