Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Aron Lindberg committed Apr 1, 2013
1 parent 6dfe826 commit 628afcd
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 1 deletion.
Empty file added .Rapp.history
Empty file.
Binary file added 1.1_Krackhardt_full.pdf
Binary file not shown.
Binary file added 1.2_krack_reports_to.pdf
Binary file not shown.
Binary file added 1.3_Krackhardt_Friendship.pdf
Binary file not shown.
Binary file added 1.5krackhard_reports_F_R.pdf
Binary file not shown.
Binary file added 1.6_Krack_reports_color.pdf
Binary file not shown.
Binary file added 1.7_Krack_reports_color.pdf
Binary file not shown.
Binary file added 1.8_Krack_overlayed_ties.pdf
Binary file not shown.
Binary file added 1.9_krack_overlayed_str.pdf
Binary file not shown.
232 changes: 232 additions & 0 deletions krack_full.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
0 1
0 3
0 7
0 11
0 15
0 17
0 20
1 0
1 5
1 6
1 17
1 20
2 0
2 1
2 3
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 13
2 16
2 17
2 18
2 19
2 20
3 0
3 1
3 5
3 7
3 9
3 10
3 11
3 15
3 16
3 17
3 19
3 20
4 0
4 1
4 5
4 6
4 7
4 8
4 9
4 10
4 12
4 13
4 15
4 16
4 17
4 18
4 19
4 20
5 1
5 6
5 8
5 11
5 16
5 20
6 1
6 5
6 10
6 11
6 13
6 16
6 17
6 20
7 1
7 3
7 5
7 6
7 9
7 10
7 17
7 20
8 0
8 1
8 5
8 6
8 7
8 9
8 10
8 11
8 13
8 15
8 16
8 17
8 20
9 0
9 1
9 2
9 3
9 4
9 7
9 8
9 10
9 11
9 12
9 14
9 15
9 16
9 17
9 18
9 19
10 0
10 1
10 2
10 3
10 4
10 6
10 7
10 8
10 11
10 12
10 14
10 16
10 17
10 18
11 0
11 3
11 6
11 16
11 20
12 0
12 1
12 4
12 8
12 10
12 13
12 17
13 1
13 6
13 14
13 17
13 20
14 0
14 1
14 2
14 3
14 4
14 5
14 6
14 7
14 8
14 9
14 10
14 11
14 12
14 13
14 15
14 16
14 17
14 18
14 19
14 20
15 0
15 1
15 9
15 17
16 0
16 1
16 2
16 3
16 4
16 5
16 6
16 7
16 8
16 9
16 10
16 11
16 13
16 14
16 15
16 18
16 19
16 20
17 0
17 1
17 2
17 3
17 4
17 6
17 7
17 8
17 9
17 10
17 12
17 13
17 14
17 15
17 18
17 19
17 20
18 0
18 1
18 2
18 4
18 6
18 9
18 10
18 11
18 13
18 14
18 17
18 19
19 0
19 1
19 5
19 7
19 10
19 11
19 13
19 14
19 15
19 16
19 17
19 20
20 1
20 2
20 3
20 5
20 6
20 7
20 11
20 13
20 16
20 17
20 19
2 changes: 1 addition & 1 deletion lab1.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setwd("~/github/local/Social-Network-Analysis-in-R/")
source("http://sna.stanford.edu/setup.R")
# source("http://sna.stanford.edu/setup.R")

sink("outfile.txt")
readLines("http://sna.stanford.edu/setup.R")
Expand Down
84 changes: 84 additions & 0 deletions lab2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
library(igraph)
library(NetData)

data(kracknets, package = "NetData")

krack_full_nonzero_edges <- subset(krack_full_data_frame, (advice_tie > 0 | friendship_tie > 0 | reports_to_tie > 0))
head(krack_full_nonzero_edges)

krack_full <- graph.data.frame(krack_full_nonzero_edges)
summary(krack_full)

# Set vertex attributes
for (i in V(krack_full)) {
for (j in names(attributes)) {
krack_full <- set.vertex.attribute(krack_full, j, index=i, attributes[i+1,j])
}
}
summary(krack_full)

# Create sub-graphs based on edge attributes
krack_advice <- delete.edges(krack_full,
E(krack_full)[get.edge.attribute(krack_full, name = "advice_tie")==0])
summary(krack_advice)

krack_friendship <- delete.edges(krack_full,
E(krack_full)[get.edge.attribute(krack_full, name = "friendship_tie")==0])
summary(krack_friendship)

krack_reports_to <- delete.edges(krack_full,
E(krack_full)[get.edge.attribute(krack_full, name = "reports_to_tie")==0])
summary(krack_reports_to)

###
# 3. NODE-LEVEL STATISTICS
###

# Compute the indegree and outdegree for each node, first in the
# full graph (accounting for all tie types) and then in each
# tie-specific sub-graph.

deg_full_in <- degree(krack_full, mode="in")
deg_full_out <- degree(krack_full, mode="out")
deg_full_in
deg_full_out

deg_advice_in <- degree(krack_advice, mode="in")
deg_advice_out <- degree(krack_advice, mode="out")
deg_advice_in
deg_advice_out

deg_friendship_in <- degree(krack_friendship, mode="in")
deg_friendship_out <- degree(krack_friendship, mode="out")
deg_friendship_in
deg_friendship_out

deg_reports_to_in <- degree(krack_reports_to, mode="in")
deg_reports_to_out <- degree(krack_reports_to, mode="out")
deg_reports_to_in
deg_reports_to_out

# Reachability can only be computed on one vertex at a time. To
# get graph-wide statistics, change the value of "vertex"
# manually or write a for loop. (Remember that, unlike R objects,
# igraph objects are numbered from 0.)

reachability <- function(g, m) {
reach_mat = matrix(nrow = vcount(g),
ncol = vcount(g))
for (i in 1:vcount(g)) {
reach_mat[i,] = 0
this_node_reach <- subcomponent(g, (i - 1), mode = m)

for (j in 1:(length(this_node_reach))) {
alter = this_node_reach[j] + 1
reach_mat[i, alter] = 1
}
}
return(reach_mat)
}

reach_full_in <- reachability(krack_full, 'in')
reach_full_out <- reachability(krack_full, 'out')
reach_full_in
reach_full_out
17 changes: 17 additions & 0 deletions outfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[1] "install.packages(\"ergm\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[2] "install.packages(\"reshape\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[3] "install.packages(\"igraph\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[4] "install.packages(\"sna\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[5] "install.packages(\"numDeriv\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[6] "install.packages(\"MatchIt\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[7] "install.packages(\"coin\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[8] "install.packages(\"boot\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[9] "install.packages(\"Hmisc\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[10] "install.packages(\"lattice\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[11] "install.packages(\"triads\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[12] "install.packages(\"psych\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[13] "install.packages(\"nFactors\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[14] "install.packages(\"animation\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[15] "install.packages(\"NetData\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[16] "install.packages(\"NetCluster\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"
[17] "install.packages(\"igraphtosonia\", repos = \"http://cran.cnr.berkeley.edu/\", dependencies = TRUE)"

0 comments on commit 628afcd

Please sign in to comment.