R-igraph-grp_month-week_3

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 [2]:
# 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-week_3.RData"
workspace_file_path <- paste( data_directory, "/", workspace_file_name )

In [3]:
# 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 changed any directories above, you'll have to re-run the above cells after loading the workspace, and you'll want to save at the end, as well. Load the workspace:


In [ ]:
# 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 [4]:
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 week 1 subset - sourcenet_data-20171115-043246-grp_month-automated-week1_subset.tab
  • human week 1 subset - sourcenet_data-20171115-043404-grp_month-human-week1_subset.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_week_3 analysis

First, look at a single week out of the shiny new month of data.

grp_week_3 (gw3) - automated - OpenCalais

Analyze the 3rd full week of data coded by OpenCalais. Set up some variables to store where data is located:


In [5]:
# initialize variables
gwAutomatedDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gwAutomatedDataFile <- "sourcenet_data-20180326-040736-grp_month-automated-week3_subset.tab"
gwAutomatedDataPath <- paste( gwAutomatedDataFolder, "/", gwAutomatedDataFile, sep = "" )

In [6]:
gwAutomatedDataPath


'/home/jonathanmorgan/work/django/research/work/phd_work/methods/data/network/grp_month/sourcenet_data-20180326-040736-grp_month-automated-week3_subset.tab'

Load the data file into memory


In [7]:
# tab-delimited:
gwAutomatedDataDF <- read.delim( gwAutomatedDataPath, header = TRUE, row.names = 1, check.names = FALSE )

In [8]:
# get count of rows...
gwAutomatedRowCount <- nrow( gwAutomatedDataDF )
message( paste( "grp_week automated row count = ", gwAutomatedRowCount, sep = "" ) )

# ...and columns
gwAutomatedColumnCount <- ncol( gwAutomatedDataDF )
message( paste( "grp_week automated column count = ", gwAutomatedColumnCount, sep = "" ) )


grp_week automated row count = 1167
grp_week automated column count = 1169

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


In [9]:
# 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.
gwAutomatedNetworkDF <- gwAutomatedDataDF[ , 1 : gwAutomatedRowCount ]
#str( gwAutomatedNetworkDF )

In [10]:
# convert to a matrix
gwAutomatedNetworkMatrix <- as.matrix( gwAutomatedNetworkDF )
# str( gwAutomatedNetworkMatrix )

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 [11]:
#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 [12]:
# load data into igraph instance.
gwAutomatedNetworkIgraph <- graph.adjacency( gwAutomatedNetworkMatrix, mode = "undirected", weighted = TRUE )

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

# first, get just the data frame column with person ID:
personIdsColumn <- gwAutomatedDataDF[ , 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( gwAutomatedNetworkIgraph )$person_id <- personIdsList

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

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


IGRAPH f537944 UNW- 1167 253 -- 
+ attr: name (v/c), person_id (v/n), weight (e/n)
+ edges from f537944 (vertex names):
 [1] 1__3__author-2 --393__1451__source-3  1__3__author-2 --672__2100__source-3 
 [3] 1__3__author-2 --673__2101__source-3  1__3__author-2 --1018__2587__source-3
 [5] 1__3__author-2 --1019__2589__source-3 3__13__author-2--939__2470__source-3 
 [7] 3__13__author-2--941__2472__source-3  3__13__author-2--970__2513__source-3 
 [9] 3__13__author-2--971__2514__source-3  3__13__author-2--972__2515__source-3 
[11] 3__13__author-2--973__2516__source-3  3__13__author-2--974__2517__source-3 
[13] 3__13__author-2--991__2540__source-3  3__13__author-2--1151__2911__source-3
[15] 3__13__author-2--1152__2912__source-3 5__23__author-2--22__102__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 [14]:
# add person_type (column 1169)
personTypeColumnNumber <- 1169

# first, get just the data frame column with person type:
personTypesColumn <- gwAutomatedDataDF[ , 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( gwAutomatedNetworkIgraph )$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
gwAutomatedNetworkIgraph
V( gwAutomatedNetworkIgraph )$person_type


IGRAPH f537944 UNW- 1167 253 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from f537944 (vertex names):
 [1] 1__3__author-2 --393__1451__source-3  1__3__author-2 --672__2100__source-3 
 [3] 1__3__author-2 --673__2101__source-3  1__3__author-2 --1018__2587__source-3
 [5] 1__3__author-2 --1019__2589__source-3 3__13__author-2--939__2470__source-3 
 [7] 3__13__author-2--941__2472__source-3  3__13__author-2--970__2513__source-3 
 [9] 3__13__author-2--971__2514__source-3  3__13__author-2--972__2515__source-3 
[11] 3__13__author-2--973__2516__source-3  3__13__author-2--974__2517__source-3 
[13] 3__13__author-2--991__2540__source-3  3__13__author-2--1151__2911__source-3
[15] 3__13__author-2--1152__2912__source-3 5__23__author-2--22__102__source-3   
+ ... omitted several edges
  1. 2
  2. 1
  3. 2
  4. 1
  5. 2
  6. 1
  7. 1
  8. 2
  9. 2
  10. 1
  11. 2
  12. 1
  13. 2
  14. 1
  15. 1
  16. 2
  17. 2
  18. 1
  19. 1
  20. 2
  21. 1
  22. 3
  23. 1
  24. 1
  25. 3
  26. 3
  27. 2
  28. 1
  29. 1
  30. 1
  31. 1
  32. 1
  33. 1
  34. 1
  35. 1
  36. 1
  37. 1
  38. 2
  39. 1
  40. 1
  41. 1
  42. 1
  43. 3
  44. 1
  45. 3
  46. 1
  47. 1
  48. 1
  49. 2
  50. 1
  51. 1
  52. 2
  53. 1
  54. 1
  55. 1
  56. 1
  57. 1
  58. 1
  59. 1
  60. 1
  61. 1
  62. 1
  63. 1
  64. 1
  65. 1
  66. 1
  67. 1
  68. 1
  69. 3
  70. 1
  71. 1
  72. 2
  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. 1
  94. 1
  95. 1
  96. 1
  97. 1
  98. 1
  99. 1
  100. 1
  101. 1
  102. 1
  103. 1
  104. 1
  105. 1
  106. 1
  107. 1
  108. 1
  109. 1
  110. 1
  111. 1
  112. 1
  113. 1
  114. 1
  115. 1
  116. 1
  117. 1
  118. 1
  119. 1
  120. 1
  121. 3
  122. 1
  123. 1
  124. 1
  125. 1
  126. 1
  127. 1
  128. 1
  129. 1
  130. 1
  131. 1
  132. 1
  133. 1
  134. 1
  135. 1
  136. 1
  137. 1
  138. 1
  139. 1
  140. 1
  141. 1
  142. 1
  143. 1
  144. 2
  145. 1
  146. 1
  147. 1
  148. 1
  149. 1
  150. 1
  151. 2
  152. 1
  153. 1
  154. 1
  155. 1
  156. 1
  157. 1
  158. 1
  159. 1
  160. 1
  161. 3
  162. 1
  163. 1
  164. 1
  165. 1
  166. 1
  167. 1
  168. 1
  169. 1
  170. 1
  171. 1
  172. 1
  173. 2
  174. 1
  175. 1
  176. 2
  177. 2
  178. 3
  179. 3
  180. 1
  181. 1
  182. 1
  183. 2
  184. 1
  185. 1
  186. 1
  187. 1
  188. 1
  189. 1
  190. 1
  191. 1
  192. 1
  193. 1
  194. 1
  195. 1
  196. 1
  197. 2
  198. 1
  199. 1
  200. 1
  201. 1
  202. 1
  203. 1
  204. 1
  205. 1
  206. 1
  207. 1
  208. 1
  209. 1
  210. 3
  211. 1
  212. 1
  213. 1
  214. 1
  215. 1
  216. 1
  217. 1
  218. 1
  219. 1
  220. 1
  221. 1
  222. 3
  223. 1
  224. 1
  225. 1
  226. 1
  227. 1
  228. 1
  229. 1
  230. 1
  231. 3
  232. 1
  233. 2
  234. 1
  235. 1
  236. 1
  237. 1
  238. 1
  239. 1
  240. 1
  241. 1
  242. 1
  243. 1
  244. 1
  245. 1
  246. 1
  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. 1
  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. 3
  275. 1
  276. 1
  277. 1
  278. 1
  279. 1
  280. 1
  281. 1
  282. 1
  283. 1
  284. 1
  285. 1
  286. 1
  287. 1
  288. 1
  289. 1
  290. 1
  291. 1
  292. 1
  293. 1
  294. 3
  295. 1
  296. 1
  297. 3
  298. 3
  299. 1
  300. 1
  301. 1
  302. 1
  303. 1
  304. 1
  305. 1
  306. 1
  307. 1
  308. 1
  309. 2
  310. 4
  311. 2
  312. 3
  313. 1
  314. 1
  315. 1
  316. 2
  317. 1
  318. 1
  319. 1
  320. 1
  321. 1
  322. 3
  323. 1
  324. 1
  325. 1
  326. 2
  327. 1
  328. 1
  329. 1
  330. 3
  331. 1
  332. 1
  333. 1
  334. 1
  335. 1
  336. 1
  337. 1
  338. 1
  339. 1
  340. 1
  341. 1
  342. 1
  343. 1
  344. 1
  345. 1
  346. 1
  347. 1
  348. 1
  349. 1
  350. 1
  351. 1
  352. 1
  353. 1
  354. 1
  355. 1
  356. 1
  357. 1
  358. 1
  359. 1
  360. 1
  361. 1
  362. 1
  363. 1
  364. 1
  365. 1
  366. 1
  367. 1
  368. 1
  369. 2
  370. 1
  371. 1
  372. 1
  373. 1
  374. 1
  375. 1
  376. 1
  377. 1
  378. 1
  379. 1
  380. 1
  381. 1
  382. 1
  383. 1
  384. 1
  385. 1
  386. 1
  387. 1
  388. 1
  389. 1
  390. 1
  391. 1
  392. 1
  393. 3
  394. 1
  395. 1
  396. 1
  397. 1
  398. 3
  399. 1
  400. 1
  401. 1
  402. 1
  403. 3
  404. 1
  405. 1
  406. 1
  407. 1
  408. 1
  409. 1
  410. 1
  411. 1
  412. 1
  413. 1
  414. 1
  415. 1
  416. 1
  417. 1
  418. 1
  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. 1
  437. 1
  438. 1
  439. 1
  440. 1
  441. 1
  442. 3
  443. 3
  444. 3
  445. 1
  446. 1
  447. 1
  448. 1
  449. 1
  450. 1
  451. 1
  452. 1
  453. 1
  454. 1
  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. 1
  477. 1
  478. 2
  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. 3
  521. 1
  522. 3
  523. 3
  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. 3
  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. 3
  592. 1
  593. 1
  594. 3
  595. 1
  596. 1
  597. 1
  598. 1
  599. 1
  600. 1
  601. 1
  602. 1
  603. 1
  604. 1
  605. 1
  606. 1
  607. 1
  608. 1
  609. 1
  610. 1
  611. 1
  612. 1
  613. 1
  614. 1
  615. 1
  616. 1
  617. 1
  618. 1
  619. 1
  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. 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. 1
  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. 1
  739. 1
  740. 1
  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. 1
  756. 1
  757. 1
  758. 1
  759. 1
  760. 1
  761. 1
  762. 1
  763. 1
  764. 1
  765. 1
  766. 1
  767. 1
  768. 1
  769. 1
  770. 1
  771. 1
  772. 1
  773. 1
  774. 1
  775. 1
  776. 1
  777. 1
  778. 1
  779. 1
  780. 1
  781. 3
  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. 1
  795. 1
  796. 1
  797. 1
  798. 1
  799. 1
  800. 1
  801. 1
  802. 1
  803. 3
  804. 1
  805. 1
  806. 1
  807. 1
  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. 1
  829. 1
  830. 1
  831. 1
  832. 1
  833. 1
  834. 1
  835. 1
  836. 1
  837. 1
  838. 1
  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. 1
  858. 1
  859. 1
  860. 1
  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. 3
  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. 1
  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. 1
  912. 1
  913. 1
  914. 1
  915. 1
  916. 3
  917. 3
  918. 3
  919. 3
  920. 1
  921. 3
  922. 3
  923. 3
  924. 1
  925. 1
  926. 1
  927. 1
  928. 1
  929. 1
  930. 1
  931. 1
  932. 1
  933. 1
  934. 1
  935. 1
  936. 1
  937. 1
  938. 1
  939. 3
  940. 1
  941. 3
  942. 1
  943. 1
  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. 1
  1008. 1
  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. 1
  1023. 1
  1024. 1
  1025. 1
  1026. 1
  1027. 1
  1028. 1
  1029. 1
  1030. 1
  1031. 1
  1032. 1
  1033. 3
  1034. 3
  1035. 2
  1036. 3
  1037. 3
  1038. 3
  1039. 3
  1040. 3
  1041. 1
  1042. 1
  1043. 1
  1044. 1
  1045. 1
  1046. 3
  1047. 3
  1048. 1
  1049. 3
  1050. 3
  1051. 1
  1052. 1
  1053. 1
  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. 3
  1068. 1
  1069. 3
  1070. 3
  1071. 3
  1072. 3
  1073. 1
  1074. 3
  1075. 3
  1076. 3
  1077. 3
  1078. 1
  1079. 1
  1080. 1
  1081. 1
  1082. 3
  1083. 3
  1084. 3
  1085. 3
  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. 1
  1112. 1
  1113. 1
  1114. 1
  1115. 1
  1116. 1
  1117. 1
  1118. 1
  1119. 1
  1120. 1
  1121. 1
  1122. 1
  1123. 1
  1124. 1
  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. 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. 1
  1163. 1
  1164. 1
  1165. 1
  1166. 1
  1167. 1

In [15]:
# calais - include ties Greater than or equal to 0 (GE0)
gwAutomatedMeanTieWeightGE0Vector <- apply( gwAutomatedNetworkMatrix, 1, calculateListMean )
gwAutomatedDataDF$meanTieWeightGE0 <- gwAutomatedMeanTieWeightGE0Vector

# calais - include ties Greater than or equal to 1 (GE1)
gwAutomatedMeanTieWeightGE1Vector <- apply( gwAutomatedNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gwAutomatedDataDF$meanTieWeightGE1 <- gwAutomatedMeanTieWeightGE1Vector

# automated - Max tie weight?
gwAutomatedMaxTieWeightVector <- apply( gwAutomatedNetworkMatrix, 1, calculateListMax )
gwAutomatedDataDF$maxTieWeight <- gwAutomatedMaxTieWeightVector

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

# 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 f537944 UNW- 1167 253 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from f537944 (vertex names):
 [1] 1__3__author-2 --393__1451__source-3  1__3__author-2 --672__2100__source-3 
 [3] 1__3__author-2 --673__2101__source-3  1__3__author-2 --1018__2587__source-3
 [5] 1__3__author-2 --1019__2589__source-3 3__13__author-2--939__2470__source-3 
 [7] 3__13__author-2--941__2472__source-3  3__13__author-2--970__2513__source-3 
 [9] 3__13__author-2--971__2514__source-3  3__13__author-2--972__2515__source-3 
[11] 3__13__author-2--973__2516__source-3  3__13__author-2--974__2517__source-3 
[13] 3__13__author-2--991__2540__source-3  3__13__author-2--1151__2911__source-3
[15] 3__13__author-2--1152__2912__source-3 5__23__author-2--22__102__source-3   
+ ... omitted several edges

Calculate some basic metrics


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

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

# calculate the mean of the degrees.
gwAutomatedAvgDegree <- mean( gwAutomatedDegreeVector )
message( paste( "grp_week automated average degree = ", gwAutomatedAvgDegree, sep = "" ) )

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

# also add degree vector to original data frame
gwAutomatedDataDF$degree <- gwAutomatedDegreeVector

# 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
gwAutomatedNetworkIgraph
V( gwAutomatedNetworkIgraph )$degree


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

Calculate average source and author degree:


In [18]:
# average author degree (person types 2 and 4)
gwAutomatedAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gwAutomatedDataDF, includeBothIN = TRUE )
message( paste( "grp_week automated average author degree (2 and 4) = ", gwAutomatedAverageAuthorDegree2And4, sep = "" ) )

# average author degree (person type 2 only)
gwAutomatedAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gwAutomatedDataDF, includeBothIN = FALSE )
message( paste( "grp_week automated average author degree (only 2) = ", gwAutomatedAverageAuthorDegreeOnly2, sep = "" ) )

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

# average source degree (person type 3 only)
gwAutomatedAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gwAutomatedDataDF, includeBothIN = FALSE )
message( paste( "grp_week automated average source degree (only 3) = ", gwAutomatedAverageSourceDegreeOnly3, sep = "" ) )


grp_week automated average author degree (2 and 4) = 8.29032258064516
grp_week automated average author degree (only 2) = 8.13333333333333
grp_week automated average source degree (3 and 4) = 1.15418502202643
grp_week automated average source degree (only 3) = 1.10176991150442

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 [19]:
# 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.
gwAutomatedDegreeMean <- gwAutomatedAvgDegree
message( paste( "grp_week automated degree mean = ", gwAutomatedDegreeMean, sep = "" ) )

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

# what is the variance of these degrees?
gwAutomatedDegreeVar <- var( gwAutomatedDegreeVector )
message( paste( "grp_week automated degree Variance = ", gwAutomatedDegreeVar, sep = "" ) )

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

# calculate and plot degree distributions
gwAutomatedDegreeFrequenciesTable <- table( gwAutomatedDegreeVector )
gwAutomatedDegreeDistribution <- igraph::degree.distribution( gwAutomatedNetworkIgraph )
plot( gwAutomatedDegreeDistribution, xlab = "grp_week automated node degree" )
lines( gwAutomatedDegreeDistribution )

# subset vector to get only those that are above mean
gwAutomatedAboveMeanVector <- gwAutomatedDegreeVector[ gwAutomatedDegreeVector > gwAutomatedDegreeMax ]

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

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

# also add transitivity vector to original data frame
gwAutomatedDataDF$transitivity <- gwAutomatedTransitivityVector

# And, if you want averages of these:
gwAutomatedMeanTransitivity <- mean( gwAutomatedTransitivityVector, na.rm = TRUE )
message( paste( "grp_week automated mean transitivity = ", gwAutomatedMeanTransitivity, 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.
gwAutomatedDegreeCentralityOutput <- igraph::centralization.degree( gwAutomatedNetworkIgraph )
gwAutomatedDegreeCentrality <- gwAutomatedDegreeCentralityOutput$centralization
gwAutomatedDegreeCentralityMax <- gwAutomatedDegreeCentralityOutput$theoretical_max
message( paste( "grp_week automated degree centrality = ", gwAutomatedDegreeCentrality, " ( max = ", gwAutomatedDegreeCentralityMax, " )", sep = "" ) )

# node-level degree centrality
gwAutomatedDegreeCentralityVector <- gwAutomatedDegreeCentralityOutput$res
#message( paste( "grp_week automated betweenness = ", gwAutomatedBetweenness, sep = "" ) )

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

# also add degree centrality vector to original data frame
gwAutomatedDataDF$degreeCentrality <- gwAutomatedDegreeCentralityVector

# And, if you want averages of these:
gwAutomatedMeanDegreeCentrality <- mean( gwAutomatedDegreeCentralityVector, na.rm = TRUE )
message( paste( "grp_week automated mean degree centrality = ", gwAutomatedMeanDegreeCentrality, 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.
gwAutomatedBetweennessCentralityOutput <- igraph::centralization.betweenness( gwAutomatedNetworkIgraph, directed = FALSE )
gwAutomatedBetweennessCentrality <- gwAutomatedBetweennessCentralityOutput$centralization
gwAutomatedBetweennessCentralityMax <- gwAutomatedBetweennessCentralityOutput$theoretical_max
message( paste( "grp_week automated betweenness centrality = ", gwAutomatedBetweennessCentrality, " ( max = ", gwAutomatedBetweennessCentralityMax, " )", sep = "" ) )

# node-level undirected betweenness
gwAutomatedBetweennessVector <- gwAutomatedBetweennessCentralityOutput$res
#message( paste( "grp_week automated betweenness = ", gwAutomatedBetweenness, sep = "" ) )

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

# also add betweenness vector to original data frame
gwAutomatedDataDF$betweenness <- gwAutomatedBetweennessVector

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

# graph-level transitivity
gwAutomatedTransitivity <- igraph::transitivity( gwAutomatedNetworkIgraph, type = "global" )
message( paste( "grp_week automated transitivity = ", gwAutomatedTransitivity, sep = "" ) )

# graph-level density
gwAutomatedDensity <- igraph::graph.density( gwAutomatedNetworkIgraph )
message( paste( "grp_week automated density = ", gwAutomatedDensity, 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
gwAutomatedNetworkIgraph

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


grp_week automated degree mean = 0.433590402742074
grp_week automated degree SD = 1.67685363914443
grp_week automated degree Variance = 2.81183812711193
grp_week automated degree Max Value = 26
grp_week automated mean transitivity = 0.358767939506366
grp_week automated degree centrality = 0.0219265948518507 ( max = 1360722 )
grp_week automated mean degree centrality = 0.433590402742074
grp_week automated betweenness centrality = 0.00207525084843086 ( max = 791941370 )
grp_week automated mean betweenness = 5.70779777206512
grp_week automated transitivity = 0.0366598778004073
grp_week automated density = 0.000371861408869703
IGRAPH f537944 UNW- 1167 253 -- 
+ 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 f537944 (vertex names):
 [1] 1__3__author-2 --393__1451__source-3  1__3__author-2 --672__2100__source-3 
 [3] 1__3__author-2 --673__2101__source-3  1__3__author-2 --1018__2587__source-3
 [5] 1__3__author-2 --1019__2589__source-3 3__13__author-2--939__2470__source-3 
 [7] 3__13__author-2--941__2472__source-3  3__13__author-2--970__2513__source-3 
 [9] 3__13__author-2--971__2514__source-3  3__13__author-2--972__2515__source-3 
[11] 3__13__author-2--973__2516__source-3  3__13__author-2--974__2517__source-3 
+ ... omitted several edges

grp_week_3 (gw3) - human

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


In [20]:
# initialize variables
gwHumanDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gwHumanDataFile <- "sourcenet_data-20180326-034548-grp_month-human-week3_subset.tab"
gwHumanDataPath <- paste( gwHumanDataFolder, "/", gwHumanDataFile, sep = "" )

In [21]:
gwHumanDataPath


'/home/jonathanmorgan/work/django/research/work/phd_work/methods/data/network/grp_month/sourcenet_data-20180326-034548-grp_month-human-week3_subset.tab'

Load the data file into memory


In [22]:
# tab-delimited:
gwHumanDataDF <- read.delim( gwHumanDataPath, header = TRUE, row.names = 1, check.names = FALSE )

In [23]:
# get count of rows...
gwHumanRowCount <- nrow( gwHumanDataDF )
message( paste( "grp_week human row count = ", gwHumanRowCount, sep = "" ) )

# ...and columns
gwHumanColumnCount <- ncol( gwHumanDataDF )
message( paste( "grp_week human column count = ", gwHumanColumnCount, sep = "" ) )


grp_week human row count = 1167
grp_week human column count = 1169

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


In [24]:
# 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.
gwHumanNetworkDF <- gwHumanDataDF[ , 1 : gwHumanRowCount ]
#str( gwAutomatedNetworkDF )

In [25]:
# convert to a matrix
gwHumanNetworkMatrix <- as.matrix( gwHumanNetworkDF )
# str( gwHumanNetworkMatrix )

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 [26]:
#install.packages( "igraph" )
library( igraph )

Load our data matrix into an igraph object.


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

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

# first, get just the data frame column with person ID:
personIdsColumn <- gwHumanDataDF[ , 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( gwHumanNetworkIgraph )$person_id <- personIdsList

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

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


IGRAPH 07e627f UNW- 1167 266 -- 
+ attr: name (v/c), person_id (v/n), weight (e/n)
+ edges from 07e627f (vertex names):
 [1] 1__3__author-2 --672__2100__source-3  1__3__author-2 --673__2101__source-3 
 [3] 1__3__author-2 --1018__2587__source-3 1__3__author-2 --1019__2589__source-3
 [5] 3__13__author-2--939__2470__source-3  3__13__author-2--941__2472__source-3 
 [7] 3__13__author-2--970__2513__source-3  3__13__author-2--971__2514__source-3 
 [9] 3__13__author-2--972__2515__source-3  3__13__author-2--973__2516__source-3 
[11] 3__13__author-2--974__2517__source-3  3__13__author-2--991__2540__source-3 
[13] 5__23__author-2--22__102__source-3    5__23__author-2--666__2094__source-3 
[15] 5__23__author-2--667__2095__source-3  5__23__author-2--668__2096__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 [29]:
# add person_type (column 1169)
personTypeColumnNumber <- 1169

# first, get just the data frame column with person type:
personTypesColumn <- gwHumanDataDF[ , 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( gwHumanNetworkIgraph )$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
gwHumanNetworkIgraph
V( gwHumanNetworkIgraph )$person_type


IGRAPH 07e627f UNW- 1167 266 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from 07e627f (vertex names):
 [1] 1__3__author-2 --672__2100__source-3  1__3__author-2 --673__2101__source-3 
 [3] 1__3__author-2 --1018__2587__source-3 1__3__author-2 --1019__2589__source-3
 [5] 3__13__author-2--939__2470__source-3  3__13__author-2--941__2472__source-3 
 [7] 3__13__author-2--970__2513__source-3  3__13__author-2--971__2514__source-3 
 [9] 3__13__author-2--972__2515__source-3  3__13__author-2--973__2516__source-3 
[11] 3__13__author-2--974__2517__source-3  3__13__author-2--991__2540__source-3 
[13] 5__23__author-2--22__102__source-3    5__23__author-2--666__2094__source-3 
[15] 5__23__author-2--667__2095__source-3  5__23__author-2--668__2096__source-3 
+ ... omitted several edges
  1. 2
  2. 1
  3. 2
  4. 1
  5. 2
  6. 1
  7. 1
  8. 2
  9. 2
  10. 1
  11. 2
  12. 1
  13. 2
  14. 1
  15. 1
  16. 2
  17. 2
  18. 1
  19. 1
  20. 2
  21. 1
  22. 3
  23. 1
  24. 1
  25. 3
  26. 3
  27. 2
  28. 1
  29. 1
  30. 1
  31. 1
  32. 1
  33. 1
  34. 1
  35. 1
  36. 1
  37. 1
  38. 2
  39. 1
  40. 1
  41. 1
  42. 1
  43. 3
  44. 1
  45. 3
  46. 1
  47. 1
  48. 1
  49. 2
  50. 1
  51. 1
  52. 2
  53. 1
  54. 1
  55. 1
  56. 1
  57. 1
  58. 1
  59. 1
  60. 1
  61. 1
  62. 1
  63. 1
  64. 1
  65. 1
  66. 1
  67. 1
  68. 1
  69. 3
  70. 1
  71. 1
  72. 2
  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. 1
  94. 1
  95. 1
  96. 1
  97. 1
  98. 1
  99. 1
  100. 1
  101. 1
  102. 1
  103. 1
  104. 1
  105. 1
  106. 1
  107. 1
  108. 1
  109. 1
  110. 1
  111. 1
  112. 1
  113. 1
  114. 1
  115. 1
  116. 1
  117. 1
  118. 1
  119. 1
  120. 1
  121. 3
  122. 1
  123. 1
  124. 1
  125. 1
  126. 1
  127. 1
  128. 1
  129. 1
  130. 1
  131. 1
  132. 1
  133. 1
  134. 1
  135. 1
  136. 1
  137. 1
  138. 1
  139. 1
  140. 1
  141. 1
  142. 1
  143. 1
  144. 2
  145. 1
  146. 1
  147. 1
  148. 1
  149. 1
  150. 1
  151. 2
  152. 1
  153. 1
  154. 1
  155. 1
  156. 1
  157. 1
  158. 1
  159. 1
  160. 1
  161. 3
  162. 1
  163. 1
  164. 1
  165. 1
  166. 1
  167. 1
  168. 1
  169. 1
  170. 1
  171. 1
  172. 1
  173. 2
  174. 1
  175. 1
  176. 2
  177. 2
  178. 3
  179. 3
  180. 1
  181. 1
  182. 1
  183. 2
  184. 1
  185. 1
  186. 1
  187. 1
  188. 1
  189. 1
  190. 1
  191. 1
  192. 1
  193. 1
  194. 1
  195. 1
  196. 1
  197. 2
  198. 1
  199. 1
  200. 1
  201. 1
  202. 1
  203. 1
  204. 1
  205. 1
  206. 1
  207. 1
  208. 1
  209. 1
  210. 3
  211. 1
  212. 1
  213. 1
  214. 1
  215. 1
  216. 1
  217. 1
  218. 1
  219. 1
  220. 1
  221. 1
  222. 3
  223. 1
  224. 1
  225. 1
  226. 1
  227. 1
  228. 1
  229. 1
  230. 1
  231. 3
  232. 1
  233. 2
  234. 1
  235. 1
  236. 1
  237. 1
  238. 1
  239. 1
  240. 1
  241. 1
  242. 1
  243. 1
  244. 1
  245. 1
  246. 1
  247. 1
  248. 1
  249. 3
  250. 1
  251. 1
  252. 1
  253. 1
  254. 1
  255. 1
  256. 1
  257. 1
  258. 1
  259. 1
  260. 1
  261. 1
  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. 3
  275. 1
  276. 1
  277. 1
  278. 1
  279. 1
  280. 1
  281. 1
  282. 1
  283. 1
  284. 1
  285. 1
  286. 1
  287. 1
  288. 1
  289. 1
  290. 1
  291. 1
  292. 1
  293. 1
  294. 3
  295. 1
  296. 1
  297. 3
  298. 3
  299. 1
  300. 1
  301. 1
  302. 1
  303. 1
  304. 1
  305. 1
  306. 1
  307. 1
  308. 1
  309. 2
  310. 2
  311. 2
  312. 3
  313. 1
  314. 1
  315. 1
  316. 2
  317. 1
  318. 1
  319. 1
  320. 3
  321. 1
  322. 3
  323. 1
  324. 1
  325. 1
  326. 2
  327. 1
  328. 1
  329. 1
  330. 3
  331. 1
  332. 1
  333. 1
  334. 1
  335. 1
  336. 1
  337. 1
  338. 1
  339. 1
  340. 1
  341. 1
  342. 1
  343. 1
  344. 1
  345. 1
  346. 1
  347. 1
  348. 1
  349. 1
  350. 1
  351. 1
  352. 1
  353. 1
  354. 1
  355. 1
  356. 1
  357. 1
  358. 1
  359. 1
  360. 1
  361. 1
  362. 1
  363. 3
  364. 1
  365. 1
  366. 1
  367. 1
  368. 1
  369. 2
  370. 1
  371. 1
  372. 1
  373. 1
  374. 1
  375. 1
  376. 1
  377. 1
  378. 1
  379. 1
  380. 1
  381. 1
  382. 1
  383. 1
  384. 1
  385. 1
  386. 1
  387. 1
  388. 1
  389. 1
  390. 1
  391. 1
  392. 1
  393. 1
  394. 1
  395. 1
  396. 1
  397. 1
  398. 3
  399. 1
  400. 1
  401. 1
  402. 1
  403. 3
  404. 1
  405. 1
  406. 1
  407. 1
  408. 1
  409. 1
  410. 1
  411. 1
  412. 1
  413. 1
  414. 1
  415. 1
  416. 1
  417. 1
  418. 1
  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. 1
  437. 1
  438. 1
  439. 1
  440. 1
  441. 1
  442. 3
  443. 3
  444. 3
  445. 1
  446. 1
  447. 1
  448. 1
  449. 1
  450. 1
  451. 1
  452. 1
  453. 1
  454. 1
  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. 1
  477. 1
  478. 2
  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. 3
  521. 1
  522. 3
  523. 3
  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. 3
  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. 3
  592. 1
  593. 1
  594. 3
  595. 1
  596. 1
  597. 1
  598. 1
  599. 1
  600. 1
  601. 1
  602. 1
  603. 1
  604. 1
  605. 1
  606. 1
  607. 1
  608. 1
  609. 1
  610. 1
  611. 1
  612. 1
  613. 1
  614. 1
  615. 1
  616. 1
  617. 1
  618. 1
  619. 1
  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. 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. 1
  738. 1
  739. 1
  740. 1
  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. 1
  756. 1
  757. 1
  758. 1
  759. 1
  760. 1
  761. 1
  762. 1
  763. 1
  764. 1
  765. 1
  766. 1
  767. 1
  768. 1
  769. 1
  770. 1
  771. 1
  772. 1
  773. 1
  774. 1
  775. 1
  776. 1
  777. 1
  778. 1
  779. 1
  780. 1
  781. 3
  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. 1
  795. 1
  796. 1
  797. 1
  798. 1
  799. 1
  800. 1
  801. 1
  802. 1
  803. 3
  804. 1
  805. 1
  806. 1
  807. 1
  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. 1
  829. 1
  830. 1
  831. 1
  832. 1
  833. 1
  834. 1
  835. 1
  836. 1
  837. 1
  838. 1
  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. 1
  858. 1
  859. 1
  860. 1
  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. 3
  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. 1
  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. 1
  912. 1
  913. 1
  914. 1
  915. 1
  916. 3
  917. 3
  918. 3
  919. 3
  920. 3
  921. 3
  922. 3
  923. 3
  924. 1
  925. 1
  926. 1
  927. 1
  928. 1
  929. 1
  930. 1
  931. 1
  932. 1
  933. 1
  934. 1
  935. 1
  936. 1
  937. 1
  938. 1
  939. 3
  940. 1
  941. 3
  942. 1
  943. 1
  944. 1
  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. 1
  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. 1
  1023. 1
  1024. 1
  1025. 1
  1026. 1
  1027. 1
  1028. 1
  1029. 1
  1030. 1
  1031. 1
  1032. 3
  1033. 3
  1034. 3
  1035. 2
  1036. 3
  1037. 3
  1038. 3
  1039. 3
  1040. 3
  1041. 1
  1042. 1
  1043. 1
  1044. 1
  1045. 1
  1046. 3
  1047. 3
  1048. 1
  1049. 3
  1050. 3
  1051. 1
  1052. 1
  1053. 1
  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. 3
  1068. 3
  1069. 3
  1070. 3
  1071. 3
  1072. 3
  1073. 3
  1074. 3
  1075. 3
  1076. 3
  1077. 3
  1078. 1
  1079. 1
  1080. 1
  1081. 1
  1082. 3
  1083. 3
  1084. 3
  1085. 3
  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. 1
  1112. 1
  1113. 1
  1114. 1
  1115. 1
  1116. 1
  1117. 1
  1118. 1
  1119. 1
  1120. 1
  1121. 1
  1122. 1
  1123. 1
  1124. 1
  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. 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. 1
  1165. 1
  1166. 1
  1167. 1

In [30]:
# human - include ties Greater than or equal to 0 (GE0)
gwHumanMeanTieWeightGE0Vector <- apply( gwHumanNetworkMatrix, 1, calculateListMean )
gwHumanDataDF$meanTieWeightGE0 <- gwHumanMeanTieWeightGE0Vector

# human - include ties Greater than or equal to 1 (GE1)
gwHumanMeanTieWeightGE1Vector <- apply( gwHumanNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gwHumanDataDF$meanTieWeightGE1 <- gwHumanMeanTieWeightGE1Vector

# human - Max tie weight?
gwHumanMaxTieWeightVector <- apply( gwHumanNetworkMatrix, 1, calculateListMax )
gwHumanDataDF$maxTieWeight <- gwHumanMaxTieWeightVector

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

# 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 07e627f UNW- 1167 266 -- 
+ attr: name (v/c), person_id (v/n), person_type (v/n), weight (e/n)
+ edges from 07e627f (vertex names):
 [1] 1__3__author-2 --672__2100__source-3  1__3__author-2 --673__2101__source-3 
 [3] 1__3__author-2 --1018__2587__source-3 1__3__author-2 --1019__2589__source-3
 [5] 3__13__author-2--939__2470__source-3  3__13__author-2--941__2472__source-3 
 [7] 3__13__author-2--970__2513__source-3  3__13__author-2--971__2514__source-3 
 [9] 3__13__author-2--972__2515__source-3  3__13__author-2--973__2516__source-3 
[11] 3__13__author-2--974__2517__source-3  3__13__author-2--991__2540__source-3 
[13] 5__23__author-2--22__102__source-3    5__23__author-2--666__2094__source-3 
[15] 5__23__author-2--667__2095__source-3  5__23__author-2--668__2096__source-3 
+ ... omitted several edges

Calculate some basic metrics


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

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

# calculate the mean of the degrees.
gwHumanAvgDegree <- mean( gwHumanDegreeVector )
message( paste( "grp_week human average degree = ", gwHumanAvgDegree, sep = "" ) )

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

# also add degree vector to original data frame
gwHumanDataDF$degree <- gwHumanDegreeVector

# 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
gwHumanNetworkIgraph
V( gwHumanNetworkIgraph )$degree


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

Calculate average source and author degree:


In [33]:
# average author degree (person types 2 and 4)
gwHumanAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gwHumanDataDF, includeBothIN = TRUE )
message( paste( "grp_week human average author degree (2 and 4) = ", gwHumanAverageAuthorDegree2And4, sep = "" ) )

# average author degree (person type 2 only)
gwHumanAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gwHumanDataDF, includeBothIN = FALSE )
message( paste( "grp_week human average author degree (only 2) = ", gwHumanAverageAuthorDegreeOnly2, sep = "" ) )

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

# average source degree (person type 3 only)
gwHumanAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gwHumanDataDF, includeBothIN = FALSE )
message( paste( "grp_week human average source degree (only 3) = ", gwHumanAverageSourceDegreeOnly3, sep = "" ) )


grp_week human average author degree (2 and 4) = 8.67741935483871
grp_week human average author degree (only 2) = 8.67741935483871
grp_week human average source degree (3 and 4) = 1.08677685950413
grp_week human average source degree (only 3) = 1.08677685950413

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 [34]:
# 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.
gwHumanDegreeMean <- gwHumanAvgDegree
message( paste( "grp_week human degree mean = ", gwHumanDegreeMean, sep = "" ) )

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

# what is the variance of these degrees?
gwHumanDegreeVar <- var( gwHumanDegreeVector )
message( paste( "grp_week human degree Variance = ", gwHumanDegreeVar, sep = "" ) )

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

# calculate and plot degree distributions
gwHumanDegreeFrequenciesTable <- table( gwHumanDegreeVector )
gwHumanDegreeDistribution <- igraph::degree.distribution( gwHumanNetworkIgraph )
plot( gwHumanDegreeDistribution, xlab = "grp_week human node degree" )
lines( gwHumanDegreeDistribution )

# subset vector to get only those that are above mean
gwHumanAboveMeanVector <- gwHumanDegreeVector[ gwHumanDegreeVector > gwHumanDegreeMax ]

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

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

# also add transitivity vector to original data frame
gwHumanDataDF$transitivity <- gwHumanTransitivityVector

# And, if you want averages of these:
gwHumanMeanTransitivity <- mean( gwHumanTransitivityVector, na.rm = TRUE )
message( paste( "grp_week human mean transitivity = ", gwHumanMeanTransitivity, 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.
gwHumanDegreeCentralityOutput <- igraph::centralization.degree( gwHumanNetworkIgraph )
gwHumanDegreeCentrality <- gwHumanDegreeCentralityOutput$centralization
gwHumanDegreeCentralityMax <- gwHumanDegreeCentralityOutput$theoretical_max
message( paste( "grp_week human degree centrality = ", gwHumanDegreeCentrality, " ( max = ", gwHumanDegreeCentralityMax, " )", sep = "" ) )

# node-level degree centrality
gwHumanDegreeCentralityVector <- gwHumanDegreeCentralityOutput$res
#message( paste( "grp_week human betweenness = ", gwHumanBetweenness, sep = "" ) )

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

# also add degree centrality vector to original data frame
gwHumanDataDF$degreeCentrality <- gwHumanDegreeCentralityVector

# And, if you want averages of these:
gwHumanMeanDegreeCentrality <- mean( gwHumanDegreeCentralityVector, na.rm = TRUE )
message( paste( "grp_week human mean degree centrality = ", gwHumanMeanDegreeCentrality, 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.
gwHumanBetweennessCentralityOutput <- igraph::centralization.betweenness( gwHumanNetworkIgraph, directed = FALSE )
gwHumanBetweennessCentrality <- gwHumanBetweennessCentralityOutput$centralization
gwHumanBetweennessCentralityMax <- gwHumanBetweennessCentralityOutput$theoretical_max
message( paste( "grp_week human betweenness centrality = ", gwHumanBetweennessCentrality, " ( max = ", gwHumanBetweennessCentralityMax, " )", sep = "" ) )

# node-level undirected betweenness
gwHumanBetweennessVector <- gwHumanBetweennessCentralityOutput$res
#message( paste( "grp_week human betweenness = ", gwHumanBetweenness, sep = "" ) )

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

# also add betweenness vector to original data frame
gwHumanDataDF$betweenness <- gwHumanBetweennessVector

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

# graph-level transitivity
gwHumanTransitivity <- igraph::transitivity( gwHumanNetworkIgraph, type = "global" )
message( paste( "grp_week human transitivity = ", gwHumanTransitivity, sep = "" ) )

# graph-level density
gwHumanDensity <- igraph::graph.density( gwHumanNetworkIgraph )
message( paste( "grp_week human density = ", gwHumanDensity, 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
gwHumanNetworkIgraph

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


grp_week human degree mean = 0.455869751499572
grp_week human degree SD = 1.76915570666071
grp_week human degree Variance = 3.12991191441014
grp_week human degree Max Value = 28
grp_week human mean transitivity = 0.353956354756355
grp_week human degree centrality = 0.0236227532148374 ( max = 1360722 )
grp_week human mean degree centrality = 0.455869751499572
grp_week human betweenness centrality = 0.00244100519713978 ( max = 791941370 )
grp_week human mean betweenness = 6.50214224507284
grp_week human transitivity = 0.0303571428571429
grp_week human density = 0.000390968912092257
IGRAPH 07e627f UNW- 1167 266 -- 
+ 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 07e627f (vertex names):
 [1] 1__3__author-2 --672__2100__source-3  1__3__author-2 --673__2101__source-3 
 [3] 1__3__author-2 --1018__2587__source-3 1__3__author-2 --1019__2589__source-3
 [5] 3__13__author-2--939__2470__source-3  3__13__author-2--941__2472__source-3 
 [7] 3__13__author-2--970__2513__source-3  3__13__author-2--971__2514__source-3 
 [9] 3__13__author-2--972__2515__source-3  3__13__author-2--973__2516__source-3 
[11] 3__13__author-2--974__2517__source-3  3__13__author-2--991__2540__source-3 
+ ... omitted several edges

Save workspace image

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


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


workspace_file_name = igraph-grp_month-week_3.RData

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


saved workspace_file_name = igraph-grp_month-week_3.RData