R-igraph-grp_month-full_month

2017.12.02 - work log - prelim - R network analysis - igraph

R network analysis files

Related files:

  • network descriptives

    • network-level

      • files

        • R scripts:

          • context_text/R/db_connect.r
          • context_text/R/sna/functions-sna.r
          • context_text/R/sna/sna-load_data.r
          • context_text/R/sna/igraph/*
          • context_text/R/sna/statnet/*
      • statnet/sna

        • sna::gden() - graph density
        • R scripts:

          • context_text/R/sna/statnet/sna-statnet-init.r
          • context_text/R/sna/statnet/sna-statnet-network-stats.r
          • context_text/R/sna/statnet/sna-qap.r
      • igraph

        • igraph::transitivity() - vector of transitivity scores for each node in a graph, plus network-level transitivity score.

          • Q - interpretation?
        • R scripts:

          • context_text/R/sna/statnet/sna-igraph-init.r
          • context_text/R/sna/statnet/sna-igraph-network-stats.r

Setup

Setup - working directories

Store important directories and file names in variables:


In [1]:
getwd()


'/home/jonathanmorgan/work/django/research/work/phd_work/methods/network_analysis/igraph'

In [32]:
# code files (in particular SNA function library, modest though it may be)
code_directory <- "/home/jonathanmorgan/work/django/research/context_analysis/R/sna"
sna_function_file_path = paste( code_directory, "/", 'functions-sna.r', sep = "" )

# home directory
home_directory <- getwd()
home_directory <- "/home/jonathanmorgan/work/django/research/work/phd_work/methods"

# data directories
data_directory <- paste( home_directory, "/data", sep = "" )
workspace_file_name <- "igraph-grp_month-full_month.RData"
workspace_file_path <- paste( data_directory, "/", workspace_file_name )

In [26]:
# set working directory to data directory for now.
setwd( data_directory )
message( getwd() )


/home/jonathanmorgan/work/django/research/work/phd_work/methods/data

Setup - load workspace (optional)

If you want, you can load this file's workspace, from a previous run - If you've changed values above, you might also need to re-run the above cells so new values overwrite those in workspace (make sure to save at the end, also):


In [24]:
# assumes that you've already set working directory above to the
#     working directory.
setwd( data_directory )
load( workspace_file_name )

Setup - import SNA functions

source the file functions-sna.r.


In [27]:
source( sna_function_file_path )

Setup - network data - render and store network data

First, need render to render network data and upload it to your server.

Directions for rendering network data are in 2017.11.14-work_log-prelim-network_analysis.ipynb. You want a tab-delimited matrix that includes both the network and attributes of nodes as columns, and you want it to include a header row.

Once you render your network data files, you should place them on the server.

High level data file layout:

  • tab-delimited.
  • first row and first column are labels
  • last 2 columns are traits of nodes (person_id and person_type)
  • each row and column after first until the trait columns represents a person found in one of the articles.
  • The people are in the same order from top to bottom and left to right.
  • Where the row and column of two people meet, and one of the people is an author, the nunber in the cell where they meet is the number of times the non-author was quoted in an article by the author. Does not include more basic two-mode co-location ties (appeared in same article, even if not an author and/or not quoted).

Files and their location on server:

data - grp_month

This is data from the Grand Rapids Press articles from December of 2009, coded by both humans and OpenCalais.

Files:

  • automated full month - sourcenet_data-20171115-043151-grp_month-automated.tab
  • human full month - sourcenet_data-20171115-043102-grp_month-human.tab

Location in Dropbox: Dropbox/academia/MSU/program_stuff/prelim_paper/data/network_analysis/2017.11.14/network/new_coders/grp_month

Location on server: /home/jonathanmorgan/work/django/research/work/phd_work/data/network/grp_month

grp_month analysis

First, look at the shiny new month of data.

grp_month (gm) - automated - OpenCalais

First, we'll analyze the month of data coded by OpenCalais. Set up some variables to store where data is located:


In [28]:
# initialize variables
gmAutomatedDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gmAutomatedDataFile <- "sourcenet_data-20171205-022551-grp_month-automated.tab"
gmAutomatedDataPath <- paste( gmAutomatedDataFolder, "/", gmAutomatedDataFile, sep = "" )

In [29]:
gmAutomatedDataPath


'/home/jonathanmorgan/work/django/research/work/phd_work/methods/data/network/grp_month/sourcenet_data-20171205-022551-grp_month-automated.tab'

Load the data file into memory


In [30]:
# tab-delimited:
gmAutomatedDataDF <- read.delim( gmAutomatedDataPath, header = TRUE, row.names = 1, check.names = FALSE )

In [31]:
# get count of rows...
gmAutomatedRowCount <- nrow( gmAutomatedDataDF )
message( paste( "grp_month automated row count = ", gmAutomatedRowCount, sep = "" ) )

# ...and columns
gmAutomatedColumnCount <- ncol( gmAutomatedDataDF )
message( paste( "grp_month automated column count = ", gmAutomatedColumnCount, sep = "" ) )


grp_month automated row count = 1167
grp_month automated column count = 1169

Get just the tie rows and columns for initializing network libraries.


In [33]:
# the below syntax returns only as many columns as there are rows, so
#     omitting any trait columns that lie in columns on the right side
#     of the file.
gmAutomatedNetworkDF <- gmAutomatedDataDF[ , 1 : gmAutomatedRowCount ]
#str( gmAutomatedNetworkDF )

In [34]:
# convert to a matrix
gmAutomatedNetworkMatrix <- as.matrix( gmAutomatedNetworkDF )
# str( gmAutomatedNetworkMatrix )

Initialize igraph

First, load the igraph package.

Once we get the data into an igraph object, run the code in the following for more in-depth information:

  • context_text/R/sna/statnet/sna-igraph-init.r
  • context_text/R/sna/statnet/sna-igraph-network-stats.r

In [35]:
#install.packages( "igraph" )
library( igraph )


Attaching package: ‘igraph’

The following objects are masked from ‘package:stats’:

    decompose, spectrum

The following object is masked from ‘package:base’:

    union

Load our data matrix into an igraph object.


In [36]:
# load data into igraph instance.
gmAutomatedNetworkIgraph <- graph.adjacency( gmAutomatedNetworkMatrix, mode = "undirected", weighted = TRUE )

In [37]:
# add person_id (column 1168)
personIdColumnNumber <- 1168

# first, get just the data frame column with person ID:
personIdsColumn <- gmAutomatedDataDF[ , personIdColumnNumber ]

# populate list we will use to set node person_ID attribute

# Don't just do these - they don't convert to simple list/vector, contain remnants of data frame
#personIdsList <- personIdsColumn
#personIdsList <- c( personIdsColumn )

# Convert to a list of numbers.
personIdsList <- as.numeric( personIdsColumn )

# Try this if you have character attribute...
#personTypesList <- unname( unlist( personTypesColumn ) )

# set vertex/node attribute person_id
V( gmAutomatedNetworkIgraph )$person_id <- personIdsList

# OR use function:
#gmAutomatedNetworkIgraph <- set.vertex.attribute( gmAutomatedNetworkIgraph, "person_id", value = personIdsList )

# look at graph and person_type attribute values
gmAutomatedNetworkIgraph
V( gmAutomatedNetworkIgraph )$person_id


IGRAPH 69a72c9 UNW- 1167 1153 -- 
+ attr: name (v/c), person_id (v/n), weight (e/n)
+ edges from 69a72c9 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--308__589__source-3  1__3__author-2--348__774__source-3 
 [9] 1__3__author-2--368__1080__source-3 1__3__author-2--388__1419__source-3
[11] 1__3__author-2--393__1451__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
[15] 1__3__author-2--808__2271__source-3 1__3__author-2--809__2272__source-3
+ ... omitted several edges
  1. 3
  2. 12
  3. 13
  4. 15
  5. 23
  6. 24
  7. 25
  8. 29
  9. 30
  10. 32
  11. 36
  12. 37
  13. 46
  14. 51
  15. 53
  16. 66
  17. 69
  18. 73
  19. 74
  20. 84
  21. 100
  22. 102
  23. 131
  24. 132
  25. 137
  26. 138
  27. 161
  28. 162
  29. 163
  30. 164
  31. 165
  32. 166
  33. 172
  34. 173
  35. 174
  36. 175
  37. 176
  38. 178
  39. 179
  40. 180
  41. 181
  42. 182
  43. 184
  44. 187
  45. 188
  46. 204
  47. 213
  48. 215
  49. 217
  50. 218
  51. 219
  52. 223
  53. 225
  54. 234
  55. 236
  56. 237
  57. 239
  58. 250
  59. 268
  60. 269
  61. 271
  62. 272
  63. 273
  64. 274
  65. 275
  66. 276
  67. 277
  68. 289
  69. 290
  70. 292
  71. 295
  72. 302
  73. 305
  74. 307
  75. 308
  76. 309
  77. 310
  78. 311
  79. 312
  80. 319
  81. 320
  82. 321
  83. 322
  84. 323
  85. 324
  86. 325
  87. 326
  88. 327
  89. 328
  90. 329
  91. 330
  92. 331
  93. 332
  94. 333
  95. 334
  96. 335
  97. 336
  98. 337
  99. 338
  100. 339
  101. 340
  102. 343
  103. 344
  104. 345
  105. 346
  106. 347
  107. 349
  108. 350
  109. 351
  110. 352
  111. 353
  112. 354
  113. 355
  114. 356
  115. 357
  116. 358
  117. 360
  118. 361
  119. 362
  120. 363
  121. 364
  122. 365
  123. 366
  124. 367
  125. 368
  126. 369
  127. 370
  128. 371
  129. 372
  130. 373
  131. 374
  132. 375
  133. 376
  134. 377
  135. 378
  136. 379
  137. 380
  138. 381
  139. 382
  140. 383
  141. 384
  142. 385
  143. 386
  144. 387
  145. 388
  146. 389
  147. 390
  148. 391
  149. 392
  150. 393
  151. 394
  152. 395
  153. 396
  154. 397
  155. 398
  156. 399
  157. 400
  158. 401
  159. 402
  160. 403
  161. 404
  162. 405
  163. 406
  164. 407
  165. 408
  166. 410
  167. 411
  168. 412
  169. 413
  170. 414
  171. 415
  172. 416
  173. 417
  174. 418
  175. 419
  176. 425
  177. 437
  178. 438
  179. 439
  180. 440
  181. 441
  182. 442
  183. 443
  184. 444
  185. 445
  186. 446
  187. 447
  188. 448
  189. 449
  190. 450
  191. 451
  192. 452
  193. 453
  194. 454
  195. 455
  196. 456
  197. 460
  198. 461
  199. 462
  200. 463
  201. 464
  202. 466
  203. 467
  204. 468
  205. 469
  206. 470
  207. 471
  208. 472
  209. 473
  210. 474
  211. 475
  212. 476
  213. 477
  214. 478
  215. 479
  216. 480
  217. 481
  218. 482
  219. 484
  220. 485
  221. 486
  222. 487
  223. 488
  224. 489
  225. 490
  226. 491
  227. 498
  228. 499
  229. 500
  230. 501
  231. 502
  232. 503
  233. 505
  234. 506
  235. 507
  236. 508
  237. 509
  238. 510
  239. 511
  240. 512
  241. 513
  242. 514
  243. 515
  244. 516
  245. 517
  246. 518
  247. 519
  248. 520
  249. 521
  250. 522
  251. 523
  252. 524
  253. 525
  254. 526
  255. 527
  256. 528
  257. 529
  258. 530
  259. 531
  260. 532
  261. 534
  262. 535
  263. 536
  264. 537
  265. 538
  266. 539
  267. 541
  268. 542
  269. 543
  270. 544
  271. 545
  272. 546
  273. 547
  274. 548
  275. 549
  276. 551
  277. 552
  278. 553
  279. 554
  280. 555
  281. 556
  282. 557
  283. 558
  284. 559
  285. 560
  286. 561
  287. 562
  288. 563
  289. 564
  290. 565
  291. 566
  292. 567
  293. 568
  294. 569
  295. 570
  296. 571
  297. 572
  298. 574
  299. 575
  300. 576
  301. 579
  302. 580
  303. 581
  304. 582
  305. 583
  306. 585
  307. 588
  308. 589
  309. 591
  310. 598
  311. 599
  312. 617
  313. 618
  314. 620
  315. 633
  316. 637
  317. 652
  318. 654
  319. 660
  320. 664
  321. 668
  322. 669
  323. 686
  324. 703
  325. 714
  326. 736
  327. 743
  328. 750
  329. 752
  330. 753
  331. 757
  332. 758
  333. 759
  334. 760
  335. 761
  336. 762
  337. 763
  338. 764
  339. 765
  340. 766
  341. 767
  342. 768
  343. 769
  344. 770
  345. 771
  346. 772
  347. 773
  348. 774
  349. 775
  350. 776
  351. 777
  352. 778
  353. 779
  354. 780
  355. 848
  356. 852
  357. 901
  358. 904
  359. 937
  360. 949
  361. 954
  362. 959
  363. 971
  364. 1043
  365. 1044
  366. 1056
  367. 1059
  368. 1080
  369. 1082
  370. 1109
  371. 1113
  372. 1133
  373. 1152
  374. 1183
  375. 1203
  376. 1205
  377. 1206
  378. 1207
  379. 1286
  380. 1287
  381. 1289
  382. 1298
  383. 1299
  384. 1318
  385. 1319
  386. 1343
  387. 1348
  388. 1419
  389. 1441
  390. 1442
  391. 1443
  392. 1445
  393. 1451
  394. 1453
  395. 1457
  396. 1458
  397. 1476
  398. 1479
  399. 1544
  400. 1546
  401. 1547
  402. 1548
  403. 1576
  404. 1591
  405. 1642
  406. 1655
  407. 1674
  408. 1687
  409. 1688
  410. 1689
  411. 1690
  412. 1691
  413. 1692
  414. 1693
  415. 1694
  416. 1695
  417. 1696
  418. 1697
  419. 1700
  420. 1703
  421. 1704
  422. 1705
  423. 1707
  424. 1708
  425. 1711
  426. 1712
  427. 1713
  428. 1714
  429. 1717
  430. 1718
  431. 1719
  432. 1720
  433. 1721
  434. 1722
  435. 1723
  436. 1724
  437. 1725
  438. 1726
  439. 1727
  440. 1728
  441. 1729
  442. 1730
  443. 1732
  444. 1733
  445. 1734
  446. 1735
  447. 1736
  448. 1737
  449. 1739
  450. 1740
  451. 1741
  452. 1743
  453. 1745
  454. 1746
  455. 1747
  456. 1749
  457. 1750
  458. 1752
  459. 1753
  460. 1754
  461. 1756
  462. 1757
  463. 1758
  464. 1759
  465. 1760
  466. 1761
  467. 1762
  468. 1765
  469. 1766
  470. 1767
  471. 1768
  472. 1769
  473. 1770
  474. 1772
  475. 1775
  476. 1778
  477. 1779
  478. 1782
  479. 1783
  480. 1784
  481. 1786
  482. 1787
  483. 1793
  484. 1794
  485. 1795
  486. 1796
  487. 1798
  488. 1800
  489. 1801
  490. 1803
  491. 1805
  492. 1806
  493. 1807
  494. 1808
  495. 1810
  496. 1811
  497. 1814
  498. 1815
  499. 1816
  500. 1817
  501. 1818
  502. 1819
  503. 1821
  504. 1823
  505. 1824
  506. 1825
  507. 1826
  508. 1827
  509. 1828
  510. 1829
  511. 1830
  512. 1831
  513. 1832
  514. 1833
  515. 1834
  516. 1835
  517. 1836
  518. 1837
  519. 1838
  520. 1839
  521. 1840
  522. 1841
  523. 1842
  524. 1843
  525. 1844
  526. 1845
  527. 1846
  528. 1847
  529. 1848
  530. 1849
  531. 1850
  532. 1851
  533. 1852
  534. 1853
  535. 1854
  536. 1855
  537. 1856
  538. 1857
  539. 1858
  540. 1859
  541. 1860
  542. 1861
  543. 1862
  544. 1863
  545. 1864
  546. 1865
  547. 1866
  548. 1867
  549. 1871
  550. 1872
  551. 1873
  552. 1874
  553. 1875
  554. 1880
  555. 1882
  556. 1883
  557. 1884
  558. 1886
  559. 1888
  560. 1889
  561. 1890
  562. 1891
  563. 1892
  564. 1899
  565. 1900
  566. 1901
  567. 1902
  568. 1903
  569. 1904
  570. 1905
  571. 1906
  572. 1907
  573. 1908
  574. 1911
  575. 1913
  576. 1931
  577. 1933
  578. 1955
  579. 1956
  580. 1960
  581. 1961
  582. 1962
  583. 1963
  584. 1964
  585. 1965
  586. 1966
  587. 1967
  588. 1972
  589. 1973
  590. 1974
  591. 1977
  592. 1978
  593. 1979
  594. 1980
  595. 1981
  596. 1982
  597. 1983
  598. 1984
  599. 1986
  600. 1988
  601. 1990
  602. 1991
  603. 1992
  604. 1994
  605. 1998
  606. 1999
  607. 2000
  608. 2001
  609. 2002
  610. 2003
  611. 2004
  612. 2008
  613. 2009
  614. 2012
  615. 2013
  616. 2014
  617. 2015
  618. 2016
  619. 2018
  620. 2019
  621. 2022
  622. 2023
  623. 2024
  624. 2025
  625. 2026
  626. 2027
  627. 2028
  628. 2029
  629. 2030
  630. 2031
  631. 2032
  632. 2034
  633. 2035
  634. 2036
  635. 2037
  636. 2038
  637. 2039
  638. 2040
  639. 2041
  640. 2042
  641. 2043
  642. 2044
  643. 2045
  644. 2046
  645. 2047
  646. 2048
  647. 2052
  648. 2054
  649. 2055
  650. 2056
  651. 2060
  652. 2064
  653. 2068
  654. 2069
  655. 2071
  656. 2073
  657. 2075
  658. 2076
  659. 2077
  660. 2078
  661. 2079
  662. 2080
  663. 2081
  664. 2087
  665. 2091
  666. 2094
  667. 2095
  668. 2096
  669. 2097
  670. 2098
  671. 2099
  672. 2100
  673. 2101
  674. 2102
  675. 2104
  676. 2105
  677. 2106
  678. 2107
  679. 2108
  680. 2110
  681. 2111
  682. 2112
  683. 2113
  684. 2114
  685. 2116
  686. 2118
  687. 2119
  688. 2120
  689. 2121
  690. 2126
  691. 2127
  692. 2128
  693. 2129
  694. 2130
  695. 2131
  696. 2132
  697. 2134
  698. 2136
  699. 2137
  700. 2138
  701. 2139
  702. 2140
  703. 2141
  704. 2142
  705. 2143
  706. 2144
  707. 2147
  708. 2148
  709. 2149
  710. 2150
  711. 2151
  712. 2152
  713. 2153
  714. 2154
  715. 2155
  716. 2156
  717. 2157
  718. 2158
  719. 2159
  720. 2160
  721. 2161
  722. 2162
  723. 2163
  724. 2164
  725. 2166
  726. 2167
  727. 2168
  728. 2169
  729. 2170
  730. 2171
  731. 2172
  732. 2173
  733. 2174
  734. 2175
  735. 2176
  736. 2177
  737. 2178
  738. 2181
  739. 2182
  740. 2185
  741. 2186
  742. 2187
  743. 2188
  744. 2189
  745. 2190
  746. 2191
  747. 2192
  748. 2193
  749. 2195
  750. 2196
  751. 2197
  752. 2198
  753. 2199
  754. 2201
  755. 2202
  756. 2203
  757. 2204
  758. 2205
  759. 2206
  760. 2207
  761. 2208
  762. 2209
  763. 2210
  764. 2211
  765. 2212
  766. 2213
  767. 2214
  768. 2216
  769. 2218
  770. 2219
  771. 2220
  772. 2221
  773. 2222
  774. 2223
  775. 2224
  776. 2225
  777. 2226
  778. 2229
  779. 2231
  780. 2232
  781. 2233
  782. 2234
  783. 2235
  784. 2245
  785. 2246
  786. 2247
  787. 2248
  788. 2249
  789. 2250
  790. 2251
  791. 2252
  792. 2253
  793. 2254
  794. 2255
  795. 2256
  796. 2257
  797. 2258
  798. 2259
  799. 2261
  800. 2262
  801. 2263
  802. 2264
  803. 2265
  804. 2266
  805. 2267
  806. 2268
  807. 2269
  808. 2271
  809. 2272
  810. 2277
  811. 2278
  812. 2280
  813. 2288
  814. 2289
  815. 2290
  816. 2291
  817. 2292
  818. 2293
  819. 2294
  820. 2295
  821. 2296
  822. 2297
  823. 2298
  824. 2299
  825. 2300
  826. 2301
  827. 2303
  828. 2306
  829. 2307
  830. 2308
  831. 2310
  832. 2311
  833. 2312
  834. 2313
  835. 2314
  836. 2315
  837. 2316
  838. 2317
  839. 2318
  840. 2319
  841. 2320
  842. 2321
  843. 2322
  844. 2323
  845. 2324
  846. 2325
  847. 2326
  848. 2329
  849. 2330
  850. 2331
  851. 2332
  852. 2338
  853. 2340
  854. 2341
  855. 2342
  856. 2346
  857. 2347
  858. 2348
  859. 2350
  860. 2351
  861. 2352
  862. 2353
  863. 2354
  864. 2355
  865. 2356
  866. 2358
  867. 2359
  868. 2360
  869. 2361
  870. 2362
  871. 2363
  872. 2364
  873. 2366
  874. 2367
  875. 2368
  876. 2369
  877. 2370
  878. 2371
  879. 2373
  880. 2374
  881. 2375
  882. 2379
  883. 2383
  884. 2386
  885. 2387
  886. 2388
  887. 2389
  888. 2390
  889. 2391
  890. 2392
  891. 2393
  892. 2397
  893. 2398
  894. 2399
  895. 2400
  896. 2401
  897. 2402
  898. 2403
  899. 2404
  900. 2405
  901. 2406
  902. 2407
  903. 2408
  904. 2409
  905. 2410
  906. 2411
  907. 2412
  908. 2413
  909. 2414
  910. 2415
  911. 2419
  912. 2430
  913. 2431
  914. 2432
  915. 2433
  916. 2434
  917. 2435
  918. 2437
  919. 2438
  920. 2439
  921. 2440
  922. 2441
  923. 2442
  924. 2443
  925. 2444
  926. 2445
  927. 2446
  928. 2447
  929. 2450
  930. 2455
  931. 2456
  932. 2457
  933. 2458
  934. 2459
  935. 2460
  936. 2461
  937. 2463
  938. 2466
  939. 2470
  940. 2471
  941. 2472
  942. 2473
  943. 2475
  944. 2476
  945. 2480
  946. 2481
  947. 2482
  948. 2485
  949. 2486
  950. 2488
  951. 2489
  952. 2490
  953. 2491
  954. 2492
  955. 2493
  956. 2494
  957. 2495
  958. 2496
  959. 2497
  960. 2498
  961. 2499
  962. 2501
  963. 2502
  964. 2503
  965. 2507
  966. 2509
  967. 2510
  968. 2511
  969. 2512
  970. 2513
  971. 2514
  972. 2515
  973. 2516
  974. 2517
  975. 2522
  976. 2523
  977. 2524
  978. 2525
  979. 2526
  980. 2527
  981. 2528
  982. 2529
  983. 2530
  984. 2531
  985. 2532
  986. 2534
  987. 2536
  988. 2537
  989. 2538
  990. 2539
  991. 2540
  992. 2544
  993. 2546
  994. 2547
  995. 2548
  996. 2549
  997. 2551
  998. 2552
  999. 2553
  1000. 2555
  1001. 2556
  1002. 2557
  1003. 2558
  1004. 2560
  1005. 2562
  1006. 2563
  1007. 2566
  1008. 2567
  1009. 2568
  1010. 2569
  1011. 2570
  1012. 2571
  1013. 2573
  1014. 2574
  1015. 2576
  1016. 2577
  1017. 2586
  1018. 2587
  1019. 2589
  1020. 2591
  1021. 2592
  1022. 2593
  1023. 2594
  1024. 2599
  1025. 2601
  1026. 2602
  1027. 2603
  1028. 2604
  1029. 2605
  1030. 2606
  1031. 2608
  1032. 2609
  1033. 2610
  1034. 2611
  1035. 2614
  1036. 2615
  1037. 2616
  1038. 2617
  1039. 2618
  1040. 2619
  1041. 2621
  1042. 2622
  1043. 2623
  1044. 2624
  1045. 2625
  1046. 2626
  1047. 2627
  1048. 2628
  1049. 2629
  1050. 2630
  1051. 2631
  1052. 2632
  1053. 2633
  1054. 2634
  1055. 2635
  1056. 2636
  1057. 2637
  1058. 2638
  1059. 2639
  1060. 2643
  1061. 2644
  1062. 2650
  1063. 2651
  1064. 2652
  1065. 2653
  1066. 2654
  1067. 2655
  1068. 2656
  1069. 2657
  1070. 2658
  1071. 2660
  1072. 2661
  1073. 2662
  1074. 2663
  1075. 2664
  1076. 2665
  1077. 2666
  1078. 2667
  1079. 2668
  1080. 2669
  1081. 2670
  1082. 2671
  1083. 2673
  1084. 2675
  1085. 2677
  1086. 2680
  1087. 2684
  1088. 2685
  1089. 2686
  1090. 2692
  1091. 2693
  1092. 2694
  1093. 2700
  1094. 2701
  1095. 2708
  1096. 2709
  1097. 2710
  1098. 2711
  1099. 2712
  1100. 2713
  1101. 2714
  1102. 2715
  1103. 2716
  1104. 2717
  1105. 2718
  1106. 2719
  1107. 2720
  1108. 2721
  1109. 2722
  1110. 2726
  1111. 2727
  1112. 2728
  1113. 2729
  1114. 2730
  1115. 2731
  1116. 2733
  1117. 2734
  1118. 2735
  1119. 2736
  1120. 2737
  1121. 2738
  1122. 2739
  1123. 2740
  1124. 2744
  1125. 2745
  1126. 2746
  1127. 2749
  1128. 2797
  1129. 2807
  1130. 2809
  1131. 2813
  1132. 2816
  1133. 2820
  1134. 2822
  1135. 2828
  1136. 2829
  1137. 2834
  1138. 2835
  1139. 2850
  1140. 2851
  1141. 2862
  1142. 2866
  1143. 2867
  1144. 2868
  1145. 2871
  1146. 2886
  1147. 2893
  1148. 2895
  1149. 2903
  1150. 2907
  1151. 2911
  1152. 2912
  1153. 2914
  1154. 2915
  1155. 2916
  1156. 2917
  1157. 2929
  1158. 2932
  1159. 2934
  1160. 2935
  1161. 2937
  1162. 2953
  1163. 2957
  1164. 2960
  1165. 2962
  1166. 2968
  1167. 2970

In [38]:
# add person_type (column 1169)
personTypeColumnNumber <- 1169

# first, get just the data frame column with person type:
personTypesColumn <- gmAutomatedDataDF[ , personTypeColumnNumber ]

# populate list we will use to set node person_type attribute

# Don't just do these - they don't convert to simple list/vector, contain remnants of data frame
#personTypesList <- personTypesColumn
#personTypesList <- c( personTypesColumn )

# Convert to a list of numbers.
personTypesList <- as.numeric( personTypesColumn )

# Try this if you have character attribute...
#personTypesList <- unname( unlist( personTypesColumn ) )

# set vertex/node attribute person_type
V( gmAutomatedNetworkIgraph )$person_type <- personTypesList

# OR use function:
#test1_igraph <- set.vertex.attribute( test1_igraph, "person_type", value = person_types_list )

# look at graph and person_type attribute values
gmAutomatedNetworkIgraph
V( gmAutomatedNetworkIgraph )$person_type


IGRAPH 69a72c9 UNW- 1167 1153 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from 69a72c9 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--308__589__source-3  1__3__author-2--348__774__source-3 
 [9] 1__3__author-2--368__1080__source-3 1__3__author-2--388__1419__source-3
[11] 1__3__author-2--393__1451__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
[15] 1__3__author-2--808__2271__source-3 1__3__author-2--809__2272__source-3
+ ... omitted several edges
  1. 2
  2. 3
  3. 2
  4. 3
  5. 2
  6. 3
  7. 3
  8. 2
  9. 2
  10. 3
  11. 2
  12. 3
  13. 2
  14. 3
  15. 3
  16. 2
  17. 2
  18. 2
  19. 2
  20. 2
  21. 3
  22. 3
  23. 3
  24. 3
  25. 3
  26. 3
  27. 2
  28. 1
  29. 3
  30. 3
  31. 3
  32. 3
  33. 3
  34. 3
  35. 3
  36. 3
  37. 3
  38. 2
  39. 3
  40. 1
  41. 3
  42. 3
  43. 3
  44. 3
  45. 3
  46. 3
  47. 1
  48. 3
  49. 2
  50. 3
  51. 3
  52. 2
  53. 3
  54. 3
  55. 3
  56. 3
  57. 3
  58. 3
  59. 3
  60. 3
  61. 3
  62. 3
  63. 3
  64. 3
  65. 1
  66. 3
  67. 1
  68. 3
  69. 3
  70. 3
  71. 3
  72. 2
  73. 3
  74. 3
  75. 3
  76. 3
  77. 3
  78. 3
  79. 3
  80. 3
  81. 3
  82. 3
  83. 3
  84. 3
  85. 3
  86. 3
  87. 3
  88. 3
  89. 3
  90. 3
  91. 3
  92. 3
  93. 2
  94. 3
  95. 3
  96. 3
  97. 2
  98. 3
  99. 3
  100. 3
  101. 3
  102. 3
  103. 3
  104. 3
  105. 3
  106. 1
  107. 1
  108. 1
  109. 1
  110. 3
  111. 3
  112. 3
  113. 1
  114. 3
  115. 3
  116. 3
  117. 1
  118. 3
  119. 3
  120. 3
  121. 3
  122. 3
  123. 3
  124. 3
  125. 3
  126. 3
  127. 3
  128. 3
  129. 3
  130. 3
  131. 1
  132. 3
  133. 3
  134. 2
  135. 3
  136. 3
  137. 3
  138. 3
  139. 3
  140. 3
  141. 1
  142. 3
  143. 3
  144. 2
  145. 3
  146. 3
  147. 3
  148. 3
  149. 3
  150. 3
  151. 2
  152. 3
  153. 3
  154. 3
  155. 3
  156. 3
  157. 3
  158. 3
  159. 3
  160. 3
  161. 3
  162. 3
  163. 3
  164. 3
  165. 3
  166. 3
  167. 3
  168. 3
  169. 3
  170. 3
  171. 3
  172. 3
  173. 2
  174. 3
  175. 3
  176. 2
  177. 2
  178. 3
  179. 3
  180. 1
  181. 3
  182. 3
  183. 2
  184. 3
  185. 3
  186. 3
  187. 3
  188. 3
  189. 3
  190. 3
  191. 3
  192. 3
  193. 3
  194. 3
  195. 3
  196. 3
  197. 2
  198. 1
  199. 3
  200. 3
  201. 3
  202. 3
  203. 3
  204. 3
  205. 3
  206. 3
  207. 3
  208. 3
  209. 3
  210. 3
  211. 3
  212. 3
  213. 3
  214. 1
  215. 3
  216. 3
  217. 3
  218. 2
  219. 3
  220. 3
  221. 3
  222. 3
  223. 3
  224. 3
  225. 3
  226. 1
  227. 3
  228. 3
  229. 3
  230. 3
  231. 3
  232. 3
  233. 2
  234. 3
  235. 1
  236. 3
  237. 3
  238. 3
  239. 3
  240. 3
  241. 3
  242. 3
  243. 3
  244. 3
  245. 3
  246. 1
  247. 3
  248. 3
  249. 3
  250. 3
  251. 3
  252. 3
  253. 3
  254. 3
  255. 3
  256. 3
  257. 3
  258. 3
  259. 3
  260. 3
  261. 3
  262. 3
  263. 3
  264. 3
  265. 3
  266. 3
  267. 3
  268. 3
  269. 3
  270. 3
  271. 3
  272. 3
  273. 3
  274. 3
  275. 1
  276. 1
  277. 3
  278. 3
  279. 3
  280. 3
  281. 3
  282. 3
  283. 3
  284. 3
  285. 3
  286. 3
  287. 3
  288. 3
  289. 3
  290. 3
  291. 2
  292. 3
  293. 1
  294. 3
  295. 1
  296. 3
  297. 3
  298. 3
  299. 3
  300. 3
  301. 3
  302. 3
  303. 1
  304. 3
  305. 3
  306. 3
  307. 1
  308. 3
  309. 2
  310. 4
  311. 2
  312. 3
  313. 3
  314. 3
  315. 3
  316. 2
  317. 2
  318. 2
  319. 3
  320. 3
  321. 3
  322. 3
  323. 3
  324. 2
  325. 3
  326. 2
  327. 2
  328. 3
  329. 3
  330. 3
  331. 3
  332. 1
  333. 1
  334. 1
  335. 3
  336. 3
  337. 3
  338. 3
  339. 3
  340. 3
  341. 3
  342. 3
  343. 3
  344. 3
  345. 1
  346. 3
  347. 3
  348. 3
  349. 3
  350. 3
  351. 3
  352. 1
  353. 3
  354. 3
  355. 1
  356. 3
  357. 3
  358. 1
  359. 1
  360. 3
  361. 3
  362. 1
  363. 1
  364. 3
  365. 3
  366. 3
  367. 3
  368. 3
  369. 2
  370. 3
  371. 3
  372. 3
  373. 3
  374. 1
  375. 3
  376. 3
  377. 1
  378. 3
  379. 3
  380. 3
  381. 3
  382. 3
  383. 3
  384. 3
  385. 3
  386. 3
  387. 3
  388. 3
  389. 3
  390. 3
  391. 3
  392. 1
  393. 3
  394. 1
  395. 1
  396. 3
  397. 3
  398. 3
  399. 3
  400. 3
  401. 3
  402. 3
  403. 3
  404. 1
  405. 3
  406. 2
  407. 3
  408. 3
  409. 3
  410. 3
  411. 3
  412. 3
  413. 3
  414. 1
  415. 3
  416. 1
  417. 3
  418. 1
  419. 3
  420. 3
  421. 3
  422. 3
  423. 3
  424. 3
  425. 3
  426. 3
  427. 3
  428. 3
  429. 3
  430. 3
  431. 3
  432. 3
  433. 3
  434. 3
  435. 3
  436. 1
  437. 3
  438. 3
  439. 3
  440. 3
  441. 3
  442. 3
  443. 3
  444. 3
  445. 3
  446. 3
  447. 3
  448. 3
  449. 3
  450. 3
  451. 3
  452. 3
  453. 3
  454. 1
  455. 3
  456. 3
  457. 1
  458. 3
  459. 3
  460. 3
  461. 3
  462. 3
  463. 3
  464. 3
  465. 3
  466. 3
  467. 3
  468. 3
  469. 1
  470. 3
  471. 1
  472. 3
  473. 3
  474. 3
  475. 3
  476. 3
  477. 3
  478. 2
  479. 3
  480. 3
  481. 3
  482. 3
  483. 3
  484. 3
  485. 3
  486. 3
  487. 3
  488. 3
  489. 3
  490. 3
  491. 3
  492. 1
  493. 3
  494. 3
  495. 3
  496. 3
  497. 3
  498. 3
  499. 3
  500. 3
  501. 3
  502. 3
  503. 3
  504. 3
  505. 3
  506. 3
  507. 3
  508. 3
  509. 3
  510. 3
  511. 3
  512. 3
  513. 3
  514. 3
  515. 3
  516. 3
  517. 3
  518. 3
  519. 3
  520. 3
  521. 3
  522. 3
  523. 3
  524. 3
  525. 3
  526. 3
  527. 3
  528. 3
  529. 3
  530. 3
  531. 3
  532. 3
  533. 3
  534. 3
  535. 3
  536. 3
  537. 3
  538. 3
  539. 3
  540. 3
  541. 3
  542. 3
  543. 3
  544. 3
  545. 3
  546. 3
  547. 3
  548. 3
  549. 3
  550. 3
  551. 3
  552. 3
  553. 3
  554. 3
  555. 3
  556. 3
  557. 3
  558. 3
  559. 3
  560. 3
  561. 3
  562. 3
  563. 3
  564. 1
  565. 3
  566. 3
  567. 3
  568. 3
  569. 3
  570. 3
  571. 3
  572. 3
  573. 3
  574. 3
  575. 3
  576. 3
  577. 3
  578. 1
  579. 3
  580. 3
  581. 3
  582. 1
  583. 3
  584. 3
  585. 3
  586. 3
  587. 3
  588. 3
  589. 3
  590. 3
  591. 3
  592. 3
  593. 1
  594. 3
  595. 3
  596. 1
  597. 3
  598. 3
  599. 3
  600. 1
  601. 3
  602. 3
  603. 3
  604. 3
  605. 3
  606. 3
  607. 3
  608. 3
  609. 3
  610. 3
  611. 2
  612. 3
  613. 3
  614. 3
  615. 3
  616. 3
  617. 1
  618. 3
  619. 2
  620. 3
  621. 3
  622. 3
  623. 3
  624. 3
  625. 3
  626. 3
  627. 3
  628. 3
  629. 3
  630. 3
  631. 3
  632. 3
  633. 3
  634. 3
  635. 3
  636. 3
  637. 3
  638. 3
  639. 3
  640. 3
  641. 3
  642. 3
  643. 3
  644. 3
  645. 3
  646. 1
  647. 3
  648. 3
  649. 1
  650. 3
  651. 3
  652. 1
  653. 3
  654. 3
  655. 3
  656. 1
  657. 1
  658. 3
  659. 3
  660. 3
  661. 3
  662. 3
  663. 3
  664. 3
  665. 3
  666. 3
  667. 3
  668. 3
  669. 3
  670. 3
  671. 3
  672. 3
  673. 3
  674. 3
  675. 3
  676. 3
  677. 3
  678. 3
  679. 1
  680. 3
  681. 3
  682. 3
  683. 3
  684. 3
  685. 3
  686. 3
  687. 3
  688. 3
  689. 3
  690. 3
  691. 3
  692. 3
  693. 1
  694. 3
  695. 3
  696. 3
  697. 1
  698. 3
  699. 3
  700. 3
  701. 3
  702. 3
  703. 3
  704. 3
  705. 3
  706. 3
  707. 1
  708. 3
  709. 3
  710. 3
  711. 3
  712. 3
  713. 3
  714. 3
  715. 3
  716. 3
  717. 3
  718. 3
  719. 3
  720. 3
  721. 3
  722. 3
  723. 1
  724. 1
  725. 1
  726. 3
  727. 3
  728. 3
  729. 3
  730. 3
  731. 3
  732. 3
  733. 1
  734. 1
  735. 3
  736. 1
  737. 1
  738. 3
  739. 1
  740. 1
  741. 3
  742. 3
  743. 3
  744. 3
  745. 3
  746. 3
  747. 3
  748. 3
  749. 3
  750. 3
  751. 3
  752. 3
  753. 3
  754. 3
  755. 1
  756. 3
  757. 3
  758. 3
  759. 3
  760. 1
  761. 3
  762. 1
  763. 3
  764. 3
  765. 3
  766. 1
  767. 3
  768. 3
  769. 3
  770. 3
  771. 3
  772. 1
  773. 3
  774. 3
  775. 3
  776. 3
  777. 3
  778. 3
  779. 3
  780. 3
  781. 3
  782. 3
  783. 3
  784. 3
  785. 3
  786. 3
  787. 3
  788. 3
  789. 3
  790. 3
  791. 3
  792. 3
  793. 3
  794. 1
  795. 3
  796. 3
  797. 3
  798. 3
  799. 3
  800. 3
  801. 3
  802. 3
  803. 3
  804. 3
  805. 3
  806. 3
  807. 1
  808. 3
  809. 3
  810. 3
  811. 3
  812. 3
  813. 1
  814. 3
  815. 3
  816. 3
  817. 3
  818. 1
  819. 3
  820. 3
  821. 3
  822. 3
  823. 1
  824. 3
  825. 1
  826. 1
  827. 3
  828. 3
  829. 1
  830. 3
  831. 2
  832. 3
  833. 3
  834. 3
  835. 3
  836. 3
  837. 3
  838. 1
  839. 3
  840. 3
  841. 3
  842. 3
  843. 3
  844. 3
  845. 3
  846. 3
  847. 3
  848. 3
  849. 3
  850. 3
  851. 3
  852. 3
  853. 3
  854. 3
  855. 3
  856. 3
  857. 1
  858. 3
  859. 3
  860. 1
  861. 3
  862. 3
  863. 3
  864. 3
  865. 3
  866. 3
  867. 3
  868. 3
  869. 3
  870. 3
  871. 3
  872. 3
  873. 3
  874. 3
  875. 3
  876. 3
  877. 3
  878. 3
  879. 3
  880. 3
  881. 3
  882. 3
  883. 3
  884. 3
  885. 3
  886. 3
  887. 3
  888. 3
  889. 3
  890. 3
  891. 3
  892. 3
  893. 3
  894. 1
  895. 3
  896. 3
  897. 3
  898. 3
  899. 3
  900. 3
  901. 3
  902. 3
  903. 3
  904. 3
  905. 3
  906. 3
  907. 3
  908. 3
  909. 3
  910. 3
  911. 1
  912. 3
  913. 3
  914. 3
  915. 3
  916. 3
  917. 3
  918. 3
  919. 3
  920. 1
  921. 3
  922. 3
  923. 3
  924. 3
  925. 3
  926. 1
  927. 1
  928. 3
  929. 3
  930. 3
  931. 3
  932. 3
  933. 3
  934. 3
  935. 1
  936. 3
  937. 3
  938. 3
  939. 3
  940. 3
  941. 3
  942. 3
  943. 3
  944. 1
  945. 1
  946. 3
  947. 3
  948. 3
  949. 3
  950. 3
  951. 3
  952. 3
  953. 3
  954. 3
  955. 3
  956. 3
  957. 3
  958. 3
  959. 3
  960. 3
  961. 1
  962. 1
  963. 3
  964. 3
  965. 3
  966. 3
  967. 3
  968. 3
  969. 3
  970. 3
  971. 3
  972. 3
  973. 3
  974. 3
  975. 3
  976. 3
  977. 3
  978. 3
  979. 3
  980. 1
  981. 1
  982. 1
  983. 3
  984. 1
  985. 3
  986. 3
  987. 3
  988. 3
  989. 3
  990. 3
  991. 3
  992. 3
  993. 3
  994. 3
  995. 1
  996. 3
  997. 3
  998. 3
  999. 3
  1000. 3
  1001. 3
  1002. 3
  1003. 3
  1004. 3
  1005. 3
  1006. 3
  1007. 3
  1008. 2
  1009. 3
  1010. 3
  1011. 3
  1012. 1
  1013. 3
  1014. 3
  1015. 1
  1016. 3
  1017. 3
  1018. 3
  1019. 3
  1020. 1
  1021. 3
  1022. 3
  1023. 1
  1024. 3
  1025. 3
  1026. 3
  1027. 3
  1028. 3
  1029. 3
  1030. 3
  1031. 3
  1032. 1
  1033. 3
  1034. 3
  1035. 2
  1036. 3
  1037. 3
  1038. 3
  1039. 3
  1040. 3
  1041. 3
  1042. 3
  1043. 3
  1044. 3
  1045. 3
  1046. 3
  1047. 3
  1048. 1
  1049. 3
  1050. 3
  1051. 3
  1052. 3
  1053. 3
  1054. 3
  1055. 3
  1056. 3
  1057. 3
  1058. 1
  1059. 3
  1060. 3
  1061. 3
  1062. 3
  1063. 3
  1064. 3
  1065. 3
  1066. 3
  1067. 3
  1068. 1
  1069. 3
  1070. 3
  1071. 3
  1072. 3
  1073. 1
  1074. 3
  1075. 3
  1076. 3
  1077. 3
  1078. 3
  1079. 1
  1080. 3
  1081. 3
  1082. 3
  1083. 3
  1084. 3
  1085. 3
  1086. 3
  1087. 3
  1088. 3
  1089. 3
  1090. 3
  1091. 3
  1092. 3
  1093. 3
  1094. 3
  1095. 3
  1096. 3
  1097. 3
  1098. 3
  1099. 3
  1100. 3
  1101. 3
  1102. 3
  1103. 3
  1104. 3
  1105. 3
  1106. 3
  1107. 3
  1108. 3
  1109. 3
  1110. 3
  1111. 1
  1112. 3
  1113. 3
  1114. 3
  1115. 3
  1116. 3
  1117. 3
  1118. 3
  1119. 3
  1120. 3
  1121. 3
  1122. 3
  1123. 1
  1124. 1
  1125. 3
  1126. 3
  1127. 3
  1128. 3
  1129. 3
  1130. 3
  1131. 3
  1132. 3
  1133. 3
  1134. 3
  1135. 3
  1136. 3
  1137. 3
  1138. 3
  1139. 3
  1140. 3
  1141. 3
  1142. 3
  1143. 3
  1144. 3
  1145. 3
  1146. 3
  1147. 3
  1148. 3
  1149. 3
  1150. 3
  1151. 3
  1152. 3
  1153. 3
  1154. 3
  1155. 3
  1156. 3
  1157. 3
  1158. 3
  1159. 3
  1160. 3
  1161. 3
  1162. 3
  1163. 3
  1164. 1
  1165. 3
  1166. 1
  1167. 3

In [39]:
# calais - include ties Greater than or equal to 0 (GE0)
gmAutomatedMeanTieWeightGE0Vector <- apply( gmAutomatedNetworkMatrix, 1, calculateListMean )
gmAutomatedDataDF$meanTieWeightGE0 <- gmAutomatedMeanTieWeightGE0Vector

# calais - include ties Greater than or equal to 1 (GE1)
gmAutomatedMeanTieWeightGE1Vector <- apply( gmAutomatedNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gmAutomatedDataDF$meanTieWeightGE1 <- gmAutomatedMeanTieWeightGE1Vector

# automated - Max tie weight?
gmAutomatedMaxTieWeightVector <- apply( gmAutomatedNetworkMatrix, 1, calculateListMax )
gmAutomatedDataDF$maxTieWeight <- gmAutomatedMaxTieWeightVector

In [40]:
# to see count of nodes and edges, just type the object name:
gmAutomatedNetworkIgraph

# Will output something like:
#
# IGRAPH UNW- 314 309 --
# + attr: name (v/c), weight (e/n)
#
# in the first line, "UNW-" are traits of graph:
# - 1 - U = undirected ( directed would be "D" )
# - 2 - N = named or not ( "-" instead of "N" )
# - 3 - W = weighted
# - 4 - B = bipartite ( "-" = not bipartite )
# 314 is where node count goes, 309 is edge count.
# The second line gives you information about the 'attributes' associated with the graph. In this case, there are two attributes, name and weight.  Next to each attribute name is a two-character construct that looks like "(v/c)".  The first letter is the thing the attribute is associated with (g = graph, v = vertex or node, e = edge).  The second is the type of the attribute (c = character data, n = numeric data).  So, in this case:
# - name (v/c) - the name attribute is a vertex/node attribute - the "v" in "(v/c)" - where the values are character data - the "c" in "(v/c)".
# - weight (e/n) - the weight attribute is an edge attribute - the "e" in "(e/n)" - where the values are numeric data - the "n" in "(e/n)".
# - based on: http://www.shizukalab.com/toolkits/sna/sna_data


IGRAPH 69a72c9 UNW- 1167 1153 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from 69a72c9 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--308__589__source-3  1__3__author-2--348__774__source-3 
 [9] 1__3__author-2--368__1080__source-3 1__3__author-2--388__1419__source-3
[11] 1__3__author-2--393__1451__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
[15] 1__3__author-2--808__2271__source-3 1__3__author-2--809__2272__source-3
+ ... omitted several edges

Calculate some basic metrics


In [41]:
# try calling the degree() function on an igraph object.  Returns a number vector with names.
gmAutomatedDegreeVector <- igraph::degree( gmAutomatedNetworkIgraph )

# For help with igraph::degree function:
#??igraph::degree

# calculate the mean of the degrees.
gmAutomatedAvgDegree <- mean( gmAutomatedDegreeVector )
message( paste( "grp_month automated average degree = ", gmAutomatedAvgDegree, sep = "" ) )

# append the degrees to the network as a vertex attribute.
V( gmAutomatedNetworkIgraph )$degree <- gmAutomatedDegreeVector

# also add degree vector to original data frame
gmAutomatedDataDF$degree <- gmAutomatedDegreeVector

# if you want to just work with the traits of the nodes/vertexes, you can
#    combine the attribute vectors into a data frame.

# first, output igraph object to see what attributes you have
gmAutomatedNetworkIgraph
V( gmAutomatedNetworkIgraph )$degree


grp_month automated average degree = 1.97600685518423
IGRAPH 69a72c9 UNW- 1167 1153 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), degree (v/n),
| weight (e/n)
+ edges from 69a72c9 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--308__589__source-3  1__3__author-2--348__774__source-3 
 [9] 1__3__author-2--368__1080__source-3 1__3__author-2--388__1419__source-3
[11] 1__3__author-2--393__1451__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
+ ... omitted several edges
  1. 30
  2. 1
  3. 39
  4. 1
  5. 34
  6. 1
  7. 1
  8. 50
  9. 26
  10. 1
  11. 29
  12. 1
  13. 47
  14. 1
  15. 1
  16. 93
  17. 46
  18. 29
  19. 47
  20. 71
  21. 2
  22. 9
  23. 1
  24. 1
  25. 2
  26. 1
  27. 35
  28. 0
  29. 2
  30. 2
  31. 2
  32. 2
  33. 1
  34. 1
  35. 1
  36. 1
  37. 1
  38. 42
  39. 1
  40. 0
  41. 1
  42. 2
  43. 2
  44. 1
  45. 5
  46. 1
  47. 0
  48. 1
  49. 43
  50. 5
  51. 1
  52. 14
  53. 1
  54. 1
  55. 2
  56. 2
  57. 1
  58. 2
  59. 1
  60. 1
  61. 1
  62. 1
  63. 1
  64. 1
  65. 0
  66. 1
  67. 0
  68. 2
  69. 4
  70. 1
  71. 1
  72. 32
  73. 1
  74. 1
  75. 3
  76. 1
  77. 1
  78. 1
  79. 1
  80. 1
  81. 1
  82. 1
  83. 1
  84. 1
  85. 1
  86. 1
  87. 1
  88. 1
  89. 1
  90. 1
  91. 1
  92. 1
  93. 7
  94. 1
  95. 1
  96. 1
  97. 9
  98. 2
  99. 1
  100. 1
  101. 1
  102. 1
  103. 1
  104. 2
  105. 5
  106. 0
  107. 0
  108. 0
  109. 0
  110. 1
  111. 1
  112. 1
  113. 0
  114. 1
  115. 1
  116. 2
  117. 0
  118. 2
  119. 2
  120. 1
  121. 1
  122. 1
  123. 1
  124. 1
  125. 2
  126. 1
  127. 1
  128. 1
  129. 1
  130. 1
  131. 0
  132. 1
  133. 1
  134. 35
  135. 1
  136. 1
  137. 1
  138. 1
  139. 1
  140. 1
  141. 0
  142. 1
  143. 1
  144. 19
  145. 1
  146. 1
  147. 1
  148. 1
  149. 1
  150. 1
  151. 27
  152. 1
  153. 1
  154. 1
  155. 1
  156. 1
  157. 1
  158. 1
  159. 1
  160. 1
  161. 2
  162. 1
  163. 1
  164. 1
  165. 1
  166. 1
  167. 1
  168. 1
  169. 1
  170. 1
  171. 1
  172. 1
  173. 4
  174. 1
  175. 1
  176. 32
  177. 49
  178. 1
  179. 2
  180. 0
  181. 1
  182. 1
  183. 44
  184. 1
  185. 1
  186. 1
  187. 1
  188. 1
  189. 1
  190. 1
  191. 2
  192. 1
  193. 1
  194. 2
  195. 1
  196. 1
  197. 4
  198. 0
  199. 1
  200. 1
  201. 1
  202. 1
  203. 1
  204. 1
  205. 1
  206. 1
  207. 1
  208. 1
  209. 1
  210. 2
  211. 2
  212. 2
  213. 2
  214. 0
  215. 2
  216. 2
  217. 1
  218. 1
  219. 1
  220. 1
  221. 1
  222. 4
  223. 1
  224. 1
  225. 1
  226. 0
  227. 1
  228. 1
  229. 1
  230. 1
  231. 2
  232. 1
  233. 15
  234. 1
  235. 0
  236. 1
  237. 1
  238. 2
  239. 2
  240. 2
  241. 2
  242. 2
  243. 2
  244. 4
  245. 1
  246. 0
  247. 1
  248. 1
  249. 1
  250. 1
  251. 1
  252. 1
  253. 1
  254. 1
  255. 1
  256. 1
  257. 1
  258. 1
  259. 1
  260. 1
  261. 2
  262. 1
  263. 1
  264. 1
  265. 1
  266. 1
  267. 1
  268. 1
  269. 1
  270. 1
  271. 1
  272. 1
  273. 1
  274. 1
  275. 0
  276. 0
  277. 2
  278. 2
  279. 2
  280. 2
  281. 1
  282. 1
  283. 2
  284. 1
  285. 1
  286. 1
  287. 1
  288. 1
  289. 1
  290. 1
  291. 2
  292. 1
  293. 0
  294. 2
  295. 0
  296. 1
  297. 2
  298. 3
  299. 1
  300. 1
  301. 1
  302. 1
  303. 0
  304. 1
  305. 1
  306. 1
  307. 0
  308. 1
  309. 72
  310. 24
  311. 46
  312. 3
  313. 1
  314. 1
  315. 1
  316. 10
  317. 8
  318. 2
  319. 1
  320. 1
  321. 2
  322. 1
  323. 1
  324. 2
  325. 1
  326. 2
  327. 2
  328. 1
  329. 1
  330. 1
  331. 1
  332. 0
  333. 0
  334. 0
  335. 1
  336. 2
  337. 1
  338. 1
  339. 1
  340. 1
  341. 1
  342. 1
  343. 2
  344. 1
  345. 0
  346. 1
  347. 1
  348. 1
  349. 1
  350. 1
  351. 1
  352. 0
  353. 1
  354. 1
  355. 0
  356. 1
  357. 1
  358. 0
  359. 0
  360. 1
  361. 1
  362. 0
  363. 0
  364. 1
  365. 1
  366. 1
  367. 3
  368. 2
  369. 15
  370. 1
  371. 1
  372. 1
  373. 1
  374. 0
  375. 2
  376. 1
  377. 0
  378. 1
  379. 1
  380. 1
  381. 1
  382. 1
  383. 1
  384. 1
  385. 1
  386. 2
  387. 1
  388. 2
  389. 1
  390. 1
  391. 1
  392. 0
  393. 1
  394. 0
  395. 0
  396. 1
  397. 1
  398. 1
  399. 1
  400. 1
  401. 1
  402. 2
  403. 1
  404. 0
  405. 1
  406. 7
  407. 1
  408. 1
  409. 1
  410. 1
  411. 1
  412. 1
  413. 1
  414. 0
  415. 1
  416. 0
  417. 1
  418. 0
  419. 1
  420. 1
  421. 1
  422. 1
  423. 1
  424. 1
  425. 1
  426. 1
  427. 1
  428. 1
  429. 1
  430. 1
  431. 1
  432. 1
  433. 1
  434. 1
  435. 1
  436. 0
  437. 1
  438. 1
  439. 1
  440. 1
  441. 1
  442. 3
  443. 2
  444. 4
  445. 2
  446. 1
  447. 2
  448. 2
  449. 1
  450. 1
  451. 1
  452. 1
  453. 1
  454. 0
  455. 1
  456. 1
  457. 0
  458. 1
  459. 1
  460. 1
  461. 1
  462. 1
  463. 1
  464. 1
  465. 1
  466. 1
  467. 1
  468. 1
  469. 0
  470. 1
  471. 0
  472. 1
  473. 1
  474. 1
  475. 1
  476. 2
  477. 1
  478. 4
  479. 1
  480. 1
  481. 1
  482. 1
  483. 1
  484. 1
  485. 1
  486. 1
  487. 1
  488. 1
  489. 1
  490. 1
  491. 1
  492. 0
  493. 1
  494. 1
  495. 1
  496. 1
  497. 1
  498. 1
  499. 1
  500. 1
  501. 1
  502. 1
  503. 1
  504. 1
  505. 1
  506. 1
  507. 1
  508. 1
  509. 1
  510. 1
  511. 1
  512. 1
  513. 1
  514. 1
  515. 1
  516. 1
  517. 1
  518. 1
  519. 1
  520. 1
  521. 1
  522. 1
  523. 1
  524. 1
  525. 1
  526. 1
  527. 1
  528. 1
  529. 1
  530. 1
  531. 1
  532. 1
  533. 1
  534. 1
  535. 1
  536. 1
  537. 1
  538. 1
  539. 1
  540. 1
  541. 1
  542. 1
  543. 1
  544. 1
  545. 1
  546. 1
  547. 1
  548. 1
  549. 1
  550. 1
  551. 1
  552. 1
  553. 1
  554. 1
  555. 1
  556. 1
  557. 1
  558. 1
  559. 1
  560. 1
  561. 1
  562. 1
  563. 2
  564. 0
  565. 1
  566. 1
  567. 1
  568. 1
  569. 1
  570. 1
  571. 1
  572. 1
  573. 1
  574. 1
  575. 1
  576. 1
  577. 1
  578. 0
  579. 1
  580. 1
  581. 1
  582. 0
  583. 1
  584. 1
  585. 1
  586. 1
  587. 1
  588. 1
  589. 1
  590. 1
  591. 1
  592. 1
  593. 0
  594. 2
  595. 1
  596. 0
  597. 1
  598. 1
  599. 1
  600. 0
  601. 1
  602. 1
  603. 1
  604. 1
  605. 1
  606. 1
  607. 1
  608. 1
  609. 1
  610. 1
  611. 4
  612. 1
  613. 1
  614. 1
  615. 1
  616. 1
  617. 0
  618. 1
  619. 5
  620. 1
  621. 1
  622. 1
  623. 1
  624. 1
  625. 1
  626. 1
  627. 1
  628. 1
  629. 1
  630. 1
  631. 1
  632. 1
  633. 1
  634. 1
  635. 1
  636. 1
  637. 1
  638. 1
  639. 1
  640. 1
  641. 1
  642. 1
  643. 1
  644. 1
  645. 1
  646. 0
  647. 2
  648. 2
  649. 0
  650. 2
  651. 2
  652. 0
  653. 1
  654. 1
  655. 1
  656. 0
  657. 0
  658. 1
  659. 1
  660. 1
  661. 1
  662. 1
  663. 1
  664. 1
  665. 1
  666. 4
  667. 1
  668. 1
  669. 1
  670. 1
  671. 1
  672. 1
  673. 1
  674. 1
  675. 1
  676. 1
  677. 1
  678. 1
  679. 0
  680. 1
  681. 1
  682. 1
  683. 1
  684. 1
  685. 1
  686. 1
  687. 1
  688. 1
  689. 1
  690. 1
  691. 1
  692. 1
  693. 0
  694. 1
  695. 1
  696. 1
  697. 0
  698. 1
  699. 1
  700. 1
  701. 1
  702. 1
  703. 1
  704. 1
  705. 1
  706. 1
  707. 0
  708. 1
  709. 1
  710. 1
  711. 1
  712. 1
  713. 1
  714. 1
  715. 1
  716. 1
  717. 1
  718. 1
  719. 1
  720. 1
  721. 1
  722. 1
  723. 0
  724. 0
  725. 0
  726. 1
  727. 1
  728. 1
  729. 1
  730. 1
  731. 1
  732. 1
  733. 0
  734. 0
  735. 1
  736. 0
  737. 0
  738. 1
  739. 0
  740. 0
  741. 1
  742. 1
  743. 1
  744. 1
  745. 1
  746. 1
  747. 1
  748. 1
  749. 1
  750. 1
  751. 1
  752. 1
  753. 1
  754. 1
  755. 0
  756. 1
  757. 1
  758. 2
  759. 1
  760. 0
  761. 1
  762. 0
  763. 1
  764. 1
  765. 1
  766. 0
  767. 1
  768. 1
  769. 1
  770. 1
  771. 1
  772. 0
  773. 2
  774. 2
  775. 2
  776. 2
  777. 2
  778. 1
  779. 1
  780. 1
  781. 2
  782. 1
  783. 1
  784. 1
  785. 1
  786. 1
  787. 1
  788. 1
  789. 1
  790. 1
  791. 1
  792. 1
  793. 1
  794. 0
  795. 2
  796. 1
  797. 1
  798. 1
  799. 1
  800. 1
  801. 1
  802. 1
  803. 2
  804. 1
  805. 1
  806. 1
  807. 0
  808. 1
  809. 1
  810. 1
  811. 1
  812. 1
  813. 0
  814. 1
  815. 1
  816. 1
  817. 1
  818. 0
  819. 1
  820. 1
  821. 1
  822. 1
  823. 0
  824. 1
  825. 0
  826. 0
  827. 1
  828. 1
  829. 0
  830. 1
  831. 3
  832. 2
  833. 1
  834. 1
  835. 1
  836. 2
  837. 1
  838. 0
  839. 1
  840. 1
  841. 1
  842. 1
  843. 1
  844. 1
  845. 1
  846. 1
  847. 1
  848. 1
  849. 1
  850. 1
  851. 1
  852. 1
  853. 1
  854. 1
  855. 1
  856. 1
  857. 0
  858. 1
  859. 1
  860. 0
  861. 1
  862. 1
  863. 1
  864. 1
  865. 1
  866. 1
  867. 1
  868. 1
  869. 1
  870. 1
  871. 1
  872. 1
  873. 1
  874. 1
  875. 1
  876. 1
  877. 1
  878. 1
  879. 1
  880. 1
  881. 1
  882. 1
  883. 1
  884. 1
  885. 1
  886. 1
  887. 1
  888. 1
  889. 1
  890. 1
  891. 1
  892. 1
  893. 1
  894. 0
  895. 1
  896. 1
  897. 2
  898. 1
  899. 1
  900. 1
  901. 1
  902. 1
  903. 1
  904. 1
  905. 1
  906. 1
  907. 1
  908. 1
  909. 1
  910. 1
  911. 0
  912. 1
  913. 1
  914. 1
  915. 1
  916. 1
  917. 1
  918. 1
  919. 1
  920. 0
  921. 1
  922. 1
  923. 1
  924. 1
  925. 1
  926. 0
  927. 0
  928. 1
  929. 1
  930. 1
  931. 1
  932. 1
  933. 1
  934. 1
  935. 0
  936. 1
  937. 1
  938. 1
  939. 1
  940. 1
  941. 1
  942. 1
  943. 1
  944. 0
  945. 0
  946. 1
  947. 1
  948. 1
  949. 1
  950. 1
  951. 1
  952. 1
  953. 1
  954. 1
  955. 1
  956. 1
  957. 1
  958. 1
  959. 1
  960. 1
  961. 0
  962. 0
  963. 1
  964. 1
  965. 1
  966. 1
  967. 1
  968. 1
  969. 1
  970. 1
  971. 1
  972. 1
  973. 1
  974. 1
  975. 1
  976. 1
  977. 1
  978. 1
  979. 1
  980. 0
  981. 0
  982. 0
  983. 1
  984. 0
  985. 1
  986. 1
  987. 1
  988. 1
  989. 1
  990. 1
  991. 1
  992. 1
  993. 1
  994. 1
  995. 0
  996. 1
  997. 1
  998. 1
  999. 1
  1000. 1
  1001. 1
  1002. 1
  1003. 1
  1004. 1
  1005. 1
  1006. 1
  1007. 1
  1008. 0
  1009. 1
  1010. 1
  1011. 1
  1012. 0
  1013. 1
  1014. 1
  1015. 0
  1016. 1
  1017. 1
  1018. 1
  1019. 1
  1020. 0
  1021. 1
  1022. 1
  1023. 0
  1024. 1
  1025. 1
  1026. 1
  1027. 1
  1028. 1
  1029. 1
  1030. 1
  1031. 1
  1032. 0
  1033. 1
  1034. 1
  1035. 6
  1036. 1
  1037. 1
  1038. 1
  1039. 1
  1040. 2
  1041. 1
  1042. 1
  1043. 1
  1044. 1
  1045. 1
  1046. 2
  1047. 2
  1048. 0
  1049. 2
  1050. 2
  1051. 1
  1052. 1
  1053. 1
  1054. 1
  1055. 1
  1056. 1
  1057. 1
  1058. 0
  1059. 1
  1060. 1
  1061. 1
  1062. 1
  1063. 1
  1064. 1
  1065. 1
  1066. 1
  1067. 2
  1068. 0
  1069. 2
  1070. 2
  1071. 2
  1072. 1
  1073. 0
  1074. 1
  1075. 1
  1076. 1
  1077. 1
  1078. 1
  1079. 0
  1080. 1
  1081. 1
  1082. 1
  1083. 1
  1084. 1
  1085. 1
  1086. 1
  1087. 1
  1088. 1
  1089. 1
  1090. 1
  1091. 1
  1092. 1
  1093. 1
  1094. 1
  1095. 1
  1096. 1
  1097. 1
  1098. 1
  1099. 1
  1100. 1
  1101. 1
  1102. 1
  1103. 1
  1104. 1
  1105. 1
  1106. 1
  1107. 1
  1108. 1
  1109. 1
  1110. 1
  1111. 0
  1112. 1
  1113. 2
  1114. 2
  1115. 2
  1116. 2
  1117. 2
  1118. 2
  1119. 2
  1120. 1
  1121. 1
  1122. 1
  1123. 0
  1124. 0
  1125. 1
  1126. 1
  1127. 1
  1128. 1
  1129. 1
  1130. 1
  1131. 1
  1132. 1
  1133. 1
  1134. 1
  1135. 1
  1136. 1
  1137. 1
  1138. 1
  1139. 1
  1140. 1
  1141. 1
  1142. 1
  1143. 1
  1144. 1
  1145. 1
  1146. 1
  1147. 2
  1148. 2
  1149. 1
  1150. 1
  1151. 1
  1152. 1
  1153. 1
  1154. 1
  1155. 1
  1156. 1
  1157. 1
  1158. 1
  1159. 2
  1160. 2
  1161. 1
  1162. 1
  1163. 2
  1164. 0
  1165. 1
  1166. 0
  1167. 1

Calculate average source and author degree:


In [42]:
# average author degree (person types 2 and 4)
gmAutomatedAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gmAutomatedDataDF, includeBothIN = TRUE )
message( paste( "grp_month automated average author degree (2 and 4) = ", gmAutomatedAverageAuthorDegree2And4, sep = "" ) )

# average author degree (person type 2 only)
gmAutomatedAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gmAutomatedDataDF, includeBothIN = FALSE )
message( paste( "grp_month automated average author degree (only 2) = ", gmAutomatedAverageAuthorDegreeOnly2, sep = "" ) )

# average source degree (person types 3 and 4)
gmAutomatedAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gmAutomatedDataDF, includeBothIN = TRUE )
message( paste( "grp_month automated average source degree (3 and 4) = ", gmAutomatedAverageSourceDegree3And4, sep = "" ) )

# average source degree (person type 3 only)
gmAutomatedAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gmAutomatedDataDF, includeBothIN = FALSE )
message( paste( "grp_month automated average source degree (only 3) = ", gmAutomatedAverageSourceDegreeOnly3, sep = "" ) )


grp_month automated average author degree (2 and 4) = 24.8297872340426
grp_month automated average author degree (only 2) = 24.8478260869565
grp_month automated average source degree (3 and 4) = 1.163
grp_month automated average source degree (only 3) = 1.14014014014014

More metrics

Once we get the data into an igraph object, run the code in the following for more in-depth information:

context_text/R/sna/statnet/sna-igraph-init.r
context_text/R/sna/statnet/sna-igraph-network-stats.r

In [43]:
# First, need to load SNA functions and load data into statnet network object.
#    For more details on that, see the files "functions-sna.r",
#    "sna-load_data.r" and "sna-igraph_init.r".
#
# assumes that working directory for statnet is context_text/R/igraph
# setwd( ".." )
# source( "functions-sna.r" )
# source( "sna-load_data.r" )
# setwd( "igraph" )
# source( "sna-igraph-init.r" )

# results in (among other things):
# - humanNetworkData - data frame with human-generated network data matrix in it, including columns on the right side for any node-specific attributes.
# - calaisNetworkData - data frame with computer-generated network data matrix in it, including columns on the right side for any node-specific attributes.
# - humanNetworkTies - data frame with only human-generated network data matrix in it, no node-specific attributes.
# - calaisNetworkTies - data frame with only computer-generated network data matrix in it, no node-specific attributes.
# - humanNetworkMatrix - matrix with only human-generated network data matrix in it, no node-specific attributes.
# - calaisNetworkMatrix - matrix with only computer-generated network data matrix in it, no node-specific attributes.
# - humanNetworkIgraph - igraph network with human-coded network in it, including node-specific attributes.
# - calaisNetworkIgraph - igraph network with computer-coded network in it, including node-specific attributes.

# Links:
# - CRAN page: http://cran.r-project.org/web/packages/igraph/index.html
# - Manual (PDF): http://cran.r-project.org/web/packages/igraph/igraph.pdf
# - intro.: http://horicky.blogspot.com/2012/04/basic-graph-analytics-using-igraph.html
# - good notes: http://www.shizukalab.com/toolkits/sna/node-level-calculations

# Also, be advised that statnet and igraph don't really play nice together.
#    If you'll be using both, best idea is to have a workspace for each.

#==============================================================================#
# igraph
#==============================================================================#

# Good notes:
# - http://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/

# make sure you've loaded the igraph library
# install.packages( "igraph" )
library( igraph )

#==============================================================================#
# NODE level
#==============================================================================#

# calculate the mean of the degrees.
gmAutomatedDegreeMean <- gmAutomatedAvgDegree
message( paste( "grp_month automated degree mean = ", gmAutomatedDegreeMean, sep = "" ) )

# what is the standard deviation of these degrees?
gmAutomatedDegreeSd <- sd( gmAutomatedDegreeVector )
message( paste( "grp_month automated degree SD = ", gmAutomatedDegreeSd, sep = "" ) )

# what is the variance of these degrees?
gmAutomatedDegreeVar <- var( gmAutomatedDegreeVector )
message( paste( "grp_month automated degree Variance = ", gmAutomatedDegreeVar, sep = "" ) )

# what is the max value among these degrees?
gmAutomatedDegreeMax <- max( gmAutomatedDegreeVector )
message( paste( "grp_month automated degree Max Value = ", gmAutomatedDegreeMax, sep = "" ) )

# calculate and plot degree distributions
gmAutomatedDegreeFrequenciesTable <- table( gmAutomatedDegreeVector )
gmAutomatedDegreeDistribution <- igraph::degree.distribution( gmAutomatedNetworkIgraph )
plot( gmAutomatedDegreeDistribution, xlab = "grp_month automated node degree" )
lines( gmAutomatedDegreeDistribution )

# subset vector to get only those that are above mean
gmAutomatedAboveMeanVector <- gmAutomatedDegreeVector[ gmAutomatedDegreeVector > gmAutomatedDegreeMax ]

# node-level transitivity
# create transitivity vectors.
gmAutomatedTransitivityVector <- igraph::transitivity( gmAutomatedNetworkIgraph, type = "local" )

# append the transitivity to the network as a vertex attribute.
V( gmAutomatedNetworkIgraph )$transitivity <- gmAutomatedTransitivityVector

# also add transitivity vector to original data frame
gmAutomatedDataDF$transitivity <- gmAutomatedTransitivityVector

# And, if you want averages of these:
gmAutomatedMeanTransitivity <- mean( gmAutomatedTransitivityVector, na.rm = TRUE )
message( paste( "grp_month automated mean transitivity = ", gmAutomatedMeanTransitivity, sep = "" ) )

#==============================================================================#
# NETWORK level
#==============================================================================#

#------------------------------------------------------------------------------#
# ==> graph-level degree centrality
#
# Returns a named list with the following components:
# res - The node-level centrality scores
# centralization - The graph level centrality index.
# theoretical_max - The maximum theoretical graph level centralization score
#     for a graph with the given number of vertices, using the same parameters.
#     If the normalized argument was TRUE (the default), then the result was
#     divided by this number.
gmAutomatedDegreeCentralityOutput <- igraph::centralization.degree( gmAutomatedNetworkIgraph )
gmAutomatedDegreeCentrality <- gmAutomatedDegreeCentralityOutput$centralization
gmAutomatedDegreeCentralityMax <- gmAutomatedDegreeCentralityOutput$theoretical_max
message( paste( "grp_month automated degree centrality = ", gmAutomatedDegreeCentrality, " ( max = ", gmAutomatedDegreeCentralityMax, " )", sep = "" ) )

# node-level degree centrality
gmAutomatedDegreeCentralityVector <- gmAutomatedDegreeCentralityOutput$res
#message( paste( "grp_month automated betweenness = ", gmAutomatedBetweenness, sep = "" ) )

# append the degree centrality to the network as a vertex attribute.
V( gmAutomatedNetworkIgraph )$degreeCentrality <- gmAutomatedDegreeCentralityVector

# also add degree centrality vector to original data frame
gmAutomatedDataDF$degreeCentrality <- gmAutomatedDegreeCentralityVector

# And, if you want averages of these:
gmAutomatedMeanDegreeCentrality <- mean( gmAutomatedDegreeCentralityVector, na.rm = TRUE )
message( paste( "grp_month automated mean degree centrality = ", gmAutomatedMeanDegreeCentrality, sep = "" ) )

#------------------------------------------------------------------------------#
# ==> graph-level undirected betweenness
#
# Returns a named list with the following components:
# res - The node-level centrality scores
# centralization - The graph level centrality index.
# theoretical_max - The maximum theoretical graph level centralization score
#     for a graph with the given number of vertices, using the same parameters.
#     If the normalized argument was TRUE (the default), then the result was
#     divided by this number.
gmAutomatedBetweennessCentralityOutput <- igraph::centralization.betweenness( gmAutomatedNetworkIgraph, directed = FALSE )
gmAutomatedBetweennessCentrality <- gmAutomatedBetweennessCentralityOutput$centralization
gmAutomatedBetweennessCentralityMax <- gmAutomatedBetweennessCentralityOutput$theoretical_max
message( paste( "grp_month automated betweenness centrality = ", gmAutomatedBetweennessCentrality, " ( max = ", gmAutomatedBetweennessCentralityMax, " )", sep = "" ) )

# node-level undirected betweenness
gmAutomatedBetweennessVector <- gmAutomatedBetweennessCentralityOutput$res
#message( paste( "grp_month automated betweenness = ", gmAutomatedBetweenness, sep = "" ) )

# append the betweenness to the network as a vertex attribute.
V( gmAutomatedNetworkIgraph )$betweenness <- gmAutomatedBetweennessVector

# also add betweenness vector to original data frame
gmAutomatedDataDF$betweenness <- gmAutomatedBetweennessVector

# And, if you want averages of these:
gmAutomatedMeanBetweenness <- mean( gmAutomatedBetweennessVector, na.rm = TRUE )
message( paste( "grp_month automated mean betweenness = ", gmAutomatedMeanBetweenness, sep = "" ) )

# graph-level transitivity
gmAutomatedTransitivity <- igraph::transitivity( gmAutomatedNetworkIgraph, type = "global" )
message( paste( "grp_month automated transitivity = ", gmAutomatedTransitivity, sep = "" ) )

# graph-level density
gmAutomatedDensity <- igraph::graph.density( gmAutomatedNetworkIgraph )
message( paste( "grp_month automated density = ", gmAutomatedDensity, sep = "" ) )

#==============================================================================#
# output attributes to data frame
#==============================================================================#

# if you want to just work with the traits of the nodes/vertexes, you can
#    combine the attribute vectors into a data frame.

# first, output igraph object to see what attributes you have
gmAutomatedNetworkIgraph

# then, combine them into a data frame.
gmAutomatedAttributeDF <- data.frame( id = V( gmAutomatedNetworkIgraph )$name,
                                      person_id = V( gmAutomatedNetworkIgraph )$person_id,
                                      person_type = V( gmAutomatedNetworkIgraph )$person_type,
                                      degree = V( gmAutomatedNetworkIgraph )$degree,
                                      transitivity = V( gmAutomatedNetworkIgraph )$transitivity,
                                      degreeCentrality = V( gmAutomatedNetworkIgraph )$degreeCentrality,
                                      betweenness = V( gmAutomatedNetworkIgraph )$betweenness )


grp_month automated degree mean = 1.97600685518423
grp_month automated degree SD = 6.43021172327381
grp_month automated degree Variance = 41.3476228061279
grp_month automated degree Max Value = 93
grp_month automated mean transitivity = 0.424735508579124
grp_month automated degree centrality = 0.0780651742236842 ( max = 1360722 )
grp_month automated mean degree centrality = 1.97600685518423
grp_month automated betweenness centrality = 0.206660606881935 ( max = 791941370 )
grp_month automated mean betweenness = 1342.06512425021
grp_month automated transitivity = 0.00893353450329548
grp_month automated density = 0.00169468855504651
IGRAPH 69a72c9 UNW- 1167 1153 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), degree (v/n),
| transitivity (v/n), degreeCentrality (v/n), betweenness (v/n), weight
| (e/n)
+ edges from 69a72c9 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--308__589__source-3  1__3__author-2--348__774__source-3 
 [9] 1__3__author-2--368__1080__source-3 1__3__author-2--388__1419__source-3
[11] 1__3__author-2--393__1451__source-3 1__3__author-2--672__2100__source-3
+ ... omitted several edges

In [44]:
?igraph::centralization.betweenness

grp_month (gm) - human

Next, we'll analyze the month of data coded by humans. Set up some variables to store where data is located:


In [45]:
# initialize variables
gmHumanDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gmHumanDataFile <- "sourcenet_data-20171115-043102-grp_month-human.tab"
gmHumanDataPath <- paste( gmHumanDataFolder, "/", gmHumanDataFile, sep = "" )

In [46]:
gmHumanDataPath


'/home/jonathanmorgan/work/django/research/work/phd_work/methods/data/network/grp_month/sourcenet_data-20171115-043102-grp_month-human.tab'

Load the data file into memory


In [47]:
# tab-delimited:
gmHumanDataDF <- read.delim( gmHumanDataPath, header = TRUE, row.names = 1, check.names = FALSE )

In [48]:
# get count of rows...
gmHumanRowCount <- nrow( gmHumanDataDF )
paste( "grp_month human row count = ", gmHumanRowCount, sep = "" )

# ...and columns
gmHumanColumnCount <- ncol( gmHumanDataDF )
paste( "grp_month human column count = ", gmHumanColumnCount, sep = "" )


'grp_month human row count = 1167'
'grp_month human column count = 1169'

Get just the tie rows and columns for initializing network libraries.


In [49]:
# the below syntax returns only as many columns as there are rows, so
#     omitting any trait columns that lie in columns on the right side
#     of the file.
gmHumanNetworkDF <- gmHumanDataDF[ , 1 : gmHumanRowCount ]
#str( gmAutomatedNetworkDF )

In [50]:
# convert to a matrix
gmHumanNetworkMatrix <- as.matrix( gmHumanNetworkDF )
# str( gmHumanNetworkMatrix )

Initialize igraph

First, load the igraph package.

Once we get the data into an igraph object, run the code in the following for more in-depth information:

  • context_text/R/sna/statnet/sna-igraph-init.r
  • context_text/R/sna/statnet/sna-igraph-network-stats.r

In [51]:
#install.packages( "igraph" )
library( igraph )

Load our data matrix into an igraph object.


In [52]:
# load data into igraph instance.
gmHumanNetworkIgraph <- graph.adjacency( gmHumanNetworkMatrix, mode = "undirected", weighted = TRUE )

In [53]:
# add person_id (column 1168)
personIdColumnNumber <- 1168

# first, get just the data frame column with person ID:
personIdsColumn <- gmHumanDataDF[ , personIdColumnNumber ]

# populate list we will use to set node person_ID attribute

# Don't just do these - they don't convert to simple list/vector, contain remnants of data frame
#personIdsList <- personIdsColumn
#personIdsList <- c( personIdsColumn )

# Convert to a list of numbers.
personIdsList <- as.numeric( personIdsColumn )

# Try this if you have character attribute...
#personTypesList <- unname( unlist( personTypesColumn ) )

# set vertex/node attribute person_id
V( gmHumanNetworkIgraph )$person_id <- personIdsList

# OR use function:
#gmHumanNetworkIgraph <- set.vertex.attribute( gmHumanNetworkIgraph, "person_id", value = personIdsList )

# look at graph and person_type attribute values
gmHumanNetworkIgraph
V( gmHumanNetworkIgraph )$person_id


IGRAPH 57ebbb5 UNW- 1167 1201 -- 
+ attr: name (v/c), person_id (v/n), weight (e/n)
+ edges from 57ebbb5 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--307__588__source-3  1__3__author-2--308__589__source-3 
 [9] 1__3__author-2--362__959__source-3  1__3__author-2--368__1080__source-3
[11] 1__3__author-2--388__1419__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
[15] 1__3__author-2--808__2271__source-3 1__3__author-2--809__2272__source-3
+ ... omitted several edges
  1. 3
  2. 12
  3. 13
  4. 15
  5. 23
  6. 24
  7. 25
  8. 29
  9. 30
  10. 32
  11. 36
  12. 37
  13. 46
  14. 51
  15. 53
  16. 66
  17. 69
  18. 73
  19. 74
  20. 84
  21. 100
  22. 102
  23. 131
  24. 132
  25. 137
  26. 138
  27. 161
  28. 162
  29. 163
  30. 164
  31. 165
  32. 166
  33. 172
  34. 173
  35. 174
  36. 175
  37. 176
  38. 178
  39. 179
  40. 180
  41. 181
  42. 182
  43. 184
  44. 187
  45. 188
  46. 204
  47. 213
  48. 215
  49. 217
  50. 218
  51. 219
  52. 223
  53. 225
  54. 234
  55. 236
  56. 237
  57. 239
  58. 250
  59. 268
  60. 269
  61. 271
  62. 272
  63. 273
  64. 274
  65. 275
  66. 276
  67. 277
  68. 289
  69. 290
  70. 292
  71. 295
  72. 302
  73. 305
  74. 307
  75. 308
  76. 309
  77. 310
  78. 311
  79. 312
  80. 319
  81. 320
  82. 321
  83. 322
  84. 323
  85. 324
  86. 325
  87. 326
  88. 327
  89. 328
  90. 329
  91. 330
  92. 331
  93. 332
  94. 333
  95. 334
  96. 335
  97. 336
  98. 337
  99. 338
  100. 339
  101. 340
  102. 343
  103. 344
  104. 345
  105. 346
  106. 347
  107. 349
  108. 350
  109. 351
  110. 352
  111. 353
  112. 354
  113. 355
  114. 356
  115. 357
  116. 358
  117. 360
  118. 361
  119. 362
  120. 363
  121. 364
  122. 365
  123. 366
  124. 367
  125. 368
  126. 369
  127. 370
  128. 371
  129. 372
  130. 373
  131. 374
  132. 375
  133. 376
  134. 377
  135. 378
  136. 379
  137. 380
  138. 381
  139. 382
  140. 383
  141. 384
  142. 385
  143. 386
  144. 387
  145. 388
  146. 389
  147. 390
  148. 391
  149. 392
  150. 393
  151. 394
  152. 395
  153. 396
  154. 397
  155. 398
  156. 399
  157. 400
  158. 401
  159. 402
  160. 403
  161. 404
  162. 405
  163. 406
  164. 407
  165. 408
  166. 410
  167. 411
  168. 412
  169. 413
  170. 414
  171. 415
  172. 416
  173. 417
  174. 418
  175. 419
  176. 425
  177. 437
  178. 438
  179. 439
  180. 440
  181. 441
  182. 442
  183. 443
  184. 444
  185. 445
  186. 446
  187. 447
  188. 448
  189. 449
  190. 450
  191. 451
  192. 452
  193. 453
  194. 454
  195. 455
  196. 456
  197. 460
  198. 461
  199. 462
  200. 463
  201. 464
  202. 466
  203. 467
  204. 468
  205. 469
  206. 470
  207. 471
  208. 472
  209. 473
  210. 474
  211. 475
  212. 476
  213. 477
  214. 478
  215. 479
  216. 480
  217. 481
  218. 482
  219. 484
  220. 485
  221. 486
  222. 487
  223. 488
  224. 489
  225. 490
  226. 491
  227. 498
  228. 499
  229. 500
  230. 501
  231. 502
  232. 503
  233. 505
  234. 506
  235. 507
  236. 508
  237. 509
  238. 510
  239. 511
  240. 512
  241. 513
  242. 514
  243. 515
  244. 516
  245. 517
  246. 518
  247. 519
  248. 520
  249. 521
  250. 522
  251. 523
  252. 524
  253. 525
  254. 526
  255. 527
  256. 528
  257. 529
  258. 530
  259. 531
  260. 532
  261. 534
  262. 535
  263. 536
  264. 537
  265. 538
  266. 539
  267. 541
  268. 542
  269. 543
  270. 544
  271. 545
  272. 546
  273. 547
  274. 548
  275. 549
  276. 551
  277. 552
  278. 553
  279. 554
  280. 555
  281. 556
  282. 557
  283. 558
  284. 559
  285. 560
  286. 561
  287. 562
  288. 563
  289. 564
  290. 565
  291. 566
  292. 567
  293. 568
  294. 569
  295. 570
  296. 571
  297. 572
  298. 574
  299. 575
  300. 576
  301. 579
  302. 580
  303. 581
  304. 582
  305. 583
  306. 585
  307. 588
  308. 589
  309. 591
  310. 598
  311. 599
  312. 617
  313. 618
  314. 620
  315. 633
  316. 637
  317. 652
  318. 654
  319. 660
  320. 664
  321. 668
  322. 669
  323. 686
  324. 703
  325. 714
  326. 736
  327. 743
  328. 750
  329. 752
  330. 753
  331. 757
  332. 758
  333. 759
  334. 760
  335. 761
  336. 762
  337. 763
  338. 764
  339. 765
  340. 766
  341. 767
  342. 768
  343. 769
  344. 770
  345. 771
  346. 772
  347. 773
  348. 774
  349. 775
  350. 776
  351. 777
  352. 778
  353. 779
  354. 780
  355. 848
  356. 852
  357. 901
  358. 904
  359. 937
  360. 949
  361. 954
  362. 959
  363. 971
  364. 1043
  365. 1044
  366. 1056
  367. 1059
  368. 1080
  369. 1082
  370. 1109
  371. 1113
  372. 1133
  373. 1152
  374. 1183
  375. 1203
  376. 1205
  377. 1206
  378. 1207
  379. 1286
  380. 1287
  381. 1289
  382. 1298
  383. 1299
  384. 1318
  385. 1319
  386. 1343
  387. 1348
  388. 1419
  389. 1441
  390. 1442
  391. 1443
  392. 1445
  393. 1451
  394. 1453
  395. 1457
  396. 1458
  397. 1476
  398. 1479
  399. 1544
  400. 1546
  401. 1547
  402. 1548
  403. 1576
  404. 1591
  405. 1642
  406. 1655
  407. 1674
  408. 1687
  409. 1688
  410. 1689
  411. 1690
  412. 1691
  413. 1692
  414. 1693
  415. 1694
  416. 1695
  417. 1696
  418. 1697
  419. 1700
  420. 1703
  421. 1704
  422. 1705
  423. 1707
  424. 1708
  425. 1711
  426. 1712
  427. 1713
  428. 1714
  429. 1717
  430. 1718
  431. 1719
  432. 1720
  433. 1721
  434. 1722
  435. 1723
  436. 1724
  437. 1725
  438. 1726
  439. 1727
  440. 1728
  441. 1729
  442. 1730
  443. 1732
  444. 1733
  445. 1734
  446. 1735
  447. 1736
  448. 1737
  449. 1739
  450. 1740
  451. 1741
  452. 1743
  453. 1745
  454. 1746
  455. 1747
  456. 1749
  457. 1750
  458. 1752
  459. 1753
  460. 1754
  461. 1756
  462. 1757
  463. 1758
  464. 1759
  465. 1760
  466. 1761
  467. 1762
  468. 1765
  469. 1766
  470. 1767
  471. 1768
  472. 1769
  473. 1770
  474. 1772
  475. 1775
  476. 1778
  477. 1779
  478. 1782
  479. 1783
  480. 1784
  481. 1786
  482. 1787
  483. 1793
  484. 1794
  485. 1795
  486. 1796
  487. 1798
  488. 1800
  489. 1801
  490. 1803
  491. 1805
  492. 1806
  493. 1807
  494. 1808
  495. 1810
  496. 1811
  497. 1814
  498. 1815
  499. 1816
  500. 1817
  501. 1818
  502. 1819
  503. 1821
  504. 1823
  505. 1824
  506. 1825
  507. 1826
  508. 1827
  509. 1828
  510. 1829
  511. 1830
  512. 1831
  513. 1832
  514. 1833
  515. 1834
  516. 1835
  517. 1836
  518. 1837
  519. 1838
  520. 1839
  521. 1840
  522. 1841
  523. 1842
  524. 1843
  525. 1844
  526. 1845
  527. 1846
  528. 1847
  529. 1848
  530. 1849
  531. 1850
  532. 1851
  533. 1852
  534. 1853
  535. 1854
  536. 1855
  537. 1856
  538. 1857
  539. 1858
  540. 1859
  541. 1860
  542. 1861
  543. 1862
  544. 1863
  545. 1864
  546. 1865
  547. 1866
  548. 1867
  549. 1871
  550. 1872
  551. 1873
  552. 1874
  553. 1875
  554. 1880
  555. 1882
  556. 1883
  557. 1884
  558. 1886
  559. 1888
  560. 1889
  561. 1890
  562. 1891
  563. 1892
  564. 1899
  565. 1900
  566. 1901
  567. 1902
  568. 1903
  569. 1904
  570. 1905
  571. 1906
  572. 1907
  573. 1908
  574. 1911
  575. 1913
  576. 1931
  577. 1933
  578. 1955
  579. 1956
  580. 1960
  581. 1961
  582. 1962
  583. 1963
  584. 1964
  585. 1965
  586. 1966
  587. 1967
  588. 1972
  589. 1973
  590. 1974
  591. 1977
  592. 1978
  593. 1979
  594. 1980
  595. 1981
  596. 1982
  597. 1983
  598. 1984
  599. 1986
  600. 1988
  601. 1990
  602. 1991
  603. 1992
  604. 1994
  605. 1998
  606. 1999
  607. 2000
  608. 2001
  609. 2002
  610. 2003
  611. 2004
  612. 2008
  613. 2009
  614. 2012
  615. 2013
  616. 2014
  617. 2015
  618. 2016
  619. 2018
  620. 2019
  621. 2022
  622. 2023
  623. 2024
  624. 2025
  625. 2026
  626. 2027
  627. 2028
  628. 2029
  629. 2030
  630. 2031
  631. 2032
  632. 2034
  633. 2035
  634. 2036
  635. 2037
  636. 2038
  637. 2039
  638. 2040
  639. 2041
  640. 2042
  641. 2043
  642. 2044
  643. 2045
  644. 2046
  645. 2047
  646. 2048
  647. 2052
  648. 2054
  649. 2055
  650. 2056
  651. 2060
  652. 2064
  653. 2068
  654. 2069
  655. 2071
  656. 2073
  657. 2075
  658. 2076
  659. 2077
  660. 2078
  661. 2079
  662. 2080
  663. 2081
  664. 2087
  665. 2091
  666. 2094
  667. 2095
  668. 2096
  669. 2097
  670. 2098
  671. 2099
  672. 2100
  673. 2101
  674. 2102
  675. 2104
  676. 2105
  677. 2106
  678. 2107
  679. 2108
  680. 2110
  681. 2111
  682. 2112
  683. 2113
  684. 2114
  685. 2116
  686. 2118
  687. 2119
  688. 2120
  689. 2121
  690. 2126
  691. 2127
  692. 2128
  693. 2129
  694. 2130
  695. 2131
  696. 2132
  697. 2134
  698. 2136
  699. 2137
  700. 2138
  701. 2139
  702. 2140
  703. 2141
  704. 2142
  705. 2143
  706. 2144
  707. 2147
  708. 2148
  709. 2149
  710. 2150
  711. 2151
  712. 2152
  713. 2153
  714. 2154
  715. 2155
  716. 2156
  717. 2157
  718. 2158
  719. 2159
  720. 2160
  721. 2161
  722. 2162
  723. 2163
  724. 2164
  725. 2166
  726. 2167
  727. 2168
  728. 2169
  729. 2170
  730. 2171
  731. 2172
  732. 2173
  733. 2174
  734. 2175
  735. 2176
  736. 2177
  737. 2178
  738. 2181
  739. 2182
  740. 2185
  741. 2186
  742. 2187
  743. 2188
  744. 2189
  745. 2190
  746. 2191
  747. 2192
  748. 2193
  749. 2195
  750. 2196
  751. 2197
  752. 2198
  753. 2199
  754. 2201
  755. 2202
  756. 2203
  757. 2204
  758. 2205
  759. 2206
  760. 2207
  761. 2208
  762. 2209
  763. 2210
  764. 2211
  765. 2212
  766. 2213
  767. 2214
  768. 2216
  769. 2218
  770. 2219
  771. 2220
  772. 2221
  773. 2222
  774. 2223
  775. 2224
  776. 2225
  777. 2226
  778. 2229
  779. 2231
  780. 2232
  781. 2233
  782. 2234
  783. 2235
  784. 2245
  785. 2246
  786. 2247
  787. 2248
  788. 2249
  789. 2250
  790. 2251
  791. 2252
  792. 2253
  793. 2254
  794. 2255
  795. 2256
  796. 2257
  797. 2258
  798. 2259
  799. 2261
  800. 2262
  801. 2263
  802. 2264
  803. 2265
  804. 2266
  805. 2267
  806. 2268
  807. 2269
  808. 2271
  809. 2272
  810. 2277
  811. 2278
  812. 2280
  813. 2288
  814. 2289
  815. 2290
  816. 2291
  817. 2292
  818. 2293
  819. 2294
  820. 2295
  821. 2296
  822. 2297
  823. 2298
  824. 2299
  825. 2300
  826. 2301
  827. 2303
  828. 2306
  829. 2307
  830. 2308
  831. 2310
  832. 2311
  833. 2312
  834. 2313
  835. 2314
  836. 2315
  837. 2316
  838. 2317
  839. 2318
  840. 2319
  841. 2320
  842. 2321
  843. 2322
  844. 2323
  845. 2324
  846. 2325
  847. 2326
  848. 2329
  849. 2330
  850. 2331
  851. 2332
  852. 2338
  853. 2340
  854. 2341
  855. 2342
  856. 2346
  857. 2347
  858. 2348
  859. 2350
  860. 2351
  861. 2352
  862. 2353
  863. 2354
  864. 2355
  865. 2356
  866. 2358
  867. 2359
  868. 2360
  869. 2361
  870. 2362
  871. 2363
  872. 2364
  873. 2366
  874. 2367
  875. 2368
  876. 2369
  877. 2370
  878. 2371
  879. 2373
  880. 2374
  881. 2375
  882. 2379
  883. 2383
  884. 2386
  885. 2387
  886. 2388
  887. 2389
  888. 2390
  889. 2391
  890. 2392
  891. 2393
  892. 2397
  893. 2398
  894. 2399
  895. 2400
  896. 2401
  897. 2402
  898. 2403
  899. 2404
  900. 2405
  901. 2406
  902. 2407
  903. 2408
  904. 2409
  905. 2410
  906. 2411
  907. 2412
  908. 2413
  909. 2414
  910. 2415
  911. 2419
  912. 2430
  913. 2431
  914. 2432
  915. 2433
  916. 2434
  917. 2435
  918. 2437
  919. 2438
  920. 2439
  921. 2440
  922. 2441
  923. 2442
  924. 2443
  925. 2444
  926. 2445
  927. 2446
  928. 2447
  929. 2450
  930. 2455
  931. 2456
  932. 2457
  933. 2458
  934. 2459
  935. 2460
  936. 2461
  937. 2463
  938. 2466
  939. 2470
  940. 2471
  941. 2472
  942. 2473
  943. 2475
  944. 2476
  945. 2480
  946. 2481
  947. 2482
  948. 2485
  949. 2486
  950. 2488
  951. 2489
  952. 2490
  953. 2491
  954. 2492
  955. 2493
  956. 2494
  957. 2495
  958. 2496
  959. 2497
  960. 2498
  961. 2499
  962. 2501
  963. 2502
  964. 2503
  965. 2507
  966. 2509
  967. 2510
  968. 2511
  969. 2512
  970. 2513
  971. 2514
  972. 2515
  973. 2516
  974. 2517
  975. 2522
  976. 2523
  977. 2524
  978. 2525
  979. 2526
  980. 2527
  981. 2528
  982. 2529
  983. 2530
  984. 2531
  985. 2532
  986. 2534
  987. 2536
  988. 2537
  989. 2538
  990. 2539
  991. 2540
  992. 2544
  993. 2546
  994. 2547
  995. 2548
  996. 2549
  997. 2551
  998. 2552
  999. 2553
  1000. 2555
  1001. 2556
  1002. 2557
  1003. 2558
  1004. 2560
  1005. 2562
  1006. 2563
  1007. 2566
  1008. 2567
  1009. 2568
  1010. 2569
  1011. 2570
  1012. 2571
  1013. 2573
  1014. 2574
  1015. 2576
  1016. 2577
  1017. 2586
  1018. 2587
  1019. 2589
  1020. 2591
  1021. 2592
  1022. 2593
  1023. 2594
  1024. 2599
  1025. 2601
  1026. 2602
  1027. 2603
  1028. 2604
  1029. 2605
  1030. 2606
  1031. 2608
  1032. 2609
  1033. 2610
  1034. 2611
  1035. 2614
  1036. 2615
  1037. 2616
  1038. 2617
  1039. 2618
  1040. 2619
  1041. 2621
  1042. 2622
  1043. 2623
  1044. 2624
  1045. 2625
  1046. 2626
  1047. 2627
  1048. 2628
  1049. 2629
  1050. 2630
  1051. 2631
  1052. 2632
  1053. 2633
  1054. 2634
  1055. 2635
  1056. 2636
  1057. 2637
  1058. 2638
  1059. 2639
  1060. 2643
  1061. 2644
  1062. 2650
  1063. 2651
  1064. 2652
  1065. 2653
  1066. 2654
  1067. 2655
  1068. 2656
  1069. 2657
  1070. 2658
  1071. 2660
  1072. 2661
  1073. 2662
  1074. 2663
  1075. 2664
  1076. 2665
  1077. 2666
  1078. 2667
  1079. 2668
  1080. 2669
  1081. 2670
  1082. 2671
  1083. 2673
  1084. 2675
  1085. 2677
  1086. 2680
  1087. 2684
  1088. 2685
  1089. 2686
  1090. 2692
  1091. 2693
  1092. 2694
  1093. 2700
  1094. 2701
  1095. 2708
  1096. 2709
  1097. 2710
  1098. 2711
  1099. 2712
  1100. 2713
  1101. 2714
  1102. 2715
  1103. 2716
  1104. 2717
  1105. 2718
  1106. 2719
  1107. 2720
  1108. 2721
  1109. 2722
  1110. 2726
  1111. 2727
  1112. 2728
  1113. 2729
  1114. 2730
  1115. 2731
  1116. 2733
  1117. 2734
  1118. 2735
  1119. 2736
  1120. 2737
  1121. 2738
  1122. 2739
  1123. 2740
  1124. 2744
  1125. 2745
  1126. 2746
  1127. 2749
  1128. 2797
  1129. 2807
  1130. 2809
  1131. 2813
  1132. 2816
  1133. 2820
  1134. 2822
  1135. 2828
  1136. 2829
  1137. 2834
  1138. 2835
  1139. 2850
  1140. 2851
  1141. 2862
  1142. 2866
  1143. 2867
  1144. 2868
  1145. 2871
  1146. 2886
  1147. 2893
  1148. 2895
  1149. 2903
  1150. 2907
  1151. 2911
  1152. 2912
  1153. 2914
  1154. 2915
  1155. 2916
  1156. 2917
  1157. 2929
  1158. 2932
  1159. 2934
  1160. 2935
  1161. 2937
  1162. 2953
  1163. 2957
  1164. 2960
  1165. 2962
  1166. 2968
  1167. 2970

In [54]:
# add person_type (column 1169)
personTypeColumnNumber <- 1169

# first, get just the data frame column with person type:
personTypesColumn <- gmHumanDataDF[ , personTypeColumnNumber ]

# populate list we will use to set node person_type attribute

# Don't just do these - they don't convert to simple list/vector, contain remnants of data frame
#personTypesList <- personTypesColumn
#personTypesList <- c( personTypesColumn )

# Convert to a list of numbers.
personTypesList <- as.numeric( personTypesColumn )

# Try this if you have character attribute...
#personTypesList <- unname( unlist( personTypesColumn ) )

# set vertex/node attribute person_type
V( gmHumanNetworkIgraph )$person_type <- personTypesList

# OR use function:
#test1_igraph <- set.vertex.attribute( test1_igraph, "person_type", value = person_types_list )

# look at graph and person_type attribute values
gmHumanNetworkIgraph
V( gmHumanNetworkIgraph )$person_type


IGRAPH 57ebbb5 UNW- 1167 1201 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from 57ebbb5 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--307__588__source-3  1__3__author-2--308__589__source-3 
 [9] 1__3__author-2--362__959__source-3  1__3__author-2--368__1080__source-3
[11] 1__3__author-2--388__1419__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
[15] 1__3__author-2--808__2271__source-3 1__3__author-2--809__2272__source-3
+ ... omitted several edges
  1. 2
  2. 3
  3. 2
  4. 3
  5. 2
  6. 1
  7. 3
  8. 2
  9. 2
  10. 3
  11. 2
  12. 3
  13. 2
  14. 3
  15. 3
  16. 2
  17. 2
  18. 2
  19. 2
  20. 2
  21. 3
  22. 3
  23. 3
  24. 3
  25. 3
  26. 3
  27. 2
  28. 3
  29. 3
  30. 3
  31. 3
  32. 3
  33. 3
  34. 3
  35. 3
  36. 3
  37. 3
  38. 2
  39. 3
  40. 3
  41. 3
  42. 3
  43. 3
  44. 3
  45. 3
  46. 3
  47. 1
  48. 3
  49. 2
  50. 3
  51. 3
  52. 2
  53. 3
  54. 3
  55. 3
  56. 3
  57. 3
  58. 3
  59. 3
  60. 3
  61. 1
  62. 3
  63. 3
  64. 3
  65. 3
  66. 1
  67. 3
  68. 3
  69. 3
  70. 3
  71. 3
  72. 2
  73. 3
  74. 3
  75. 3
  76. 3
  77. 3
  78. 3
  79. 3
  80. 3
  81. 3
  82. 3
  83. 3
  84. 3
  85. 3
  86. 3
  87. 3
  88. 3
  89. 3
  90. 3
  91. 3
  92. 3
  93. 2
  94. 3
  95. 3
  96. 3
  97. 2
  98. 3
  99. 3
  100. 3
  101. 3
  102. 3
  103. 3
  104. 3
  105. 3
  106. 3
  107. 1
  108. 1
  109. 1
  110. 3
  111. 3
  112. 3
  113. 3
  114. 3
  115. 3
  116. 3
  117. 3
  118. 3
  119. 3
  120. 3
  121. 3
  122. 3
  123. 3
  124. 3
  125. 3
  126. 3
  127. 3
  128. 3
  129. 3
  130. 3
  131. 3
  132. 3
  133. 3
  134. 2
  135. 3
  136. 3
  137. 3
  138. 3
  139. 3
  140. 3
  141. 3
  142. 3
  143. 3
  144. 2
  145. 3
  146. 3
  147. 3
  148. 3
  149. 3
  150. 3
  151. 2
  152. 3
  153. 3
  154. 3
  155. 3
  156. 3
  157. 3
  158. 3
  159. 3
  160. 3
  161. 3
  162. 3
  163. 3
  164. 3
  165. 3
  166. 3
  167. 3
  168. 3
  169. 3
  170. 3
  171. 3
  172. 3
  173. 2
  174. 3
  175. 3
  176. 2
  177. 2
  178. 3
  179. 3
  180. 3
  181. 3
  182. 3
  183. 2
  184. 3
  185. 3
  186. 3
  187. 3
  188. 3
  189. 3
  190. 3
  191. 3
  192. 3
  193. 3
  194. 3
  195. 3
  196. 3
  197. 2
  198. 1
  199. 3
  200. 3
  201. 3
  202. 3
  203. 3
  204. 3
  205. 3
  206. 3
  207. 3
  208. 3
  209. 3
  210. 3
  211. 3
  212. 3
  213. 3
  214. 3
  215. 3
  216. 3
  217. 3
  218. 2
  219. 3
  220. 3
  221. 3
  222. 3
  223. 3
  224. 3
  225. 3
  226. 3
  227. 3
  228. 3
  229. 3
  230. 3
  231. 3
  232. 3
  233. 2
  234. 3
  235. 3
  236. 3
  237. 3
  238. 3
  239. 3
  240. 3
  241. 3
  242. 3
  243. 3
  244. 3
  245. 3
  246. 1
  247. 3
  248. 3
  249. 3
  250. 3
  251. 3
  252. 3
  253. 3
  254. 3
  255. 3
  256. 3
  257. 3
  258. 3
  259. 3
  260. 3
  261. 3
  262. 3
  263. 3
  264. 3
  265. 3
  266. 3
  267. 3
  268. 3
  269. 3
  270. 3
  271. 3
  272. 3
  273. 3
  274. 3
  275. 3
  276. 3
  277. 3
  278. 3
  279. 3
  280. 3
  281. 3
  282. 3
  283. 3
  284. 3
  285. 3
  286. 3
  287. 3
  288. 3
  289. 3
  290. 3
  291. 2
  292. 3
  293. 3
  294. 3
  295. 3
  296. 3
  297. 3
  298. 3
  299. 3
  300. 3
  301. 3
  302. 3
  303. 3
  304. 3
  305. 3
  306. 3
  307. 3
  308. 3
  309. 2
  310. 2
  311. 2
  312. 3
  313. 3
  314. 3
  315. 3
  316. 2
  317. 2
  318. 2
  319. 3
  320. 3
  321. 3
  322. 3
  323. 3
  324. 2
  325. 3
  326. 2
  327. 2
  328. 3
  329. 1
  330. 3
  331. 1
  332. 1
  333. 1
  334. 1
  335. 3
  336. 3
  337. 1
  338. 3
  339. 1
  340. 1
  341. 3
  342. 1
  343. 3
  344. 1
  345. 3
  346. 3
  347. 3
  348. 1
  349. 1
  350. 3
  351. 3
  352. 1
  353. 1
  354. 3
  355. 1
  356. 3
  357. 3
  358. 1
  359. 2
  360. 1
  361. 3
  362. 3
  363. 3
  364. 3
  365. 3
  366. 3
  367. 3
  368. 3
  369. 2
  370. 3
  371. 3
  372. 1
  373. 3
  374. 3
  375. 3
  376. 3
  377. 3
  378. 3
  379. 3
  380. 3
  381. 3
  382. 3
  383. 3
  384. 3
  385. 3
  386. 3
  387. 3
  388. 3
  389. 3
  390. 3
  391. 3
  392. 3
  393. 1
  394. 3
  395. 3
  396. 3
  397. 3
  398. 3
  399. 3
  400. 3
  401. 3
  402. 3
  403. 3
  404. 3
  405. 3
  406. 2
  407. 3
  408. 3
  409. 1
  410. 3
  411. 3
  412. 3
  413. 1
  414. 1
  415. 3
  416. 3
  417. 3
  418. 3
  419. 3
  420. 3
  421. 3
  422. 1
  423. 3
  424. 3
  425. 3
  426. 3
  427. 3
  428. 3
  429. 3
  430. 3
  431. 3
  432. 3
  433. 3
  434. 3
  435. 3
  436. 3
  437. 3
  438. 3
  439. 3
  440. 3
  441. 3
  442. 3
  443. 3
  444. 3
  445. 3
  446. 3
  447. 3
  448. 3
  449. 3
  450. 3
  451. 3
  452. 3
  453. 3
  454. 1
  455. 3
  456. 3
  457. 3
  458. 3
  459. 3
  460. 3
  461. 3
  462. 3
  463. 3
  464. 3
  465. 3
  466. 3
  467. 3
  468. 3
  469. 3
  470. 3
  471. 3
  472. 3
  473. 3
  474. 3
  475. 3
  476. 3
  477. 3
  478. 2
  479. 3
  480. 3
  481. 3
  482. 3
  483. 3
  484. 3
  485. 3
  486. 3
  487. 3
  488. 3
  489. 3
  490. 3
  491. 3
  492. 3
  493. 3
  494. 3
  495. 3
  496. 3
  497. 3
  498. 3
  499. 3
  500. 3
  501. 3
  502. 3
  503. 3
  504. 3
  505. 3
  506. 3
  507. 3
  508. 3
  509. 3
  510. 3
  511. 3
  512. 3
  513. 3
  514. 3
  515. 3
  516. 3
  517. 3
  518. 3
  519. 3
  520. 3
  521. 1
  522. 3
  523. 3
  524. 3
  525. 3
  526. 3
  527. 3
  528. 3
  529. 3
  530. 3
  531. 3
  532. 3
  533. 3
  534. 3
  535. 3
  536. 3
  537. 3
  538. 3
  539. 3
  540. 3
  541. 3
  542. 3
  543. 3
  544. 3
  545. 3
  546. 3
  547. 3
  548. 3
  549. 3
  550. 1
  551. 3
  552. 3
  553. 3
  554. 3
  555. 3
  556. 3
  557. 3
  558. 3
  559. 3
  560. 3
  561. 3
  562. 3
  563. 3
  564. 3
  565. 3
  566. 3
  567. 3
  568. 3
  569. 3
  570. 3
  571. 3
  572. 3
  573. 3
  574. 3
  575. 3
  576. 3
  577. 3
  578. 3
  579. 3
  580. 3
  581. 3
  582. 3
  583. 3
  584. 3
  585. 3
  586. 3
  587. 3
  588. 3
  589. 3
  590. 3
  591. 3
  592. 3
  593. 3
  594. 3
  595. 3
  596. 3
  597. 3
  598. 3
  599. 1
  600. 3
  601. 3
  602. 3
  603. 3
  604. 3
  605. 3
  606. 3
  607. 3
  608. 3
  609. 3
  610. 3
  611. 2
  612. 1
  613. 3
  614. 3
  615. 3
  616. 3
  617. 1
  618. 3
  619. 2
  620. 3
  621. 3
  622. 3
  623. 3
  624. 3
  625. 3
  626. 3
  627. 3
  628. 3
  629. 3
  630. 3
  631. 3
  632. 3
  633. 3
  634. 3
  635. 3
  636. 3
  637. 3
  638. 3
  639. 3
  640. 3
  641. 3
  642. 3
  643. 3
  644. 3
  645. 3
  646. 3
  647. 3
  648. 3
  649. 3
  650. 3
  651. 3
  652. 1
  653. 3
  654. 3
  655. 3
  656. 3
  657. 3
  658. 3
  659. 3
  660. 3
  661. 3
  662. 3
  663. 3
  664. 3
  665. 3
  666. 3
  667. 3
  668. 3
  669. 3
  670. 3
  671. 3
  672. 3
  673. 3
  674. 3
  675. 3
  676. 3
  677. 3
  678. 3
  679. 3
  680. 3
  681. 3
  682. 3
  683. 3
  684. 3
  685. 3
  686. 3
  687. 3
  688. 3
  689. 3
  690. 3
  691. 3
  692. 3
  693. 3
  694. 3
  695. 3
  696. 3
  697. 3
  698. 3
  699. 3
  700. 3
  701. 3
  702. 3
  703. 3
  704. 3
  705. 3
  706. 3
  707. 3
  708. 3
  709. 3
  710. 3
  711. 3
  712. 3
  713. 3
  714. 3
  715. 3
  716. 3
  717. 3
  718. 3
  719. 3
  720. 3
  721. 3
  722. 3
  723. 3
  724. 3
  725. 3
  726. 3
  727. 3
  728. 3
  729. 3
  730. 3
  731. 3
  732. 3
  733. 1
  734. 3
  735. 3
  736. 3
  737. 3
  738. 3
  739. 3
  740. 3
  741. 3
  742. 3
  743. 1
  744. 3
  745. 3
  746. 3
  747. 3
  748. 1
  749. 3
  750. 3
  751. 3
  752. 3
  753. 3
  754. 3
  755. 3
  756. 3
  757. 3
  758. 3
  759. 3
  760. 3
  761. 3
  762. 3
  763. 3
  764. 3
  765. 3
  766. 3
  767. 3
  768. 3
  769. 1
  770. 3
  771. 3
  772. 3
  773. 3
  774. 3
  775. 3
  776. 3
  777. 3
  778. 3
  779. 3
  780. 3
  781. 3
  782. 3
  783. 3
  784. 1
  785. 3
  786. 3
  787. 3
  788. 3
  789. 3
  790. 3
  791. 3
  792. 3
  793. 3
  794. 3
  795. 3
  796. 3
  797. 3
  798. 3
  799. 1
  800. 3
  801. 3
  802. 3
  803. 3
  804. 3
  805. 3
  806. 3
  807. 1
  808. 3
  809. 3
  810. 3
  811. 3
  812. 3
  813. 3
  814. 3
  815. 3
  816. 3
  817. 3
  818. 3
  819. 3
  820. 3
  821. 3
  822. 3
  823. 3
  824. 3
  825. 3
  826. 3
  827. 3
  828. 1
  829. 3
  830. 3
  831. 2
  832. 3
  833. 3
  834. 3
  835. 3
  836. 3
  837. 3
  838. 3
  839. 3
  840. 3
  841. 3
  842. 3
  843. 3
  844. 3
  845. 3
  846. 1
  847. 3
  848. 1
  849. 3
  850. 3
  851. 3
  852. 3
  853. 1
  854. 3
  855. 3
  856. 3
  857. 3
  858. 3
  859. 3
  860. 3
  861. 3
  862. 3
  863. 3
  864. 3
  865. 1
  866. 3
  867. 3
  868. 3
  869. 1
  870. 3
  871. 3
  872. 3
  873. 3
  874. 3
  875. 3
  876. 3
  877. 3
  878. 3
  879. 3
  880. 3
  881. 3
  882. 3
  883. 3
  884. 3
  885. 3
  886. 3
  887. 3
  888. 3
  889. 3
  890. 3
  891. 3
  892. 3
  893. 3
  894. 3
  895. 3
  896. 3
  897. 3
  898. 1
  899. 3
  900. 3
  901. 3
  902. 3
  903. 3
  904. 3
  905. 3
  906. 3
  907. 3
  908. 3
  909. 3
  910. 3
  911. 1
  912. 3
  913. 3
  914. 3
  915. 3
  916. 3
  917. 3
  918. 3
  919. 3
  920. 3
  921. 3
  922. 3
  923. 3
  924. 3
  925. 3
  926. 3
  927. 3
  928. 1
  929. 3
  930. 3
  931. 3
  932. 3
  933. 3
  934. 1
  935. 3
  936. 3
  937. 3
  938. 3
  939. 3
  940. 3
  941. 3
  942. 3
  943. 3
  944. 3
  945. 3
  946. 3
  947. 3
  948. 3
  949. 3
  950. 3
  951. 3
  952. 3
  953. 3
  954. 3
  955. 3
  956. 3
  957. 3
  958. 3
  959. 3
  960. 3
  961. 3
  962. 3
  963. 3
  964. 3
  965. 3
  966. 3
  967. 3
  968. 3
  969. 3
  970. 3
  971. 3
  972. 3
  973. 3
  974. 3
  975. 3
  976. 3
  977. 3
  978. 3
  979. 3
  980. 3
  981. 3
  982. 3
  983. 3
  984. 3
  985. 3
  986. 3
  987. 3
  988. 3
  989. 3
  990. 3
  991. 3
  992. 3
  993. 3
  994. 3
  995. 3
  996. 3
  997. 3
  998. 3
  999. 3
  1000. 3
  1001. 3
  1002. 3
  1003. 3
  1004. 3
  1005. 3
  1006. 1
  1007. 1
  1008. 2
  1009. 3
  1010. 3
  1011. 3
  1012. 3
  1013. 1
  1014. 3
  1015. 3
  1016. 3
  1017. 3
  1018. 3
  1019. 3
  1020. 1
  1021. 3
  1022. 3
  1023. 3
  1024. 3
  1025. 3
  1026. 3
  1027. 3
  1028. 3
  1029. 3
  1030. 3
  1031. 3
  1032. 3
  1033. 3
  1034. 3
  1035. 2
  1036. 3
  1037. 3
  1038. 3
  1039. 3
  1040. 3
  1041. 3
  1042. 3
  1043. 3
  1044. 3
  1045. 3
  1046. 3
  1047. 3
  1048. 1
  1049. 3
  1050. 3
  1051. 3
  1052. 3
  1053. 1
  1054. 3
  1055. 3
  1056. 3
  1057. 3
  1058. 3
  1059. 3
  1060. 3
  1061. 3
  1062. 3
  1063. 3
  1064. 3
  1065. 3
  1066. 3
  1067. 3
  1068. 3
  1069. 3
  1070. 3
  1071. 3
  1072. 3
  1073. 3
  1074. 3
  1075. 3
  1076. 3
  1077. 3
  1078. 3
  1079. 3
  1080. 1
  1081. 1
  1082. 3
  1083. 3
  1084. 3
  1085. 3
  1086. 3
  1087. 3
  1088. 3
  1089. 3
  1090. 3
  1091. 3
  1092. 3
  1093. 3
  1094. 3
  1095. 3
  1096. 1
  1097. 3
  1098. 3
  1099. 3
  1100. 3
  1101. 3
  1102. 3
  1103. 3
  1104. 3
  1105. 3
  1106. 3
  1107. 3
  1108. 3
  1109. 3
  1110. 3
  1111. 3
  1112. 3
  1113. 1
  1114. 1
  1115. 3
  1116. 3
  1117. 3
  1118. 3
  1119. 3
  1120. 3
  1121. 3
  1122. 3
  1123. 3
  1124. 3
  1125. 3
  1126. 3
  1127. 3
  1128. 3
  1129. 1
  1130. 1
  1131. 1
  1132. 1
  1133. 1
  1134. 3
  1135. 1
  1136. 3
  1137. 1
  1138. 1
  1139. 1
  1140. 3
  1141. 1
  1142. 1
  1143. 1
  1144. 1
  1145. 1
  1146. 1
  1147. 1
  1148. 1
  1149. 1
  1150. 3
  1151. 1
  1152. 1
  1153. 1
  1154. 1
  1155. 1
  1156. 1
  1157. 1
  1158. 1
  1159. 3
  1160. 1
  1161. 3
  1162. 1
  1163. 1
  1164. 3
  1165. 3
  1166. 3
  1167. 3

In [55]:
# human - include ties Greater than or equal to 0 (GE0)
gmHumanMeanTieWeightGE0Vector <- apply( gmHumanNetworkMatrix, 1, calculateListMean )
gmHumanDataDF$meanTieWeightGE0 <- gmHumanMeanTieWeightGE0Vector

# human - include ties Greater than or equal to 1 (GE1)
gmHumanMeanTieWeightGE1Vector <- apply( gmHumanNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gmHumanDataDF$meanTieWeightGE1 <- gmHumanMeanTieWeightGE1Vector

# human - Max tie weight?
gmHumanMaxTieWeightVector <- apply( gmHumanNetworkMatrix, 1, calculateListMax )
gmHumanDataDF$maxTieWeight <- gmHumanMaxTieWeightVector

In [56]:
# to see count of nodes and edges, just type the object name:
gmHumanNetworkIgraph

# Will output something like:
#
# IGRAPH UNW- 314 309 --
# + attr: name (v/c), weight (e/n)
#
# in the first line, "UNW-" are traits of graph:
# - 1 - U = undirected ( directed would be "D" )
# - 2 - N = named or not ( "-" instead of "N" )
# - 3 - W = weighted
# - 4 - B = bipartite ( "-" = not bipartite )
# 314 is where node count goes, 309 is edge count.
# The second line gives you information about the 'attributes' associated with the graph. In this case, there are two attributes, name and weight.  Next to each attribute name is a two-character construct that looks like "(v/c)".  The first letter is the thing the attribute is associated with (g = graph, v = vertex or node, e = edge).  The second is the type of the attribute (c = character data, n = numeric data).  So, in this case:
# - name (v/c) - the name attribute is a vertex/node attribute - the "v" in "(v/c)" - where the values are character data - the "c" in "(v/c)".
# - weight (e/n) - the weight attribute is an edge attribute - the "e" in "(e/n)" - where the values are numeric data - the "n" in "(e/n)".
# - based on: http://www.shizukalab.com/toolkits/sna/sna_data


IGRAPH 57ebbb5 UNW- 1167 1201 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from 57ebbb5 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--307__588__source-3  1__3__author-2--308__589__source-3 
 [9] 1__3__author-2--362__959__source-3  1__3__author-2--368__1080__source-3
[11] 1__3__author-2--388__1419__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
[15] 1__3__author-2--808__2271__source-3 1__3__author-2--809__2272__source-3
+ ... omitted several edges

Calculate some basic metrics


In [57]:
# try calling the degree() function on an igraph object.  Returns a number vector with names.
gmHumanDegreeVector <- igraph::degree( gmHumanNetworkIgraph )

# For help with igraph::degree function:
#??igraph::degree

# calculate the mean of the degrees.
gmHumanAvgDegree <- mean( gmHumanDegreeVector )
message( paste( "grp_month human average degree = ", gmHumanAvgDegree, sep = "" ) )

# append the degrees to the network as a vertex attribute.
V( gmHumanNetworkIgraph )$degree <- gmHumanDegreeVector

# also add degree vector to original data frame
gmHumanDataDF$degree <- gmHumanDegreeVector

# if you want to just work with the traits of the nodes/vertexes, you can
#    combine the attribute vectors into a data frame.

# first, output igraph object to see what attributes you have
gmHumanNetworkIgraph
V( gmHumanNetworkIgraph )$degree


grp_month human average degree = 2.05826906598115
IGRAPH 57ebbb5 UNW- 1167 1201 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), degree (v/n),
| weight (e/n)
+ edges from 57ebbb5 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--307__588__source-3  1__3__author-2--308__589__source-3 
 [9] 1__3__author-2--362__959__source-3  1__3__author-2--368__1080__source-3
[11] 1__3__author-2--388__1419__source-3 1__3__author-2--672__2100__source-3
[13] 1__3__author-2--673__2101__source-3 1__3__author-2--805__2267__source-3
+ ... omitted several edges
  1. 28
  2. 1
  3. 36
  4. 1
  5. 34
  6. 0
  7. 1
  8. 50
  9. 28
  10. 1
  11. 32
  12. 1
  13. 61
  14. 1
  15. 1
  16. 99
  17. 44
  18. 31
  19. 47
  20. 66
  21. 2
  22. 6
  23. 1
  24. 1
  25. 2
  26. 1
  27. 38
  28. 2
  29. 2
  30. 2
  31. 2
  32. 2
  33. 1
  34. 1
  35. 1
  36. 1
  37. 1
  38. 41
  39. 1
  40. 1
  41. 1
  42. 2
  43. 1
  44. 1
  45. 7
  46. 1
  47. 0
  48. 1
  49. 46
  50. 4
  51. 1
  52. 19
  53. 3
  54. 1
  55. 2
  56. 2
  57. 1
  58. 1
  59. 1
  60. 1
  61. 0
  62. 1
  63. 1
  64. 1
  65. 1
  66. 0
  67. 1
  68. 2
  69. 3
  70. 1
  71. 1
  72. 32
  73. 1
  74. 1
  75. 3
  76. 1
  77. 1
  78. 1
  79. 1
  80. 1
  81. 1
  82. 1
  83. 1
  84. 1
  85. 1
  86. 1
  87. 1
  88. 1
  89. 1
  90. 1
  91. 1
  92. 1
  93. 7
  94. 1
  95. 1
  96. 1
  97. 9
  98. 2
  99. 1
  100. 1
  101. 1
  102. 1
  103. 1
  104. 2
  105. 7
  106. 1
  107. 0
  108. 0
  109. 0
  110. 1
  111. 1
  112. 1
  113. 1
  114. 1
  115. 1
  116. 2
  117. 2
  118. 2
  119. 2
  120. 1
  121. 1
  122. 1
  123. 1
  124. 1
  125. 2
  126. 1
  127. 1
  128. 1
  129. 1
  130. 1
  131. 1
  132. 1
  133. 1
  134. 37
  135. 1
  136. 1
  137. 1
  138. 1
  139. 1
  140. 2
  141. 1
  142. 1
  143. 1
  144. 19
  145. 1
  146. 1
  147. 1
  148. 1
  149. 1
  150. 1
  151. 33
  152. 1
  153. 1
  154. 1
  155. 1
  156. 1
  157. 1
  158. 1
  159. 1
  160. 1
  161. 2
  162. 1
  163. 1
  164. 1
  165. 1
  166. 1
  167. 1
  168. 1
  169. 1
  170. 1
  171. 1
  172. 1
  173. 4
  174. 1
  175. 1
  176. 31
  177. 45
  178. 1
  179. 2
  180. 1
  181. 1
  182. 1
  183. 44
  184. 1
  185. 1
  186. 1
  187. 1
  188. 1
  189. 1
  190. 1
  191. 2
  192. 1
  193. 1
  194. 2
  195. 1
  196. 1
  197. 3
  198. 0
  199. 1
  200. 1
  201. 1
  202. 1
  203. 1
  204. 1
  205. 1
  206. 1
  207. 1
  208. 1
  209. 1
  210. 2
  211. 2
  212. 4
  213. 4
  214. 4
  215. 4
  216. 4
  217. 1
  218. 1
  219. 1
  220. 1
  221. 1
  222. 4
  223. 1
  224. 1
  225. 1
  226. 1
  227. 1
  228. 1
  229. 1
  230. 1
  231. 2
  232. 1
  233. 19
  234. 1
  235. 1
  236. 1
  237. 1
  238. 2
  239. 2
  240. 2
  241. 3
  242. 2
  243. 2
  244. 4
  245. 1
  246. 0
  247. 1
  248. 1
  249. 2
  250. 1
  251. 1
  252. 1
  253. 1
  254. 1
  255. 1
  256. 1
  257. 1
  258. 1
  259. 1
  260. 1
  261. 3
  262. 1
  263. 1
  264. 1
  265. 1
  266. 1
  267. 1
  268. 1
  269. 1
  270. 1
  271. 1
  272. 1
  273. 1
  274. 1
  275. 1
  276. 2
  277. 2
  278. 2
  279. 2
  280. 3
  281. 1
  282. 1
  283. 2
  284. 1
  285. 1
  286. 1
  287. 1
  288. 1
  289. 1
  290. 1
  291. 4
  292. 1
  293. 1
  294. 2
  295. 1
  296. 1
  297. 2
  298. 4
  299. 1
  300. 1
  301. 1
  302. 1
  303. 1
  304. 1
  305. 1
  306. 1
  307. 1
  308. 1
  309. 76
  310. 22
  311. 50
  312. 3
  313. 1
  314. 1
  315. 1
  316. 13
  317. 9
  318. 3
  319. 1
  320. 2
  321. 3
  322. 1
  323. 1
  324. 2
  325. 1
  326. 2
  327. 2
  328. 1
  329. 0
  330. 1
  331. 0
  332. 0
  333. 0
  334. 0
  335. 1
  336. 1
  337. 0
  338. 1
  339. 0
  340. 0
  341. 1
  342. 0
  343. 2
  344. 0
  345. 1
  346. 1
  347. 1
  348. 0
  349. 0
  350. 1
  351. 1
  352. 0
  353. 0
  354. 1
  355. 0
  356. 1
  357. 1
  358. 0
  359. 10
  360. 0
  361. 1
  362. 1
  363. 1
  364. 1
  365. 1
  366. 1
  367. 3
  368. 2
  369. 14
  370. 2
  371. 1
  372. 0
  373. 1
  374. 1
  375. 2
  376. 1
  377. 1
  378. 1
  379. 1
  380. 1
  381. 1
  382. 1
  383. 1
  384. 1
  385. 1
  386. 2
  387. 1
  388. 2
  389. 1
  390. 1
  391. 1
  392. 1
  393. 0
  394. 1
  395. 1
  396. 1
  397. 1
  398. 1
  399. 1
  400. 1
  401. 1
  402. 2
  403. 1
  404. 1
  405. 1
  406. 7
  407. 1
  408. 1
  409. 0
  410. 1
  411. 1
  412. 1
  413. 0
  414. 0
  415. 1
  416. 1
  417. 1
  418. 1
  419. 1
  420. 1
  421. 1
  422. 0
  423. 1
  424. 1
  425. 1
  426. 1
  427. 1
  428. 1
  429. 1
  430. 1
  431. 1
  432. 1
  433. 1
  434. 1
  435. 1
  436. 1
  437. 1
  438. 1
  439. 1
  440. 1
  441. 1
  442. 3
  443. 2
  444. 4
  445. 2
  446. 1
  447. 2
  448. 2
  449. 1
  450. 1
  451. 1
  452. 1
  453. 1
  454. 0
  455. 1
  456. 1
  457. 1
  458. 1
  459. 1
  460. 1
  461. 1
  462. 1
  463. 1
  464. 1
  465. 1
  466. 1
  467. 1
  468. 1
  469. 1
  470. 1
  471. 1
  472. 1
  473. 1
  474. 1
  475. 1
  476. 2
  477. 1
  478. 4
  479. 1
  480. 1
  481. 1
  482. 1
  483. 1
  484. 1
  485. 1
  486. 1
  487. 1
  488. 1
  489. 1
  490. 1
  491. 1
  492. 1
  493. 1
  494. 1
  495. 1
  496. 1
  497. 1
  498. 1
  499. 1
  500. 1
  501. 1
  502. 1
  503. 1
  504. 1
  505. 1
  506. 1
  507. 1
  508. 1
  509. 1
  510. 1
  511. 1
  512. 1
  513. 1
  514. 1
  515. 1
  516. 1
  517. 1
  518. 1
  519. 1
  520. 1
  521. 0
  522. 1
  523. 1
  524. 1
  525. 1
  526. 1
  527. 1
  528. 1
  529. 1
  530. 1
  531. 1
  532. 1
  533. 1
  534. 1
  535. 1
  536. 1
  537. 1
  538. 1
  539. 1
  540. 1
  541. 1
  542. 2
  543. 1
  544. 1
  545. 1
  546. 1
  547. 1
  548. 1
  549. 1
  550. 0
  551. 1
  552. 1
  553. 1
  554. 1
  555. 1
  556. 1
  557. 1
  558. 1
  559. 1
  560. 1
  561. 1
  562. 1
  563. 2
  564. 1
  565. 1
  566. 1
  567. 1
  568. 1
  569. 1
  570. 1
  571. 1
  572. 1
  573. 1
  574. 1
  575. 1
  576. 1
  577. 1
  578. 1
  579. 1
  580. 1
  581. 1
  582. 1
  583. 1
  584. 1
  585. 1
  586. 1
  587. 1
  588. 1
  589. 1
  590. 1
  591. 1
  592. 1
  593. 1
  594. 2
  595. 1
  596. 1
  597. 1
  598. 1
  599. 0
  600. 1
  601. 1
  602. 1
  603. 1
  604. 1
  605. 1
  606. 1
  607. 1
  608. 1
  609. 1
  610. 1
  611. 4
  612. 0
  613. 1
  614. 1
  615. 1
  616. 1
  617. 0
  618. 1
  619. 5
  620. 1
  621. 1
  622. 1
  623. 1
  624. 1
  625. 1
  626. 3
  627. 1
  628. 1
  629. 1
  630. 1
  631. 1
  632. 1
  633. 1
  634. 1
  635. 1
  636. 1
  637. 1
  638. 1
  639. 1
  640. 1
  641. 1
  642. 1
  643. 1
  644. 1
  645. 1
  646. 1
  647. 2
  648. 2
  649. 2
  650. 2
  651. 2
  652. 0
  653. 1
  654. 1
  655. 1
  656. 1
  657. 1
  658. 1
  659. 1
  660. 1
  661. 1
  662. 1
  663. 1
  664. 1
  665. 1
  666. 4
  667. 1
  668. 2
  669. 1
  670. 1
  671. 1
  672. 1
  673. 1
  674. 1
  675. 1
  676. 1
  677. 1
  678. 1
  679. 1
  680. 1
  681. 1
  682. 1
  683. 1
  684. 1
  685. 1
  686. 1
  687. 1
  688. 1
  689. 1
  690. 1
  691. 1
  692. 1
  693. 1
  694. 1
  695. 1
  696. 1
  697. 1
  698. 1
  699. 1
  700. 1
  701. 1
  702. 1
  703. 1
  704. 1
  705. 1
  706. 1
  707. 1
  708. 1
  709. 1
  710. 1
  711. 1
  712. 1
  713. 1
  714. 1
  715. 1
  716. 1
  717. 1
  718. 1
  719. 1
  720. 1
  721. 1
  722. 1
  723. 1
  724. 1
  725. 1
  726. 1
  727. 1
  728. 1
  729. 1
  730. 1
  731. 1
  732. 1
  733. 0
  734. 1
  735. 1
  736. 1
  737. 1
  738. 1
  739. 1
  740. 1
  741. 1
  742. 1
  743. 0
  744. 1
  745. 1
  746. 1
  747. 1
  748. 0
  749. 1
  750. 1
  751. 1
  752. 1
  753. 1
  754. 1
  755. 1
  756. 1
  757. 1
  758. 2
  759. 1
  760. 1
  761. 1
  762. 1
  763. 1
  764. 1
  765. 1
  766. 1
  767. 1
  768. 1
  769. 0
  770. 1
  771. 1
  772. 1
  773. 2
  774. 2
  775. 2
  776. 2
  777. 2
  778. 1
  779. 1
  780. 1
  781. 2
  782. 1
  783. 1
  784. 0
  785. 1
  786. 1
  787. 1
  788. 1
  789. 1
  790. 1
  791. 1
  792. 1
  793. 1
  794. 1
  795. 2
  796. 1
  797. 1
  798. 1
  799. 0
  800. 1
  801. 1
  802. 1
  803. 2
  804. 1
  805. 1
  806. 1
  807. 0
  808. 1
  809. 1
  810. 1
  811. 1
  812. 1
  813. 1
  814. 1
  815. 1
  816. 1
  817. 1
  818. 1
  819. 1
  820. 1
  821. 1
  822. 1
  823. 1
  824. 1
  825. 1
  826. 1
  827. 1
  828. 0
  829. 1
  830. 1
  831. 3
  832. 2
  833. 1
  834. 1
  835. 1
  836. 2
  837. 1
  838. 1
  839. 1
  840. 1
  841. 1
  842. 1
  843. 1
  844. 1
  845. 1
  846. 0
  847. 1
  848. 0
  849. 1
  850. 1
  851. 1
  852. 1
  853. 0
  854. 1
  855. 1
  856. 1
  857. 1
  858. 1
  859. 1
  860. 1
  861. 1
  862. 1
  863. 1
  864. 1
  865. 0
  866. 1
  867. 1
  868. 1
  869. 0
  870. 1
  871. 1
  872. 1
  873. 1
  874. 1
  875. 1
  876. 1
  877. 1
  878. 1
  879. 1
  880. 1
  881. 1
  882. 1
  883. 1
  884. 1
  885. 1
  886. 1
  887. 1
  888. 1
  889. 1
  890. 1
  891. 1
  892. 1
  893. 1
  894. 1
  895. 1
  896. 1
  897. 2
  898. 0
  899. 1
  900. 1
  901. 1
  902. 1
  903. 1
  904. 1
  905. 1
  906. 1
  907. 1
  908. 1
  909. 1
  910. 1
  911. 0
  912. 1
  913. 1
  914. 1
  915. 1
  916. 1
  917. 1
  918. 1
  919. 1
  920. 1
  921. 1
  922. 1
  923. 1
  924. 1
  925. 1
  926. 1
  927. 1
  928. 0
  929. 1
  930. 1
  931. 1
  932. 1
  933. 1
  934. 0
  935. 1
  936. 1
  937. 1
  938. 1
  939. 1
  940. 1
  941. 1
  942. 1
  943. 1
  944. 1
  945. 1
  946. 1
  947. 1
  948. 1
  949. 1
  950. 1
  951. 1
  952. 1
  953. 1
  954. 1
  955. 1
  956. 1
  957. 1
  958. 1
  959. 1
  960. 1
  961. 1
  962. 1
  963. 1
  964. 1
  965. 1
  966. 1
  967. 1
  968. 1
  969. 1
  970. 1
  971. 1
  972. 1
  973. 1
  974. 1
  975. 1
  976. 1
  977. 1
  978. 1
  979. 1
  980. 1
  981. 1
  982. 1
  983. 1
  984. 1
  985. 1
  986. 1
  987. 1
  988. 1
  989. 1
  990. 1
  991. 1
  992. 1
  993. 1
  994. 1
  995. 1
  996. 1
  997. 1
  998. 1
  999. 1
  1000. 1
  1001. 1
  1002. 1
  1003. 1
  1004. 1
  1005. 1
  1006. 0
  1007. 0
  1008. 0
  1009. 1
  1010. 1
  1011. 1
  1012. 1
  1013. 0
  1014. 1
  1015. 1
  1016. 1
  1017. 1
  1018. 1
  1019. 1
  1020. 0
  1021. 1
  1022. 1
  1023. 1
  1024. 1
  1025. 1
  1026. 1
  1027. 1
  1028. 1
  1029. 1
  1030. 1
  1031. 1
  1032. 1
  1033. 1
  1034. 1
  1035. 5
  1036. 1
  1037. 1
  1038. 1
  1039. 1
  1040. 1
  1041. 1
  1042. 1
  1043. 1
  1044. 1
  1045. 1
  1046. 2
  1047. 2
  1048. 0
  1049. 2
  1050. 2
  1051. 1
  1052. 1
  1053. 0
  1054. 1
  1055. 1
  1056. 1
  1057. 1
  1058. 1
  1059. 1
  1060. 1
  1061. 1
  1062. 1
  1063. 1
  1064. 1
  1065. 1
  1066. 1
  1067. 2
  1068. 2
  1069. 2
  1070. 2
  1071. 2
  1072. 1
  1073. 1
  1074. 1
  1075. 1
  1076. 1
  1077. 1
  1078. 1
  1079. 1
  1080. 0
  1081. 0
  1082. 1
  1083. 1
  1084. 1
  1085. 1
  1086. 1
  1087. 1
  1088. 1
  1089. 1
  1090. 1
  1091. 1
  1092. 1
  1093. 1
  1094. 1
  1095. 1
  1096. 0
  1097. 1
  1098. 1
  1099. 1
  1100. 1
  1101. 1
  1102. 1
  1103. 1
  1104. 1
  1105. 1
  1106. 1
  1107. 1
  1108. 1
  1109. 1
  1110. 1
  1111. 1
  1112. 1
  1113. 0
  1114. 0
  1115. 2
  1116. 2
  1117. 2
  1118. 2
  1119. 2
  1120. 1
  1121. 1
  1122. 1
  1123. 1
  1124. 1
  1125. 1
  1126. 1
  1127. 1
  1128. 1
  1129. 0
  1130. 0
  1131. 0
  1132. 0
  1133. 0
  1134. 1
  1135. 0
  1136. 1
  1137. 0
  1138. 0
  1139. 0
  1140. 1
  1141. 0
  1142. 0
  1143. 0
  1144. 0
  1145. 0
  1146. 0
  1147. 0
  1148. 0
  1149. 0
  1150. 1
  1151. 0
  1152. 0
  1153. 0
  1154. 0
  1155. 0
  1156. 0
  1157. 0
  1158. 0
  1159. 2
  1160. 0
  1161. 1
  1162. 0
  1163. 0
  1164. 1
  1165. 1
  1166. 1
  1167. 1

Calculate average source and author degree:


In [58]:
# average author degree (person types 2 and 4)
gmHumanAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gmHumanDataDF, includeBothIN = TRUE )
message( paste( "grp_month human average author degree (2 and 4) = ", gmHumanAverageAuthorDegree2And4, sep = "" ) )

# average author degree (person type 2 only)
gmHumanAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gmHumanDataDF, includeBothIN = FALSE )
message( paste( "grp_month human average author degree (only 2) = ", gmHumanAverageAuthorDegreeOnly2, sep = "" ) )

# average source degree (person types 3 and 4)
gmHumanAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gmHumanDataDF, includeBothIN = TRUE )
message( paste( "grp_month human average source degree (3 and 4) = ", gmHumanAverageSourceDegree3And4, sep = "" ) )

# average source degree (person type 3 only)
gmHumanAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gmHumanDataDF, includeBothIN = FALSE )
message( paste( "grp_month human average source degree (only 3) = ", gmHumanAverageSourceDegreeOnly3, sep = "" ) )


grp_month human average author degree (2 and 4) = 25.3958333333333
grp_month human average author degree (only 2) = 25.3958333333333
grp_month human average source degree (3 and 4) = 1.1564027370479
grp_month human average source degree (only 3) = 1.1564027370479

More metrics

Once we get the data into an igraph object, run the code in the following for more in-depth information:

context_text/R/sna/statnet/sna-igraph-init.r
context_text/R/sna/statnet/sna-igraph-network-stats.r

In [59]:
# First, need to load SNA functions and load data into statnet network object.
#    For more details on that, see the files "functions-sna.r",
#    "sna-load_data.r" and "sna-igraph_init.r".
#
# assumes that working directory for statnet is context_text/R/igraph
# setwd( ".." )
# source( "functions-sna.r" )
# source( "sna-load_data.r" )
# setwd( "igraph" )
# source( "sna-igraph-init.r" )

# results in (among other things):
# - humanNetworkData - data frame with human-generated network data matrix in it, including columns on the right side for any node-specific attributes.
# - calaisNetworkData - data frame with computer-generated network data matrix in it, including columns on the right side for any node-specific attributes.
# - humanNetworkTies - data frame with only human-generated network data matrix in it, no node-specific attributes.
# - calaisNetworkTies - data frame with only computer-generated network data matrix in it, no node-specific attributes.
# - humanNetworkMatrix - matrix with only human-generated network data matrix in it, no node-specific attributes.
# - calaisNetworkMatrix - matrix with only computer-generated network data matrix in it, no node-specific attributes.
# - humanNetworkIgraph - igraph network with human-coded network in it, including node-specific attributes.
# - calaisNetworkIgraph - igraph network with computer-coded network in it, including node-specific attributes.

# Links:
# - CRAN page: http://cran.r-project.org/web/packages/igraph/index.html
# - Manual (PDF): http://cran.r-project.org/web/packages/igraph/igraph.pdf
# - intro.: http://horicky.blogspot.com/2012/04/basic-graph-analytics-using-igraph.html
# - good notes: http://www.shizukalab.com/toolkits/sna/node-level-calculations

# Also, be advised that statnet and igraph don't really play nice together.
#    If you'll be using both, best idea is to have a workspace for each.

#==============================================================================#
# igraph
#==============================================================================#

# Good notes:
# - http://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/

# make sure you've loaded the igraph library
# install.packages( "igraph" )
library( igraph )

#==============================================================================#
# NODE level
#==============================================================================#

# calculate the mean of the degrees.
gmHumanDegreeMean <- gmHumanAvgDegree
message( paste( "grp_month human degree mean = ", gmHumanDegreeMean, sep = "" ) )

# what is the standard deviation of these degrees?
gmHumanDegreeSd <- sd( gmHumanDegreeVector )
message( paste( "grp_month human degree SD = ", gmHumanDegreeSd, sep = "" ) )

# what is the variance of these degrees?
gmHumanDegreeVar <- var( gmHumanDegreeVector )
message( paste( "grp_month human degree Variance = ", gmHumanDegreeVar, sep = "" ) )

# what is the max value among these degrees?
gmHumanDegreeMax <- max( gmHumanDegreeVector )
message( paste( "grp_month human degree Max Value = ", gmHumanDegreeMax, sep = "" ) )

# calculate and plot degree distributions
gmHumanDegreeFrequenciesTable <- table( gmHumanDegreeVector )
gmHumanDegreeDistribution <- igraph::degree.distribution( gmHumanNetworkIgraph )
plot( gmHumanDegreeDistribution, xlab = "grp_month human node degree" )
lines( gmHumanDegreeDistribution )

# subset vector to get only those that are above mean
gmHumanAboveMeanVector <- gmHumanDegreeVector[ gmHumanDegreeVector > gmHumanDegreeMax ]

# node-level transitivity
# create transitivity vectors.
gmHumanTransitivityVector <- igraph::transitivity( gmHumanNetworkIgraph, type = "local" )

# append the transitivity to the network as a vertex attribute.
V( gmHumanNetworkIgraph )$transitivity <- gmHumanTransitivityVector

# also add transitivity vector to original data frame
gmHumanDataDF$transitivity <- gmHumanTransitivityVector

# And, if you want averages of these:
gmHumanMeanTransitivity <- mean( gmHumanTransitivityVector, na.rm = TRUE )
message( paste( "grp_month human mean transitivity = ", gmHumanMeanTransitivity, sep = "" ) )

#==============================================================================#
# NETWORK level
#==============================================================================#

#------------------------------------------------------------------------------#
# ==> graph-level degree centrality
#
# Returns a named list with the following components:
# res - The node-level centrality scores
# centralization - The graph level centrality index.
# theoretical_max - The maximum theoretical graph level centralization score
#     for a graph with the given number of vertices, using the same parameters.
#     If the normalized argument was TRUE (the default), then the result was
#     divided by this number.
gmHumanDegreeCentralityOutput <- igraph::centralization.degree( gmHumanNetworkIgraph )
gmHumanDegreeCentrality <- gmHumanDegreeCentralityOutput$centralization
gmHumanDegreeCentralityMax <- gmHumanDegreeCentralityOutput$theoretical_max
message( paste( "grp_month human degree centrality = ", gmHumanDegreeCentrality, " ( max = ", gmHumanDegreeCentralityMax, " )", sep = "" ) )

# node-level degree centrality
gmHumanDegreeCentralityVector <- gmHumanDegreeCentralityOutput$res
#message( paste( "grp_month human betweenness = ", gmHumanBetweenness, sep = "" ) )

# append the degree centrality to the network as a vertex attribute.
V( gmHumanNetworkIgraph )$degreeCentrality <- gmHumanDegreeCentralityVector

# also add degree centrality vector to original data frame
gmHumanDataDF$degreeCentrality <- gmHumanDegreeCentralityVector

# And, if you want averages of these:
gmHumanMeanDegreeCentrality <- mean( gmHumanDegreeCentralityVector, na.rm = TRUE )
message( paste( "grp_month human mean degree centrality = ", gmHumanMeanDegreeCentrality, sep = "" ) )

#------------------------------------------------------------------------------#
# ==> graph-level undirected betweenness
#
# Returns a named list with the following components:
# res - The node-level centrality scores
# centralization - The graph level centrality index.
# theoretical_max - The maximum theoretical graph level centralization score
#     for a graph with the given number of vertices, using the same parameters.
#     If the normalized argument was TRUE (the default), then the result was
#     divided by this number.
gmHumanBetweennessCentralityOutput <- igraph::centralization.betweenness( gmHumanNetworkIgraph, directed = FALSE )
gmHumanBetweennessCentrality <- gmHumanBetweennessCentralityOutput$centralization
gmHumanBetweennessCentralityMax <- gmHumanBetweennessCentralityOutput$theoretical_max
message( paste( "grp_month human betweenness centrality = ", gmHumanBetweennessCentrality, " ( max = ", gmHumanBetweennessCentralityMax, " )", sep = "" ) )

# node-level undirected betweenness
gmHumanBetweennessVector <- gmHumanBetweennessCentralityOutput$res
#message( paste( "grp_month human betweenness = ", gmHumanBetweenness, sep = "" ) )

# append the betweenness to the network as a vertex attribute.
V( gmHumanNetworkIgraph )$betweenness <- gmHumanBetweennessVector

# also add betweenness vector to original data frame
gmHumanDataDF$betweenness <- gmHumanBetweennessVector

# And, if you want averages of these:
gmHumanMeanBetweenness <- mean( gmHumanBetweennessVector, na.rm = TRUE )
message( paste( "grp_month human mean betweenness = ", gmHumanMeanBetweenness, sep = "" ) )

# graph-level transitivity
gmHumanTransitivity <- igraph::transitivity( gmHumanNetworkIgraph, type = "global" )
message( paste( "grp_month human transitivity = ", gmHumanTransitivity, sep = "" ) )

# graph-level density
gmHumanDensity <- igraph::graph.density( gmHumanNetworkIgraph )
message( paste( "grp_month human density = ", gmHumanDensity, sep = "" ) )

#==============================================================================#
# output attributes to data frame
#==============================================================================#

# if you want to just work with the traits of the nodes/vertexes, you can
#    combine the attribute vectors into a data frame.

# first, output igraph object to see what attributes you have
gmHumanNetworkIgraph

# then, combine them into a data frame.
gmHumanAttributeDF <- data.frame( id = V( gmHumanNetworkIgraph )$name,
                                      person_id = V( gmHumanNetworkIgraph )$person_id,
                                      person_type = V( gmHumanNetworkIgraph )$person_type,
                                      degree = V( gmHumanNetworkIgraph )$degree,
                                      transitivity = V( gmHumanNetworkIgraph )$transitivity,
                                      degreeCentrality = V( gmHumanNetworkIgraph )$degreeCentrality,
                                      betweenness = V( gmHumanNetworkIgraph )$betweenness )


grp_month human degree mean = 2.05826906598115
grp_month human degree SD = 6.65377784484138
grp_month human degree Variance = 44.272759608502
grp_month human degree Max Value = 99
grp_month human mean transitivity = 0.415627973371374
grp_month human degree centrality = 0.0831404210411825 ( max = 1360722 )
grp_month human mean degree centrality = 2.05826906598115
grp_month human betweenness centrality = 0.220493193695819 ( max = 791941370 )
grp_month human mean betweenness = 1712.16966580977
grp_month human transitivity = 0.0131821874307658
grp_month human density = 0.00176523933617594
IGRAPH 57ebbb5 UNW- 1167 1201 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), degree (v/n),
| transitivity (v/n), degreeCentrality (v/n), betweenness (v/n), weight
| (e/n)
+ edges from 57ebbb5 (vertex names):
 [1] 1__3__author-2--7__25__source-3     1__3__author-2--20__84__author-2   
 [3] 1__3__author-2--42__182__source-3   1__3__author-2--196__456__source-3 
 [5] 1__3__author-2--221__486__source-3  1__3__author-2--244__516__source-3 
 [7] 1__3__author-2--307__588__source-3  1__3__author-2--308__589__source-3 
 [9] 1__3__author-2--362__959__source-3  1__3__author-2--368__1080__source-3
[11] 1__3__author-2--388__1419__source-3 1__3__author-2--672__2100__source-3
+ ... omitted several edges

Save workspace image

Save all the information in the current image, in case we need/want it later.


In [ ]:
message( paste( "workspace_file_name = ", workspace_file_name, sep = "" ) )

In [60]:
# help( save.image )
save.image( file = workspace_file_name )
message( paste( "saved workspace_file_name = ", workspace_file_name, sep = "" ) )