Let’s start by installing the packages that we’re going to use to analyze our data, knowing that we want to conduct social network analysis and that we want to create sophisticated sociograms. We’ll need the following packages:
{tidyverse} which offers multiple R packages
{tidygraph} for working with relational data
{ggraph} to support network visualizations
{igraph} to optimize network visualizations
{janitor} to tidy up variable names
library(tidyverse)
library(tidygraph)
library(ggraph)
library(igraph)
library(janitor)
I will use the same data from our case study, but to keep it interesting for myself, I’ll use the dlt2 datasets instead of the dlt1 datasets.
The dlt2-edges document represents the various
interactions between the network actors (e.g. forum posts and
replies.)
The dlt2-nodes document represents various
attributes about the actors (e.g. role, location, group, gender,
etc.)
One of the questions I had during the case study was whether we could “visualize change over time among the actors in these networks.” For this independent study, I will use the following question to guide my investigation:
I will need to tidy the data as we did in the case study, since the data are structured similarly. As I read in both csv files, I will make sure that the various column types are character strings. Note that in the dlt2 files, there is no space in the column names for ‘CommentID’ and ‘DiscussionID’. Also, I wanted to include additional items from the dlt2_actors document (gender, region, grades) and was less interested in several variables from the case study (Facilitator, expert, connect) so I removed those.
Looking at this network, there are 492 actors and 2584 ties. Since I want to compare the beginning and end of the semester, I’m also going to go ahead and create two additional dataframes: one with only edges from September, and one with only edges from December. The dlt2_ties_Sept has 142 edges, and the dlt2_ties_Dec has 114 edges.
?delete.vertices
dlt2_ties <- read_csv("data/dlt2-edges.csv",
col_types = cols(Sender = col_character(),
Receiver = col_character(),
Timestamp = col_datetime(format = "%m/%d/%y"),
`Category Text` = col_skip(),
`CommentID` = col_character(),
`DiscussionID` = col_character())) |>
clean_names()
dlt2_ties_Sept <- dlt2_ties |>
filter(between(timestamp, as.Date("2013-09-01"), as.Date("2013-09-30")))
dlt2_ties_Dec <- dlt2_ties |>
filter(between(timestamp, as.Date("2013-12-01"), as.Date("2013-12-31")))
dlt2_ties_Sept
## # A tibble: 142 × 9
## sender reciever timestamp title categ…¹ parent descr…² comme…³
## <chr> <dbl> <dttm> <chr> <chr> <chr> <chr> <chr>
## 1 37 461 2013-09-27 00:00:00 Greetings… Introd… Group… Please… 3
## 2 434 434 2013-09-27 00:00:00 Sherry Ha… Introd… Group… Please… 4
## 3 302 434 2013-09-27 00:00:00 Sherry Ha… Introd… Group… Please… 5
## 4 60 434 2013-09-27 00:00:00 Sherry Ha… Introd… Group… Please… 7
## 5 128 434 2013-09-29 00:00:00 Sherry Ha… Introd… Group… Please… 38
## 6 158 434 2013-09-30 00:00:00 Sherry Ha… Introd… Group… Please… 75
## 7 43 245 2013-09-27 00:00:00 Planning … Change… Group… What w… 6
## 8 426 245 2013-09-30 00:00:00 Planning … Change… Group… What w… 146
## 9 176 43 2013-09-27 00:00:00 Teacher a… Most i… Group… Please… 8
## 10 362 43 2013-09-30 00:00:00 Teacher a… Most i… Group… Please… 107
## # … with 132 more rows, 1 more variable: discussion_id <chr>, and abbreviated
## # variable names ¹category, ²description, ³comment_id
dlt2_ties_Dec
## # A tibble: 114 × 9
## sender reciever timestamp title categ…¹ parent descr…² comme…³
## <chr> <dbl> <dttm> <chr> <chr> <chr> <chr> <chr>
## 1 28 255 2013-12-22 00:00:00 Rural Sch… Classr… Goals… <NA> 2534
## 2 460 336 2013-12-06 00:00:00 Creativit… Change… Group… What w… 2468
## 3 436 367 2013-12-04 00:00:00 Vision 20… Other … Goals… <NA> 2453
## 4 110 486 2013-12-28 00:00:00 District … Distri… Goals… <NA> 2543
## 5 342 361 2013-12-10 00:00:00 Implement… Other … Goals… <NA> 2485
## 6 28 33 2013-12-22 00:00:00 Introduci… Classr… Goals… <NA> 2535
## 7 335 302 2013-12-11 00:00:00 Knowing W… Unit 4… Archi… Please… 2492
## 8 342 396 2013-12-10 00:00:00 Rukhsana … Other … Goals… <NA> 2487
## 9 41 135 2013-12-03 00:00:00 K-2 schoo… School Goals… <NA> 2451
## 10 342 341 2013-12-10 00:00:00 THE EDUCA… Other … Goals… <NA> 2486
## # … with 104 more rows, 1 more variable: discussion_id <chr>, and abbreviated
## # variable names ¹category, ²description, ³comment_id
dlt2_ties
## # A tibble: 2,584 × 9
## sender reciever timestamp title categ…¹ parent descr…² comme…³
## <chr> <dbl> <dttm> <chr> <chr> <chr> <chr> <chr>
## 1 37 461 2013-09-27 00:00:00 Greetings… Introd… Group… Please… 3
## 2 434 434 2013-09-27 00:00:00 Sherry Ha… Introd… Group… Please… 4
## 3 302 434 2013-09-27 00:00:00 Sherry Ha… Introd… Group… Please… 5
## 4 60 434 2013-09-27 00:00:00 Sherry Ha… Introd… Group… Please… 7
## 5 128 434 2013-09-29 00:00:00 Sherry Ha… Introd… Group… Please… 38
## 6 158 434 2013-09-30 00:00:00 Sherry Ha… Introd… Group… Please… 75
## 7 442 434 2013-10-01 00:00:00 Sherry Ha… Introd… Group… Please… 193
## 8 43 245 2013-09-27 00:00:00 Planning … Change… Group… What w… 6
## 9 426 245 2013-09-30 00:00:00 Planning … Change… Group… What w… 146
## 10 142 245 2013-10-01 00:00:00 Planning … Change… Group… What w… 201
## # … with 2,574 more rows, 1 more variable: discussion_id <chr>, and abbreviated
## # variable names ¹category, ²description, ³comment_id
dlt2_actors <- read_csv("data/dlt2-nodes.csv",
col_types = cols(UID = col_character(),
gender = col_character(),
region = col_character(),
grades = col_character())) |>
clean_names()
dlt2_actors
## # A tibble: 492 × 13
## uid facilitator role exper…¹ exper…² grades locat…³ region country group
## <dbl> <dbl> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr>
## 1 1 0 curric… 2 17 gener… IN Midwe… US AL
## 2 2 0 other 1 3 prima… NC South US MN
## 3 3 0 instru… 2 20 gener… US South US OZ
## 4 4 0 instru… 2 12 middle TX South US OZ
## 5 5 0 other 1 0 gener… CAN Inter… CA AL
## 6 6 0 instru… 1 7 gener… CAN Inter… CA AL
## 7 7 0 operat… 1 6 gener… RI North… US OZ
## 8 8 0 curric… 2 12 middle ME North… US MN
## 9 9 0 other 2 11 gener… VA South US OZ
## 10 10 0 instru… 3 21 gener… WV South US OZ
## # … with 482 more rows, 3 more variables: gender <chr>, expert <dbl>,
## # connect <dbl>, and abbreviated variable names ¹experience2, ²experience,
## # ³location
Similarly to the case study, we’ll need to create a network object
that interprets our dlt2_ties dataframe as our edges and
our dlt2_actors dataframe as our nodes. I will also go
ahead and create network objects for the dlt2_ties_Sept and
dlt2_ties_Dec dataframes.
dlt2_network <- tbl_graph(edges = dlt2_ties,
nodes = dlt2_actors,
node_key = "uid",
directed = TRUE)
dlt2_network_Sept <- tbl_graph(edges = dlt2_ties_Sept,
nodes = dlt2_actors,
node_key = "uid",
directed = TRUE)
dlt2_network_Dec <- tbl_graph(edges = dlt2_ties_Dec,
nodes = dlt2_actors,
node_key = "uid",
directed = TRUE)
dlt2_network
## # A tbl_graph: 492 nodes and 2584 edges
## #
## # A directed multigraph with 69 components
## #
## # Node Data: 492 × 13 (active)
## uid facili… role experi… experi… grades locati… region country group gender
## <dbl> <dbl> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 1 0 curr… 2 17 gener… IN Midwe… US AL male
## 2 2 0 other 1 3 prima… NC South US MN female
## 3 3 0 inst… 2 20 gener… US South US OZ female
## 4 4 0 inst… 2 12 middle TX South US OZ female
## 5 5 0 other 1 0 gener… CAN Inter… CA AL female
## 6 6 0 inst… 1 7 gener… CAN Inter… CA AL female
## # … with 486 more rows, and 2 more variables: expert <dbl>, connect <dbl>
## #
## # Edge Data: 2,584 × 9
## from to timestamp title catego… parent descrip… commen… discus…
## <int> <int> <dttm> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 37 461 2013-09-27 00:00:00 Greet… Introd… Group… Please … 3 1
## 2 434 434 2013-09-27 00:00:00 Sherr… Introd… Group… Please … 4 2
## 3 302 434 2013-09-27 00:00:00 Sherr… Introd… Group… Please … 5 3
## # … with 2,581 more rows
dlt2_network_Sept
## # A tbl_graph: 492 nodes and 142 edges
## #
## # A directed multigraph with 414 components
## #
## # Node Data: 492 × 13 (active)
## uid facili… role experi… experi… grades locati… region country group gender
## <dbl> <dbl> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 1 0 curr… 2 17 gener… IN Midwe… US AL male
## 2 2 0 other 1 3 prima… NC South US MN female
## 3 3 0 inst… 2 20 gener… US South US OZ female
## 4 4 0 inst… 2 12 middle TX South US OZ female
## 5 5 0 other 1 0 gener… CAN Inter… CA AL female
## 6 6 0 inst… 1 7 gener… CAN Inter… CA AL female
## # … with 486 more rows, and 2 more variables: expert <dbl>, connect <dbl>
## #
## # Edge Data: 142 × 9
## from to timestamp title catego… parent descrip… commen… discus…
## <int> <int> <dttm> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 37 461 2013-09-27 00:00:00 Greet… Introd… Group… Please … 3 1
## 2 434 434 2013-09-27 00:00:00 Sherr… Introd… Group… Please … 4 2
## 3 302 434 2013-09-27 00:00:00 Sherr… Introd… Group… Please … 5 3
## # … with 139 more rows
dlt2_network_Dec
## # A tbl_graph: 492 nodes and 114 edges
## #
## # A directed multigraph with 430 components
## #
## # Node Data: 492 × 13 (active)
## uid facili… role experi… experi… grades locati… region country group gender
## <dbl> <dbl> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 1 0 curr… 2 17 gener… IN Midwe… US AL male
## 2 2 0 other 1 3 prima… NC South US MN female
## 3 3 0 inst… 2 20 gener… US South US OZ female
## 4 4 0 inst… 2 12 middle TX South US OZ female
## 5 5 0 other 1 0 gener… CAN Inter… CA AL female
## 6 6 0 inst… 1 7 gener… CAN Inter… CA AL female
## # … with 486 more rows, and 2 more variables: expert <dbl>, connect <dbl>
## #
## # Edge Data: 114 × 9
## from to timestamp title category parent descri… commen… discus…
## <int> <int> <dttm> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 28 255 2013-12-22 00:00:00 Rural… Classro… Goals… <NA> 2534 385
## 2 460 336 2013-12-06 00:00:00 Creat… Changes… Group… What w… 2468 407
## 3 436 367 2013-12-04 00:00:00 Visio… Other O… Goals… <NA> 2453 419
## # … with 111 more rows
I’m going to use a similar method to the one I employed in the case study, but alter it slightly to reflect the new variables (gender, region, grades). I’ll also attempt to clean it up a bit more from the case study before I apply it to the Sept/Dec networks during section 4. In the last independent study, I noticed that someone had used shape to demonstrate gender as a variable, so I want to try that as well.
As I began to graph the Sept/Dec networks, I noticed quite a few isolated nodes that had no edges (which makes sense - with a smaller timeframe, there’s a higher chance that an actor has not sent or received a message.) I used the ‘delete.vertices’ function to remove these isolated nodes to make the sociograms easier to read, especially as I begin to consider iterating on the models for Section 4.
dlt2_network_Sept_edited <- delete.vertices(dlt2_network_Sept,
which(degree(dlt2_network_Sept)==0))
dlt2_network_Dec_edited <- delete.vertices(dlt2_network_Dec,
which(degree(dlt2_network_Dec)==0))
ggraph(dlt2_network, layout = "fr") +
geom_edge_link(alpha = .2) +
geom_node_point(aes(color = grades,
shape = gender)) +
theme_graph()
ggraph(dlt2_network_Dec_edited, layout = "fr") +
geom_edge_link(alpha = .2) +
geom_node_point(aes(color = grades,
shape = gender)) +
theme_graph()
ggraph(dlt2_network_Dec_edited, layout = "fr") +
geom_edge_link(alpha = .2) +
geom_node_point(aes(color = grades,
shape = gender)) +
theme_graph()
I enjoyed learning about the different measures used to describe networks, and I would like to attempt to use several of them to analyze the edited (i.e. isolated nodes removed) December/September networks.
Pretty small subset of the overall dataset, which will have benefits (clearer visualizations) and drawbacks (oversimplification of class trends.)
gorder(dlt2_network_Sept_edited)
## [1] 82
gsize(dlt2_network_Sept_edited)
## [1] 142
gorder(dlt2_network_Dec_edited)
## [1] 63
gsize(dlt2_network_Dec_edited)
## [1] 114
Interesting difference in centrality between the September and December networks - it looks like the centralization value decreased across time. Perhaps this means that the network spread out towards the end of the semester.
centr_degree(dlt2_network_Sept_edited, mode = "all")
## $res
## [1] 2 1 7 1 2 1 4 4 1 1 2 2 1 3 1 3 2 6 2 6 2 3 4 2 8
## [26] 29 2 1 6 1 6 1 4 4 3 2 1 5 1 3 2 2 2 2 3 1 8 40 6 1
## [51] 3 1 1 6 4 3 3 3 1 8 7 3 2 1 1 2 1 1 1 1 6 1 1 2 1
## [76] 3 2 1 1 1 4 1
##
## $centralization
## [1] 0.2283189
##
## $theoretical_max
## [1] 13122
centr_degree(dlt2_network_Sept_edited, mode = "out")
## $res
## [1] 1 0 5 1 0 0 1 1 1 1 0 2 1 0 1 1 1 4 1 5 1 1 3 0 3
## [26] 18 1 1 2 0 1 1 3 0 1 2 0 1 0 2 2 2 2 2 3 1 0 21 6 0
## [51] 0 1 0 0 2 0 2 3 0 7 6 0 0 0 1 1 0 1 1 0 1 0 1 1 0
## [76] 1 2 0 0 1 3 0
##
## $centralization
## [1] 0.2378802
##
## $theoretical_max
## [1] 6642
centr_degree(dlt2_network_Sept_edited, mode = "in")
## $res
## [1] 1 1 2 0 2 1 3 3 0 0 2 0 0 3 0 2 1 2 1 1 1 2 1 2 5
## [26] 11 1 0 4 1 5 0 1 4 2 0 1 4 1 1 0 0 0 0 0 0 8 19 0 1
## [51] 3 0 1 6 2 3 1 0 1 1 1 3 2 1 0 1 1 0 0 1 5 1 0 1 1
## [76] 2 0 1 1 0 1 1
##
## $centralization
## [1] 0.2131888
##
## $theoretical_max
## [1] 6642
centr_degree(dlt2_network_Dec_edited, mode = "all")
## $res
## [1] 1 1 1 4 3 11 4 1 3 10 2 1 2 8 2 2 11 1 1 4 2 2 2 5 1
## [26] 4 1 9 1 2 4 3 1 6 2 1 12 2 3 2 16 1 1 12 2 1 6 1 6 2
## [51] 2 2 5 11 2 1 3 4 4 3 3 1 1
##
## $centralization
## [1] 0.1014568
##
## $theoretical_max
## [1] 7688
centr_degree(dlt2_network_Dec_edited, mode = "out")
## $res
## [1] 0 0 0 0 0 9 2 0 0 5 0 0 2 8 0 0 5 0 0 3 0 0 0 0 0
## [26] 3 0 9 0 0 4 0 0 5 0 0 2 2 1 0 14 0 0 12 0 0 3 0 4 0
## [51] 0 0 3 11 0 0 2 0 3 2 0 0 0
##
## $centralization
## [1] 0.1966206
##
## $theoretical_max
## [1] 3906
centr_degree(dlt2_network_Dec_edited, mode = "in")
## $res
## [1] 1 1 1 4 3 2 2 1 3 5 2 1 0 0 2 2 6 1 1 1 2 2 2 5 1
## [26] 1 1 0 1 2 0 3 1 1 2 1 10 0 2 2 2 1 1 0 2 1 3 1 2 2
## [51] 2 2 2 0 2 1 1 4 1 1 3 1 1
##
## $centralization
## [1] 0.1321045
##
## $theoretical_max
## [1] 3906
The density is pretty low, which makes sense since this is a small subset of a much larger dataset and therefore does not have as much data to display.
edge_density(dlt2_network_Sept_edited)
## [1] 0.0213791
graph.density(dlt2_network_Sept_edited)
## [1] 0.0213791
edge_density(dlt2_network_Dec_edited)
## [1] 0.02918587
graph.density(dlt2_network_Dec_edited)
## [1] 0.02918587
Reciprocity is somewhat low, which is perhaps not surprising given the small subset of data. However, it is interesting to note that the reciprocity dropped from 13% to 8% among active nodes between September and December.
reciprocity(dlt2_network_Sept_edited)
## [1] 0.1323529
reciprocity(dlt2_network_Dec_edited)
## [1] 0.0877193
Let’s see if we can make a more sophisticated version of our earlier sociograms so that we can visualize some of the trends in our smaller Sept/Dec networks. I have removed the isolated nodes to focus in on the active nodes during these months.
ggraph(dlt2_network_Sept_edited, layout = "fr") +
geom_edge_link(alpha = .2) +
geom_node_point(aes(color = grades,
shape = gender,
stroke = 3)) +
scale_color_brewer(palette = "PiYG") +
geom_node_text(aes(label = uid),
repel=TRUE) +
theme_graph(background = "white",
foreground = NULL) +
labs(title="September Network")
ggraph(dlt2_network_Dec_edited, layout = "fr") +
geom_edge_link(alpha = .2) +
geom_node_point(aes(color = grades,
shape = gender,
stroke = 3)) +
scale_color_brewer(palette = "PiYG") +
geom_node_text(aes(label = uid),
repel=TRUE) +
theme_graph(background = "white",
foreground = NULL) +
labs(title="December Network")