network_df

  1. article-level (single network) statistics
  2. out = network_df.csv
  3. calculation notes below

In [1]:
import networkx as nx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import os
from glob import glob

pd.set_option('display.mpl_style', 'default') 
# display all the columns
pd.set_option('display.width', 5000) 
pd.set_option('display.max_columns', 60)

gml_files = glob('../output/network/*/*.gml')

In [2]:
def calculate_graph_inf(graph):
    graph.name = filename
    info = nx.info(graph)
    print info
    #plot spring layout
    #plt.figure(figsize=(10,10))
    #nx.draw_spring(graph, arrows=True, with_labels=True)

def highest_centrality(cent_dict):
    """Returns a tuple (node,value) with the node
    with largest value from centrality dictionary."""
    # create ordered tuple of centrality data
    cent_items = [(b,a) for (a,b) in cent_dict.iteritems()]
    # sort in descending order
    cent_items.sort()
    cent_items.reverse()
    return tuple(reversed(cent_items[0]))

In [3]:
# create empty dataframe with columns

network_data_columns = ['name',
                    'sentiment',
                    'n nodes',
                    'n edges',
                    'avg degree',
                    'density',
                    'avg deg cent',
                    'avg bet cent',
                    'avg clo cent',
                    'highest degc',
                    'highest betc',
                    'highest cloc',
                    'avg node connect',
                    'deg assort coeff',
                    'avg in-deg',
                    'avg out-deg',
                    'n strong comp',
                    'n weak comp',
                    'n conn comp',
                    'Gc size'
                    ]

network_data = pd.DataFrame(columns = network_data_columns)

In [4]:
# graph = directed, ugraph = undirected

for graph_num, gml_graph in enumerate(gml_files):
    graph = nx.read_gml(gml_graph)
    ugraph = graph.to_undirected() ## to undirected graph
    ## adding those missing edges back
    U = graph.to_undirected(reciprocal=True)
    e = U.edges()
    ugraph.add_edges_from(e)
    ##
    (filepath, filename) = os.path.split(gml_graph)
    print('-' * 40)
    print(gml_graph)
    calculate_graph_inf(graph)
    #calculate_graph_inf(ugraph)

    # calculate variables
    
    sent = filepath.split('/')[-1]
    nodes = nx.number_of_nodes(graph)
    edges = nx.number_of_edges(graph)
    density = float("{0:.4f}".format(nx.density(graph)))
    avg_deg_cen = np.array(nx.degree_centrality(graph).values()).mean()
    avg_bet_cen = np.array(nx.betweenness_centrality(graph).values()).mean()
    avg_clo_cen = np.array(nx.closeness_centrality(graph).values()).mean()
    in_deg = sum(graph.in_degree().values())/float(nx.number_of_nodes(graph))
    out_deg = sum(graph.out_degree().values())/float(nx.number_of_nodes(graph))
    avg_deg = float("{0:.4f}".format(in_deg + out_deg))
    strong_comp = nx.number_strongly_connected_components(graph)
    weak_comp =  nx.number_weakly_connected_components(graph)
    avg_node_con = float("{0:.4f}".format((nx.average_node_connectivity(graph))))
    deg_assort_coeff = float("{0:.4f}".format((nx.degree_assortativity_coefficient(graph))))
    conn_comp = nx.number_connected_components(ugraph)
    deg_cen = nx.degree_centrality(graph)
    bet_cen = nx.betweenness_centrality(graph)
    clo_cen = nx.closeness_centrality(graph)
    highest_deg_cen = highest_centrality(deg_cen)
    highest_bet_cen = highest_centrality(bet_cen)
    highest_clo_cen = highest_centrality(clo_cen)
    Gc = len(max(nx.connected_component_subgraphs(ugraph), key=len))

    # save variables into list

    graph_values = {'name':filename,
                    'sentiment':sent,
                    'n nodes':nodes,
                    'n edges':edges,
                    'avg degree':avg_deg,
                    'density':density,
                    'avg deg cent':"%.4f" % avg_deg_cen,
                    'avg bet cent':"%.4f" % avg_bet_cen,
                    'avg clo cent':"%.4f" % avg_clo_cen,
                    'highest degc':highest_deg_cen,
                    'highest betc':highest_bet_cen,
                    'highest cloc':highest_clo_cen,
                    'avg node connect':avg_node_con,
                    'deg assort coeff':deg_assort_coeff,
                    'avg in-deg':"%.4f" % in_deg,
                    'avg out-deg':"%.4f" % out_deg,
                    'n strong comp':strong_comp,
                    'n weak comp':weak_comp,
                    'n conn comp':conn_comp,
                    'Gc size':Gc
                    }
    
    network_data = network_data.append(graph_values, ignore_index=True)
    
#    if graph_num == 0:
#        break


----------------------------------------
../output/network/negative/article03.gml
Name: article03.gml
Type: MultiDiGraph
Number of nodes: 18
Number of edges: 13
Average in degree:   0.7222
Average out degree:   0.7222
----------------------------------------
../output/network/negative/article05.gml
Name: article05.gml
Type: MultiDiGraph
Number of nodes: 22
Number of edges: 25
Average in degree:   1.1364
Average out degree:   1.1364
----------------------------------------
../output/network/negative/article06.gml
Name: article06.gml
Type: MultiDiGraph
Number of nodes: 124
Number of edges: 121
Average in degree:   0.9758
Average out degree:   0.9758
----------------------------------------
../output/network/negative/article07.gml
Name: article07.gml
Type: MultiDiGraph
Number of nodes: 56
Number of edges: 57
Average in degree:   1.0179
Average out degree:   1.0179
----------------------------------------
../output/network/negative/article1.gml
Name: article1.gml
Type: MultiDiGraph
Number of nodes: 140
Number of edges: 147
Average in degree:   1.0500
Average out degree:   1.0500
----------------------------------------
../output/network/negative/article1001.gml
Name: article1001.gml
Type: MultiDiGraph
Number of nodes: 134
Number of edges: 134
Average in degree:   1.0000
Average out degree:   1.0000
----------------------------------------
../output/network/negative/article1021.gml
Name: article1021.gml
Type: MultiDiGraph
Number of nodes: 64
Number of edges: 64
Average in degree:   1.0000
Average out degree:   1.0000
----------------------------------------
../output/network/negative/article152.gml
Name: article152.gml
Type: MultiDiGraph
Number of nodes: 78
Number of edges: 67
Average in degree:   0.8590
Average out degree:   0.8590
----------------------------------------
../output/network/negative/article2308.gml
Name: article2308.gml
Type: MultiDiGraph
Number of nodes: 66
Number of edges: 56
Average in degree:   0.8485
Average out degree:   0.8485
----------------------------------------
../output/network/negative/article3335.gml
Name: article3335.gml
Type: MultiDiGraph
Number of nodes: 120
Number of edges: 128
Average in degree:   1.0667
Average out degree:   1.0667
----------------------------------------
../output/network/negative/article4106.gml
Name: article4106.gml
Type: MultiDiGraph
Number of nodes: 38
Number of edges: 36
Average in degree:   0.9474
Average out degree:   0.9474
----------------------------------------
../output/network/negative/article432.gml
Name: article432.gml
Type: MultiDiGraph
Number of nodes: 100
Number of edges: 96
Average in degree:   0.9600
Average out degree:   0.9600
----------------------------------------
../output/network/negative/article5164.gml
Name: article5164.gml
Type: MultiDiGraph
Number of nodes: 104
Number of edges: 119
Average in degree:   1.1442
Average out degree:   1.1442
----------------------------------------
../output/network/negative/article5717.gml
Name: article5717.gml
Type: MultiDiGraph
Number of nodes: 62
Number of edges: 62
Average in degree:   1.0000
Average out degree:   1.0000
----------------------------------------
../output/network/negative/article5813.gml
Name: article5813.gml
Type: MultiDiGraph
Number of nodes: 50
Number of edges: 54
Average in degree:   1.0800
Average out degree:   1.0800
----------------------------------------
../output/network/negative/article621.gml
Name: article621.gml
Type: MultiDiGraph
Number of nodes: 30
Number of edges: 32
Average in degree:   1.0667
Average out degree:   1.0667
----------------------------------------
../output/network/negative/article683.gml
Name: article683.gml
Type: MultiDiGraph
Number of nodes: 234
Number of edges: 236
Average in degree:   1.0085
Average out degree:   1.0085
----------------------------------------
../output/network/negative/article703.gml
Name: article703.gml
Type: MultiDiGraph
Number of nodes: 282
Number of edges: 280
Average in degree:   0.9929
Average out degree:   0.9929
----------------------------------------
../output/network/negative/article774.gml
Name: article774.gml
Type: MultiDiGraph
Number of nodes: 57
Number of edges: 54
Average in degree:   0.9474
Average out degree:   0.9474
----------------------------------------
../output/network/negative/article782.gml
Name: article782.gml
Type: MultiDiGraph
Number of nodes: 84
Number of edges: 77
Average in degree:   0.9167
Average out degree:   0.9167
----------------------------------------
../output/network/negative/article99.gml
Name: article99.gml
Type: MultiDiGraph
Number of nodes: 45
Number of edges: 46
Average in degree:   1.0222
Average out degree:   1.0222
----------------------------------------
../output/network/neutral/article2047.gml
Name: article2047.gml
Type: MultiDiGraph
Number of nodes: 52
Number of edges: 61
Average in degree:   1.1731
Average out degree:   1.1731
----------------------------------------
../output/network/neutral/article532.gml
Name: article532.gml
Type: MultiDiGraph
Number of nodes: 51
Number of edges: 37
Average in degree:   0.7255
Average out degree:   0.7255
----------------------------------------
../output/network/neutral/article54.gml
Name: article54.gml
Type: MultiDiGraph
Number of nodes: 48
Number of edges: 37
Average in degree:   0.7708
Average out degree:   0.7708
----------------------------------------
../output/network/neutral/article63.gml
Name: article63.gml
Type: MultiDiGraph
Number of nodes: 17
Number of edges: 15
Average in degree:   0.8824
Average out degree:   0.8824
----------------------------------------
../output/network/neutral/article647.gml
Name: article647.gml
Type: MultiDiGraph
Number of nodes: 54
Number of edges: 48
Average in degree:   0.8889
Average out degree:   0.8889
----------------------------------------
../output/network/neutral/article756.gml
Name: article756.gml
Type: MultiDiGraph
Number of nodes: 41
Number of edges: 40
Average in degree:   0.9756
Average out degree:   0.9756
----------------------------------------
../output/network/positive/article02.gml
Name: article02.gml
Type: MultiDiGraph
Number of nodes: 36
Number of edges: 31
Average in degree:   0.8611
Average out degree:   0.8611
----------------------------------------
../output/network/positive/article1105.gml
Name: article1105.gml
Type: MultiDiGraph
Number of nodes: 38
Number of edges: 31
Average in degree:   0.8158
Average out degree:   0.8158
----------------------------------------
../output/network/positive/article111.gml
Name: article111.gml
Type: MultiDiGraph
Number of nodes: 83
Number of edges: 75
Average in degree:   0.9036
Average out degree:   0.9036
----------------------------------------
../output/network/positive/article1542.gml
Name: article1542.gml
Type: MultiDiGraph
Number of nodes: 45
Number of edges: 51
Average in degree:   1.1333
Average out degree:   1.1333
----------------------------------------
../output/network/positive/article1804.gml
Name: article1804.gml
Type: MultiDiGraph
Number of nodes: 42
Number of edges: 50
Average in degree:   1.1905
Average out degree:   1.1905
----------------------------------------
../output/network/positive/article2.gml
Name: article2.gml
Type: MultiDiGraph
Number of nodes: 28
Number of edges: 23
Average in degree:   0.8214
Average out degree:   0.8214
----------------------------------------
../output/network/positive/article29.gml
Name: article29.gml
Type: MultiDiGraph
Number of nodes: 74
Number of edges: 61
Average in degree:   0.8243
Average out degree:   0.8243
----------------------------------------
../output/network/positive/article30.gml
Name: article30.gml
Type: MultiDiGraph
Number of nodes: 17
Number of edges: 17
Average in degree:   1.0000
Average out degree:   1.0000
----------------------------------------
../output/network/positive/article31.gml
Name: article31.gml
Type: MultiDiGraph
Number of nodes: 48
Number of edges: 43
Average in degree:   0.8958
Average out degree:   0.8958
----------------------------------------
../output/network/positive/article36.gml
Name: article36.gml
Type: MultiDiGraph
Number of nodes: 15
Number of edges: 12
Average in degree:   0.8000
Average out degree:   0.8000
----------------------------------------
../output/network/positive/article37.gml
Name: article37.gml
Type: MultiDiGraph
Number of nodes: 21
Number of edges: 28
Average in degree:   1.3333
Average out degree:   1.3333
----------------------------------------
../output/network/positive/article4150.gml
Name: article4150.gml
Type: MultiDiGraph
Number of nodes: 24
Number of edges: 18
Average in degree:   0.7500
Average out degree:   0.7500
----------------------------------------
../output/network/positive/article4210.gml
Name: article4210.gml
Type: MultiDiGraph
Number of nodes: 63
Number of edges: 71
Average in degree:   1.1270
Average out degree:   1.1270
----------------------------------------
../output/network/positive/article4303.gml
Name: article4303.gml
Type: MultiDiGraph
Number of nodes: 24
Number of edges: 19
Average in degree:   0.7917
Average out degree:   0.7917
----------------------------------------
../output/network/positive/article46.gml
Name: article46.gml
Type: MultiDiGraph
Number of nodes: 80
Number of edges: 83
Average in degree:   1.0375
Average out degree:   1.0375
----------------------------------------
../output/network/positive/article5.gml
Name: article5.gml
Type: MultiDiGraph
Number of nodes: 58
Number of edges: 51
Average in degree:   0.8793
Average out degree:   0.8793
----------------------------------------
../output/network/positive/article5077.gml
Name: article5077.gml
Type: MultiDiGraph
Number of nodes: 45
Number of edges: 49
Average in degree:   1.0889
Average out degree:   1.0889
----------------------------------------
../output/network/positive/article609.gml
Name: article609.gml
Type: MultiDiGraph
Number of nodes: 134
Number of edges: 139
Average in degree:   1.0373
Average out degree:   1.0373
----------------------------------------
../output/network/positive/article620.gml
Name: article620.gml
Type: MultiDiGraph
Number of nodes: 76
Number of edges: 68
Average in degree:   0.8947
Average out degree:   0.8947
----------------------------------------
../output/network/positive/article6247.gml
Name: article6247.gml
Type: MultiDiGraph
Number of nodes: 109
Number of edges: 96
Average in degree:   0.8807
Average out degree:   0.8807
----------------------------------------
../output/network/positive/article664.gml
Name: article664.gml
Type: MultiDiGraph
Number of nodes: 29
Number of edges: 27
Average in degree:   0.9310
Average out degree:   0.9310
----------------------------------------
../output/network/positive/article665.gml
Name: article665.gml
Type: MultiDiGraph
Number of nodes: 35
Number of edges: 30
Average in degree:   0.8571
Average out degree:   0.8571
----------------------------------------
../output/network/positive/article828.gml
Name: article828.gml
Type: MultiDiGraph
Number of nodes: 56
Number of edges: 54
Average in degree:   0.9643
Average out degree:   0.9643

In [5]:
network_data


Out[5]:
name sentiment n nodes n edges avg degree density avg deg cent avg bet cent avg clo cent highest degc highest betc highest cloc avg node connect deg assort coeff avg in-deg avg out-deg n strong comp n weak comp n conn comp Gc size
0 article03.gml negative 18 13 1.4444 0.0425 0.0850 0.0025 0.0480 (parents, 0.176470588235) (immune system, 0.0147058823529) (parents, 0.210084033613) 0.0686 NaN 0.7222 0.7222 18 5 5 6
1 article05.gml negative 22 25 2.2727 0.0541 0.1082 0.0010 0.0558 (Jim Carrey, 0.333333333333) (mandatory vaccines, 0.00952380952381) (Jim Carrey, 0.321428571429) 0.0758 0.1488 1.1364 1.1364 22 3 3 14
2 article06.gml negative 124 121 1.9516 0.0079 0.0159 0.0003 0.0129 (shingles vaccine, 0.130081300813) (shingles vaccine, 0.00739704118353) (shingles vaccine, 0.130216802168) 0.0254 -0.1979 0.9758 0.9758 122 10 10 62
3 article07.gml negative 56 57 2.0357 0.0185 0.0370 0.0024 0.0338 (scientific fraud, 0.181818181818) (CDC, 0.0276094276094) (Rep. Bill Posey, 0.204642166344) 0.0802 -0.0986 1.0179 1.0179 55 3 3 39
4 article1.gml negative 140 147 2.1000 0.0076 0.0151 0.0001 0.0099 (mercury, 0.107913669065) (mercury, 0.00280210614117) (CDC, 0.106766760505) 0.0161 -0.0168 1.0500 1.0500 138 17 17 71
5 article1001.gml negative 134 134 2.0000 0.0075 0.0150 0.0002 0.0111 (SB 277, 0.157894736842) (vaccine damage, 0.00398724082935) (SB 277, 0.144760635767) 0.0212 -0.2159 1.0000 1.0000 134 17 17 84
6 article1021.gml negative 64 64 2.0000 0.0159 0.0317 0.0003 0.0219 (SV40, 0.285714285714) (SV40, 0.0143369175627) (SV40, 0.183006535948) 0.0335 -0.2714 1.0000 1.0000 64 10 10 27
7 article152.gml negative 78 67 1.7179 0.0112 0.0223 0.0012 0.0207 (thimerosal, 0.207792207792) (thimerosal, 0.0261449077239) (thimerosal, 0.15012987013) 0.0470 -0.0241 0.8590 0.8590 78 17 17 35
8 article2308.gml negative 66 56 1.6970 0.0131 0.0261 0.0002 0.0178 (National Vaccine Injury Compensation Program,... (National Vaccine Injury Compensation Program,... (National Vaccine Injury Compensation Program,... 0.0254 -0.2020 0.8485 0.8485 66 11 11 32
9 article3335.gml negative 120 128 2.1333 0.0090 0.0179 0.0004 0.0172 (vaccines, 0.210084033613) (vaccines, 0.0210084033613) (adverse effects, 0.117647058824) 0.0359 -0.3449 1.0667 1.0667 119 8 8 77
10 article4106.gml negative 38 36 1.8947 0.0256 0.0512 0.0018 0.0364 (doctors, 0.189189189189) (doctors, 0.021021021021) (doctors, 0.182432432432) 0.0676 0.1194 0.9474 0.9474 38 5 5 27
11 article432.gml negative 100 96 1.9200 0.0097 0.0194 0.0002 0.0123 (measles death, 0.0808080808081) (measles, 0.00566893424036) (Baby Boomers, 0.0707070707071) 0.0217 -0.1313 0.9600 0.9600 98 16 16 45
12 article5164.gml negative 104 119 2.2885 0.0111 0.0222 0.0026 0.0288 (children, 0.155339805825) (children, 0.049519322292) (narcolepsy, 0.162274618585) 0.0982 -0.0465 1.1442 1.1442 95 4 4 92
13 article5717.gml negative 62 62 2.0000 0.0164 0.0328 0.0001 0.0184 (vaccines, 0.131147540984) (lemming society, 0.00218579234973) (herd mentality, 0.0983606557377) 0.0241 -0.0661 1.0000 1.0000 62 9 9 28
14 article5813.gml negative 50 54 2.1600 0.0220 0.0441 0.0015 0.0354 (Nichole Rolfe, 0.367346938776) (Nichole Rolfe, 0.0246598639456) (Nichole Rolfe, 0.427394034537) 0.0690 -0.1555 1.0800 1.0800 49 3 3 46
15 article621.gml negative 30 32 2.1333 0.0368 0.0736 0.0007 0.0396 (Surgeon General Vivek Murthy, 0.344827586207) (government propaganda, 0.00738916256158) (Surgeon General Vivek Murthy, 0.287356321839) 0.0563 -0.0182 1.0667 1.0667 30 4 4 22
16 article683.gml negative 234 236 2.0171 0.0043 0.0087 0.0002 0.0091 (thimerosal, 0.103004291845) (hepatitis B vaccine, 0.0102856297173) (hepatitis B vaccine, 0.0936960035672) 0.0224 -0.0660 1.0085 1.0085 231 31 31 140
17 article703.gml negative 282 280 1.9858 0.0035 0.0071 0.0000 0.0060 (vaccines, 0.0782918149466) (vaccines, 0.0030757498729) (drug companies, 0.0614946619217) 0.0115 -0.1909 0.9929 0.9929 274 40 40 86
18 article774.gml negative 57 54 1.8947 0.0169 0.0338 0.0007 0.0204 (encephalopathy, 0.125) (autism, 0.0103896103896) (government, 0.0972222222222) 0.0363 0.0014 0.9474 0.9474 54 10 10 19
19 article782.gml negative 84 77 1.8333 0.0110 0.0221 0.0001 0.0142 (measles, 0.144578313253) (measles, 0.00352630032324) (children with ASD, 0.132530120482) 0.0208 -0.2281 0.9167 0.9167 84 10 10 29
20 article99.gml negative 45 46 2.0444 0.0232 0.0465 0.0018 0.0448 (thimerosal, 0.431818181818) (thimerosal, 0.0502114164905) (thimerosal, 0.356719367589) 0.0818 -0.3927 1.0222 1.0222 43 4 4 32
21 article2047.gml neutral 52 61 2.3462 0.0230 0.0460 0.0022 0.0483 (SB277, 0.509803921569) (SB277, 0.0701960784314) (SB277, 0.340413943355) 0.1007 -0.2046 1.1731 1.1731 50 5 5 39
22 article532.gml neutral 51 37 1.4510 0.0145 0.0290 0.0002 0.0172 (acellular pertussis vaccine, 0.14) (acellular pertussis vaccine, 0.00571428571429) (acellular pertussis vaccine, 0.098) 0.0227 -0.0407 0.7255 0.7255 50 16 16 11
23 article54.gml neutral 48 37 1.5417 0.0164 0.0328 0.0002 0.0187 (pertussis vaccine, 0.148936170213) (pertussis vaccine, 0.00416281221092) (pertussis, 0.0851063829787) 0.0239 -0.1324 0.7708 0.7708 48 12 12 8
24 article63.gml neutral 17 15 1.7647 0.0551 0.1103 0.0032 0.0738 (high-dose flu vaccine, 0.6875) (high-dose flu vaccine, 0.0458333333333) (high-dose flu vaccine, 0.630208333333) 0.0993 -0.1094 0.8824 0.8824 17 2 2 15
25 article647.gml neutral 54 48 1.7778 0.0168 0.0335 0.0003 0.0190 (Dwoskin Family Foundation, 0.150943396226) (Generation Rescue, 0.00507982583454) (Dwoskin Family Foundation, 0.152830188679) 0.0255 -0.0176 0.8889 0.8889 54 11 11 12
26 article756.gml neutral 41 40 1.9512 0.0244 0.0488 0.0005 0.0303 (vaccines, 0.25) (anti-vaccine movement, 0.00608974358974) (vaccines, 0.2) 0.0439 -0.2470 0.9756 0.9756 40 6 6 18
27 article02.gml positive 36 31 1.7222 0.0246 0.0492 0.0003 0.0260 (vaccinations, 0.142857142857) (religion, 0.00252100840336) (vaccinations, 0.142857142857) 0.0333 0.0359 0.8611 0.8611 36 9 9 8
28 article1105.gml positive 38 31 1.6316 0.0220 0.0441 0.0004 0.0257 (parents who refuse to vaccinate their childre... (parents who refuse to vaccinate their childre... (parents, 0.172119487909) 0.0356 0.0889 0.8158 0.8158 37 10 10 14
29 article111.gml positive 83 75 1.8072 0.0110 0.0220 0.0003 0.0149 (herd immunity, 0.0731707317073) (measles vaccination rate, 0.00301114122252) (measles virus, 0.0548780487805) 0.0270 -0.1159 0.9036 0.9036 83 13 13 25
30 article1542.gml positive 45 51 2.2667 0.0258 0.0515 0.0035 0.0526 (HPV vaccine, 0.363636363636) (HPV vaccine, 0.0687984496124) (HPV vaccine, 0.284090909091) 0.1177 -0.3533 1.1333 1.1333 45 5 5 34
31 article1804.gml positive 42 50 2.3810 0.0290 0.0581 0.0011 0.0389 (Gardasil, 0.268292682927) (Gardasil, 0.019512195122) (girls, 0.15243902439) 0.0685 0.0897 1.1905 1.1905 41 6 6 27
32 article2.gml positive 28 23 1.6429 0.0304 0.0608 0.0006 0.0330 (decrease in exemption rates, 0.222222222222) (decrease in exemption rates, 0.00712250712251) (decrease in exemption rates, 0.185185185185) 0.0410 0.0631 0.8214 0.8214 28 7 7 9
33 article29.gml positive 74 61 1.6486 0.0113 0.0226 0.0001 0.0138 (Tdap vaccine, 0.123287671233) (Tdap vaccine, 0.00437595129376) (polio, 0.0872386445566) 0.0183 -0.2339 0.8243 0.8243 72 17 17 16
34 article30.gml positive 17 17 2.0000 0.0625 0.1250 0.0010 0.0617 (vaccines, 0.5625) (minor symptoms, 0.0166666666667) (vaccines, 0.4375) 0.0699 0.2917 1.0000 1.0000 17 2 2 15
35 article31.gml positive 48 43 1.7917 0.0191 0.0381 0.0011 0.0231 (autism risk, 0.170212765957) (autism, 0.0115633672525) (MMR vaccine, 0.0851063829787) 0.0421 0.3114 0.8958 0.8958 48 10 10 24
36 article36.gml positive 15 12 1.6000 0.0571 0.1143 0.0044 0.0809 (2014-2015 FLULAVAL QUADRIVALENT flu vaccine, ... (2014-2015 FLULAVAL QUADRIVALENT flu vaccine, ... (2014-2015 FLULAVAL QUADRIVALENT flu vaccine, ... 0.1143 -0.3581 0.8000 0.8000 14 4 4 8
37 article37.gml positive 21 28 2.6667 0.0667 0.1333 0.0015 0.0697 (HPV vaccine, 0.4) (multi-site protection, 0.0144736842105) (HPV vaccine, 0.35) 0.1000 -0.2305 1.3333 1.3333 21 2 2 19
38 article4150.gml positive 24 18 1.5000 0.0326 0.0652 0.0002 0.0343 (vaccines do not cause autism, 0.173913043478) (MMR vaccine-autism link, 0.00592885375494) (studies, 0.130434782609) 0.0380 -0.3842 0.7500 0.7500 24 6 6 7
39 article4210.gml positive 63 71 2.2540 0.0182 0.0364 0.0009 0.0267 (Jain study, 0.241935483871) (Jain study, 0.0137493389741) (Jain study, 0.244959677419) 0.0515 -0.1602 1.1270 1.1270 63 2 2 54
40 article4303.gml positive 24 19 1.5833 0.0344 0.0688 0.0002 0.0353 (anti-vaxxer, 0.217391304348) (high risk children, 0.00197628458498) (anti-vaxxer, 0.217391304348) 0.0399 -0.2799 0.7917 0.7917 24 6 6 6
41 article46.gml positive 80 83 2.0750 0.0131 0.0263 0.0014 0.0325 (meningococcal disease, 0.354430379747) (meningococcal disease, 0.0548523206751) (meningococcal disease, 0.2194092827) 0.0744 -0.3162 1.0375 1.0375 78 9 9 53
42 article5.gml positive 58 51 1.7586 0.0154 0.0309 0.0002 0.0184 (measles, 0.157894736842) (measles, 0.00438596491228) (parents, 0.143274853801) 0.0251 -0.1960 0.8793 0.8793 58 10 10 23
43 article5077.gml positive 45 49 2.1778 0.0247 0.0495 0.0018 0.0361 (measles vaccine, 0.227272727273) (immune system, 0.0174418604651) (children, 0.168414918415) 0.0717 -0.1655 1.0889 1.0889 44 5 5 34
44 article609.gml positive 134 139 2.0746 0.0078 0.0156 0.0008 0.0153 (religious groups, 0.127819548872) (religious groups, 0.0257461836409) (religious groups, 0.141003192914) 0.0426 -0.2103 1.0373 1.0373 127 22 22 60
45 article620.gml positive 76 68 1.7895 0.0119 0.0239 0.0001 0.0134 (states, 0.0933333333333) (states, 0.0027027027027) (state-level policies, 0.0568888888889) 0.0198 0.3044 0.8947 0.8947 76 16 16 33
46 article6247.gml positive 109 96 1.7615 0.0082 0.0163 0.0000 0.0089 (anti-vaccine website, 0.12962962963) (MMR vaccine-autism link, 0.00103842159917) (anti-vaccine website, 0.12962962963) 0.0115 -0.3036 0.8807 0.8807 109 16 16 24
47 article664.gml positive 29 27 1.8621 0.0333 0.0665 0.0012 0.0395 (measles vaccine, 0.285714285714) (measles infections, 0.00925925925926) (measles vaccine, 0.21875) 0.0567 -0.2007 0.9310 0.9310 26 5 5 9
48 article665.gml positive 35 30 1.7143 0.0252 0.0504 0.0009 0.0310 (rubella, 0.147058823529) (rubella virus, 0.0106951871658) (rubella, 0.147058823529) 0.0479 0.0248 0.8571 0.8571 35 7 7 12
49 article828.gml positive 56 54 1.9286 0.0175 0.0351 0.0012 0.0372 (SB 277, 0.381818181818) (SB 277, 0.0464646464646) (SB 277, 0.222727272727) 0.0679 -0.2407 0.9643 0.9643 54 7 7 38

In [6]:
# save dataframe to csv
network_data.to_csv('network_df', encoding = 'utf-8')

In [ ]:


In [ ]:


In [ ]:


In [ ]:


single network graph calculations

need to update this from: single_calc.ipynb


In [ ]:
# for individual network

graph = nx.read_gml('../output/network/negative/article03.gml')
ugraph = graph.to_undirected()
U = graph.to_undirected(reciprocal=True)
e = U.edges()
ugraph.add_edges_from(e)
print nx.info(graph)
print nx.info(ugraph)

In [ ]:
# degree histogram: returns a list of frequencies of degree values
nx.degree_histogram(graph)

In [ ]:
# degree centrality
a = nx.degree_centrality(graph)
dfIn=pd.DataFrame.from_dict(a,orient='index')
dfIn.columns = ['degree centrality']
dfIn = dfIn.sort_values(by=['degree centrality'])
dfIn

In [ ]:
# betweenness centrality
a = nx.betweenness_centrality(graph)
dfIn=pd.DataFrame.from_dict(a,orient='index')
dfIn.columns = ['betweenness centrality']
dfIn = dfIn.sort_values(by=['betweenness centrality'])
dfIn

In [ ]:
# closeness centrality
a = nx.closeness_centrality(graph)
dfIn=pd.DataFrame.from_dict(a,orient='index')
dfIn.columns = ['closeness centrality']
dfIn = dfIn.sort_values(by=['closeness centrality'])
dfIn

In [ ]:
# in degree centrality
a = nx.in_degree_centrality(graph)
dfIn=pd.DataFrame.from_dict(a,orient='index')
dfIn.columns = ['in deg centrality']
dfIn = dfIn.sort_values(by=['in deg centrality'])
dfIn

In [ ]:
# out degree centrality
b = nx.out_degree_centrality(graph)
dfIn=pd.DataFrame.from_dict(b,orient='index')
dfIn.columns = ['out deg centrality']
dfIn = dfIn.sort_values(by=['out deg centrality'])
dfIn