Skip to contents

Generates a random connected graph and Gamma matrix with conditional independence structure corresponding to that graph.

Usage

generate_random_model(d, graph_type = "general", ...)

Arguments

d

Number of vertices in the graph

graph_type

"tree", "block", "decomposable", "complete", or "general"

...

Further arguments passed to functions generating the graph and Gamma matrix

Examples

set.seed(1)
d <- 12

generate_random_model(d, 'tree')
#> $graph
#> IGRAPH 6920943 U--- 12 11 -- 
#> + edges from 6920943:
#>  [1] 1-- 7 1--12 2-- 3 3-- 8 3-- 9 4-- 5 4-- 6 6--10 7--10 7--11 9--10
#> 
#> $Gamma
#>            [,1]      [,2]      [,3]       [,4]       [,5]      [,6]      [,7]
#>  [1,] 0.0000000 2.6720780 2.0022634 1.75490900 1.84728711 1.5147334 0.4817166
#>  [2,] 2.6720780 0.0000000 0.6698146 1.80053975 1.89291786 1.5603642 2.1903614
#>  [3,] 2.0022634 0.6698146 0.0000000 1.13072516 1.22310327 0.8905496 1.5205468
#>  [4,] 1.7549090 1.8005397 1.1307252 0.00000000 0.09237811 0.2401756 1.2731924
#>  [5,] 1.8472871 1.8929179 1.2231033 0.09237811 0.00000000 0.3325537 1.3655705
#>  [6,] 1.5147334 1.5603642 0.8905496 0.24017559 0.33255370 0.0000000 1.0330168
#>  [7,] 0.4817166 2.1903614 1.5205468 1.27319238 1.36557049 1.0330168 0.0000000
#>  [8,] 2.3459810 1.0135322 0.3437176 1.47444277 1.56682088 1.2342672 1.8642644
#>  [9,] 1.8552114 0.8168666 0.1470520 0.98367317 1.07605128 0.7434976 1.3734948
#> [10,] 1.3132236 1.3588544 0.6890398 0.44168538 0.53406349 0.2015098 0.8315070
#> [11,] 1.2638652 2.9725099 2.3026953 2.05534092 2.14771903 1.8151653 0.7821485
#> [12,] 1.0796174 3.7516954 3.0818808 2.83452640 2.92690451 2.5943508 1.5613340
#>            [,8]      [,9]     [,10]     [,11]    [,12]
#>  [1,] 2.3459810 1.8552114 1.3132236 1.2638652 1.079617
#>  [2,] 1.0135322 0.8168666 1.3588544 2.9725099 3.751695
#>  [3,] 0.3437176 0.1470520 0.6890398 2.3026953 3.081881
#>  [4,] 1.4744428 0.9836732 0.4416854 2.0553409 2.834526
#>  [5,] 1.5668209 1.0760513 0.5340635 2.1477190 2.926905
#>  [6,] 1.2342672 0.7434976 0.2015098 1.8151653 2.594351
#>  [7,] 1.8642644 1.3734948 0.8315070 0.7821485 1.561334
#>  [8,] 0.0000000 0.4907696 1.0327574 2.6464129 3.425598
#>  [9,] 0.4907696 0.0000000 0.5419878 2.1556433 2.934829
#> [10,] 1.0327574 0.5419878 0.0000000 1.6136555 2.392841
#> [11,] 2.6464129 2.1556433 1.6136555 0.0000000 2.343483
#> [12,] 3.4255984 2.9348288 2.3928410 2.3434826 0.000000
#> 
generate_random_model(d, 'block')
#> $graph
#> IGRAPH 0766dc4 U--- 12 21 -- 
#> + edges from 0766dc4:
#>  [1]  1-- 2  2-- 3  2-- 4  2-- 5  2-- 6  2-- 7  2-- 8  2-- 9  2--10  2--11
#> [11]  2--12  4-- 5  4-- 6  4-- 7  5-- 6  5-- 7  6-- 7  8-- 9  8--10  9--10
#> [21] 11--12
#> 
#> $Gamma
#>            [,1]      [,2]      [,3]       [,4]       [,5]      [,6]      [,7]
#>  [1,] 0.0000000 0.6631232 1.0431529 1.05616480 1.05953800 0.9379824 0.8416377
#>  [2,] 0.6631232 0.0000000 0.3800297 0.39304160 0.39641480 0.2748592 0.1785145
#>  [3,] 1.0431529 0.3800297 0.0000000 0.77307130 0.77644449 0.6548889 0.5585442
#>  [4,] 1.0561648 0.3930416 0.7730713 0.00000000 0.06648054 0.4351744 0.2388959
#>  [5,] 1.0595380 0.3964148 0.7764445 0.06648054 0.00000000 0.5224760 0.2543835
#>  [6,] 0.9379824 0.2748592 0.6548889 0.43517445 0.52247603 0.0000000 0.1955791
#>  [7,] 0.8416377 0.1785145 0.5585442 0.23889590 0.25438349 0.1955791 0.0000000
#>  [8,] 0.9882473 0.3251241 0.7051538 0.71816571 0.72153891 0.5999833 0.5036386
#>  [9,] 1.2927417 0.6296185 1.0096482 1.02266005 1.02603325 0.9044777 0.8081330
#> [10,] 1.7371201 1.0739969 1.4540266 1.46703848 1.47041168 1.3488561 1.2525114
#> [11,] 0.8746154 0.2114922 0.5915219 0.60453376 0.60790696 0.4863514 0.3900067
#> [12,] 0.9263971 0.2632739 0.6433036 0.65631546 0.65968866 0.5381331 0.4417884
#>            [,8]      [,9]     [,10]     [,11]     [,12]
#>  [1,] 0.9882473 1.2927417 1.7371201 0.8746154 0.9263971
#>  [2,] 0.3251241 0.6296185 1.0739969 0.2114922 0.2632739
#>  [3,] 0.7051538 1.0096482 1.4540266 0.5915219 0.6433036
#>  [4,] 0.7181657 1.0226601 1.4670385 0.6045338 0.6563155
#>  [5,] 0.7215389 1.0260333 1.4704117 0.6079070 0.6596887
#>  [6,] 0.5999833 0.9044777 1.3488561 0.4863514 0.5381331
#>  [7,] 0.5036386 0.8081330 1.2525114 0.3900067 0.4417884
#>  [8,] 0.0000000 0.2638163 0.9393278 0.5366163 0.5883980
#>  [9,] 0.2638163 0.0000000 0.6205046 0.8411106 0.8928923
#> [10,] 0.9393278 0.6205046 0.0000000 1.2854891 1.3372708
#> [11,] 0.5366163 0.8411106 1.2854891 0.0000000 0.5173694
#> [12,] 0.5883980 0.8928923 1.3372708 0.5173694 0.0000000
#> 
generate_random_model(d, 'decomposable')
#> $graph
#> IGRAPH 37bd578 U--- 12 25 -- 
#> + edges from 37bd578:
#>  [1]  1-- 2  1-- 3  1-- 4  2-- 3  2-- 4  2-- 5  2-- 6  2-- 7  2-- 8  3-- 4
#> [11]  5-- 6  5-- 7  5-- 8  5-- 9  5--10  5--11  5--12  6-- 7  6-- 8  9--10
#> [21]  9--11  9--12 10--11 10--12 11--12
#> 
#> $Gamma
#>            [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
#>  [1,] 0.0000000 0.7642524 0.4113240 1.3614233 1.0419512 0.9419788 1.1521648
#>  [2,] 0.7642524 0.0000000 0.3023596 0.3445731 0.2776988 0.1777264 0.3879125
#>  [3,] 0.4113240 0.3023596 0.0000000 0.3856178 0.5800584 0.4800860 0.6902720
#>  [4,] 1.3614233 0.3445731 0.3856178 0.0000000 0.6222719 0.5222995 0.7324856
#>  [5,] 1.0419512 0.2776988 0.5800584 0.6222719 0.0000000 0.4014644 0.3728168
#>  [6,] 0.9419788 0.1777264 0.4800860 0.5222995 0.4014644 0.0000000 0.2380561
#>  [7,] 1.1521648 0.3879125 0.6902720 0.7324856 0.3728168 0.2380561 0.0000000
#>  [8,] 1.3806228 0.6163705 0.9187301 0.9609436 0.7102602 0.5832712 0.7425574
#>  [9,] 1.2745559 0.5103035 0.8126631 0.8548766 0.2326047 0.6340691 0.6054215
#> [10,] 1.2193632 0.4551108 0.7574704 0.7996839 0.1774120 0.5788764 0.5502288
#> [11,] 1.1542695 0.3900171 0.6923767 0.7345902 0.1123183 0.5137827 0.4851351
#> [12,] 1.1869615 0.4227091 0.7250687 0.7672822 0.1450103 0.5464747 0.5178271
#>            [,8]      [,9]      [,10]      [,11]     [,12]
#>  [1,] 1.3806228 1.2745559 1.21936316 1.15426947 1.1869615
#>  [2,] 0.6163705 0.5103035 0.45511081 0.39001712 0.4227091
#>  [3,] 0.9187301 0.8126631 0.75747038 0.69237669 0.7250687
#>  [4,] 0.9609436 0.8548766 0.79968388 0.73459019 0.7672822
#>  [5,] 0.7102602 0.2326047 0.17741199 0.11231830 0.1450103
#>  [6,] 0.5832712 0.6340691 0.57887638 0.51378270 0.5464747
#>  [7,] 0.7425574 0.6054215 0.55022880 0.48513511 0.5178271
#>  [8,] 0.0000000 0.9428649 0.88767219 0.82257850 0.8552705
#>  [9,] 0.9428649 0.0000000 0.28971757 0.17883725 0.3184166
#> [10,] 0.8876722 0.2897176 0.00000000 0.09618224 0.2926910
#> [11,] 0.8225785 0.1788372 0.09618224 0.00000000 0.1896247
#> [12,] 0.8552705 0.3184166 0.29269096 0.18962473 0.0000000
#> 
generate_random_model(d, 'general')
#> $graph
#> IGRAPH 8c74e6f U--- 12 14 -- 
#> + edges from 8c74e6f:
#>  [1] 1-- 2 3-- 6 4-- 6 1-- 7 4-- 7 1-- 9 5-- 9 2--10 3--10 7--10 2--11 7--11
#> [13] 6--12 8--12
#> 
#> $Gamma
#>            [,1]      [,2]      [,3]      [,4]       [,5]      [,6]      [,7]
#>  [1,] 0.0000000 0.3098242 0.5151284 0.6425519 1.58185823 0.7206350 0.1871033
#>  [2,] 0.3098242 0.0000000 0.4689128 0.6522880 1.89168244 0.7160302 0.2291397
#>  [3,] 0.5151284 0.4689128 0.0000000 0.5602815 2.09698659 0.5274192 0.3547164
#>  [4,] 0.6425519 0.6522880 0.5602815 0.0000000 2.22441010 0.2543482 0.4652176
#>  [5,] 1.5818582 1.8916824 2.0969866 2.2244101 0.00000000 2.3024933 1.7689616
#>  [6,] 0.7206350 0.7160302 0.5274192 0.2543482 2.30249326 0.0000000 0.5476381
#>  [7,] 0.1871033 0.2291397 0.3547164 0.4652176 1.76896157 0.5476381 0.0000000
#>  [8,] 2.4528655 2.4482606 2.2596496 1.9865786 4.03472368 1.7322304 2.2798685
#>  [9,] 1.4825351 1.7923593 1.9976635 2.1250870 0.09932311 2.2031701 1.6696385
#> [10,] 0.3353065 0.2770228 0.2191284 0.5287895 1.91716473 0.5601635 0.1785445
#> [11,] 0.2797845 0.2122884 0.4447439 0.5779304 1.86164269 0.6545364 0.1258087
#> [12,] 2.2949051 2.2903002 2.1016892 1.8286182 3.87676328 1.5742700 2.1219081
#>            [,8]       [,9]     [,10]     [,11]     [,12]
#>  [1,] 2.4528655 1.48253511 0.3353065 0.2797845 2.2949051
#>  [2,] 2.4482606 1.79235933 0.2770228 0.2122884 2.2903002
#>  [3,] 2.2596496 1.99766347 0.2191284 0.4447439 2.1016892
#>  [4,] 1.9865786 2.12508699 0.5287895 0.5779304 1.8286182
#>  [5,] 4.0347237 0.09932311 1.9171647 1.8616427 3.8767633
#>  [6,] 1.7322304 2.20317014 0.5601635 0.6545364 1.5742700
#>  [7,] 2.2798685 1.66963846 0.1785445 0.1258087 2.1219081
#>  [8,] 0.0000000 3.93540056 2.2923939 2.3867669 0.1579604
#>  [9,] 3.9354006 0.00000000 1.8178416 1.7623196 3.7774402
#> [10,] 2.2923939 1.81784162 0.0000000 0.2636791 2.1344335
#> [11,] 2.3867669 1.76231958 0.2636791 0.0000000 2.2288065
#> [12,] 0.1579604 3.77744017 2.1344335 2.2288065 0.0000000
#> 
generate_random_model(d, 'complete')
#> $graph
#> IGRAPH 910a937 U--- 12 66 -- Full graph
#> + attr: name (g/c), loops (g/l)
#> + edges from 910a937:
#>  [1]  1-- 2  1-- 3  1-- 4  1-- 5  1-- 6  1-- 7  1-- 8  1-- 9  1--10  1--11
#> [11]  1--12  2-- 3  2-- 4  2-- 5  2-- 6  2-- 7  2-- 8  2-- 9  2--10  2--11
#> [21]  2--12  3-- 4  3-- 5  3-- 6  3-- 7  3-- 8  3-- 9  3--10  3--11  3--12
#> [31]  4-- 5  4-- 6  4-- 7  4-- 8  4-- 9  4--10  4--11  4--12  5-- 6  5-- 7
#> [41]  5-- 8  5-- 9  5--10  5--11  5--12  6-- 7  6-- 8  6-- 9  6--10  6--11
#> [51]  6--12  7-- 8  7-- 9  7--10  7--11  7--12  8-- 9  8--10  8--11  8--12
#> [61]  9--10  9--11  9--12 10--11 10--12 11--12
#> 
#> $Gamma
#>           [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
#>  [1,] 0.000000  1.826744 2.5198342 4.2667952  2.584708  5.583948  6.285138
#>  [2,] 1.826744  0.000000 6.4535179 9.1284751  2.252150 10.575238  9.529873
#>  [3,] 2.519834  6.453518 0.0000000 0.8056098  6.511059  2.296935  2.045383
#>  [4,] 4.266795  9.128475 0.8056098 0.0000000  8.103820  2.380367  1.898064
#>  [5,] 2.584708  2.252150 6.5110592 8.1038200  0.000000 13.214458  9.978888
#>  [6,] 5.583948 10.575238 2.2969349 2.3803671 13.214458  0.000000  4.101424
#>  [7,] 6.285138  9.529873 2.0453833 1.8980638  9.978888  4.101424  0.000000
#>  [8,] 3.799885  2.743182 6.5516513 8.0627895  1.132995 13.207905  8.282186
#>  [9,] 5.040655  3.130909 6.7864433 8.5146144  3.499823 12.735089  6.436607
#> [10,] 3.471922  2.554109 6.3456017 8.2200324  1.206106 13.336919  8.446862
#> [11,] 3.374544  7.616578 5.5408265 6.4150116  6.424110  7.346951 12.582113
#> [12,] 4.778869 10.076722 0.9297935 0.5136598  9.822322  1.585486  2.467000
#>             [,8]      [,9]      [,10]     [,11]      [,12]
#>  [1,]  3.7998848  5.040655  3.4719215  3.374544  4.7788690
#>  [2,]  2.7431822  3.130909  2.5541085  7.616578 10.0767220
#>  [3,]  6.5516513  6.786443  6.3456017  5.540827  0.9297935
#>  [4,]  8.0627895  8.514614  8.2200324  6.415012  0.5136598
#>  [5,]  1.1329952  3.499823  1.2061061  6.424110  9.8223223
#>  [6,] 13.2079046 12.735089 13.3369185  7.346951  1.5854857
#>  [7,]  8.2821860  6.436607  8.4468624 12.582113  2.4669998
#>  [8,]  0.0000000  1.394137  0.6724853  9.366593  9.4847246
#>  [9,]  1.3941372  0.000000  1.5509688 13.775335  9.8140262
#> [10,]  0.6724853  1.550969  0.0000000  9.343888  9.5150467
#> [11,]  9.3665933 13.775335  9.3438880  0.000000  6.4286236
#> [12,]  9.4847246  9.814026  9.5150467  6.428624  0.0000000
#>