-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_network_of_cognate_variables.py
More file actions
64 lines (40 loc) · 1.26 KB
/
create_network_of_cognate_variables.py
File metadata and controls
64 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import cPickle as cp
import pandas as pd
import networkx as nx
from itertools import combinations
# <codecell>
# <codecell>
# GLOBALS
GSS_YEARS = [1972, 1973, 1974, 1975, 1976, 1977, 1978,
1980, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,
1990, 1991, 1993, 1994, 1996, 1998,
2000, 2002, 2004, 2006, 2008, 2010, 2012]
pathToData = '../Data/'
# LOAD DATA ###########################
VARS_IN_ARTICLE = cp.load(open(pathToData + 'VARS_IN_ARTICLE-9-20-2013.pickle', 'rb')) # load the variables used
# <codecell>
# <codecell>
G = nx.Graph()
for variables in VARS_IN_ARTICLE.itervalues():
dvs = variables['dvs']
for combo in combinations(dvs, 2):
if G.has_edge(*combo):
G[combo[0]][combo[1]]['weight'] += 1
else:
G.add_edge(*combo, weight=1)
# <codecell>
import community
dir(community)
# <codecell>
elarge=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] > 10]
G_large = nx.Graph(elarge)
nx.draw(G_large)
# pos=nx.spring_layout(G) # positions for all nodes
# # nodes
# nx.draw_networkx_nodes(G,pos,node_size=700)
# edges
# labels
# nx.draw_networkx_labels(G,pos,font_size=20,font_family='sans-serif')