Appendix B — Creating Relational Event Data for the Frozen Character Network
The relational event model data is created from two input files: frozenlines.csv and frozenchars.csv. The first file contains the dialogue events, including the speaker for each event and indicators for which characters are addressed. The second file contains information about the characters and provides the character identifiers used in the network. Both files can be downloaded from: https://github.com/schochastics/R4SNA/tree/main/data-raw.
The goal is to transform the dialogue-level data into an event-based edge list. Each row in the final data represents one directed interaction from a sender to a receiver at a specific point in the sequence.
# Read the two files directly from the GitHub repositoryfrozenlines <-read.csv("https://raw.githubusercontent.com/schochastics/R4SNA/main/data-raw/frozenlines.csv")frozenchars <-read.csv("https://raw.githubusercontent.com/schochastics/R4SNA/main/data-raw/frozenchars.csv")# Inspect the structure of the datastr(frozenlines)
# Replace receiver column names with character IDsnames(frozenlines)[4:ncol(frozenlines)] <- frozenchars$characterID# Identify receiver columnsreceiver_cols <-4:ncol(frozenlines)edges <-list()k <-1for (i in1:nrow(frozenlines)) { sender <- frozenlines$speakerID[i] event <- frozenlines$eventID[i]# Find all receivers marked with value 1 receivers <- receiver_cols[frozenlines[i, receiver_cols] ==1]if (length(receivers) >0) {for (r in receivers) { edges[[k]] <-data.frame(time = event,sender = sender,receiver =as.integer(names(frozenlines)[r]) ) k <- k +1 } }}# Combine all sender-receiver eventsedgelist <-do.call(rbind, edges)# Sort by original event orderedgelist <- edgelist[order(edgelist$time), ]# Ensure that every relational event has a unique time stampedgelist$time <-1:nrow(edgelist)# Convert to matrix format for the relational event modeledgelist <-as.matrix(edgelist)# Number of actors in the networkn_actors <-nrow(frozenchars)
The resulting object, edgelist, contains three columns: time, sender, and receiver. Let’s look at the first 10 rows:
# Show the first rows of the resulting data as a tableknitr::kable(head(edgelist, 10), caption ="First rows of the relational event data")
First rows of the relational event data
time
sender
receiver
1
1
2
2
1
2
3
2
1
4
1
2
5
2
1
6
1
2
7
1
2
8
1
2
9
1
2
10
2
1
The time variable records the order of the relational events, while sender and receiver identify the directed tie. If a single dialogue event addresses multiple receivers, the code creates one row for each sender-receiver pair. This is necessary because relational event models require events to be represented as dyadic interactions.
The final line stores the total number of actors in n_actors, which is needed when specifying the size of the network for the relational event model.