Setting Edge Attributes

In this exercise, we will learn how to add attributes to the edges of a network using the statnet package in R. Edge attributes can provide additional information about the relationships in a network, such as their strength, type, or weight.

Adding Edge Attributes

Suppose we have the network adjacency_network and we want to assign a random value to each edge in the network. We can add this information as an edge attribute using the set.edge.attribute() function:

network::set.edge.attribute(adjacency_network, "rndval", runif(network.edgecount(adjacency_network), 0, 1))

The network:: prefix is used to specify that the function is from the network package.

Inspecting Attribute Values

We can inspect the values of an edge attribute using the %e% operator:

adjacency_network %e% "rndval"
[1] 0.6122244 0.3373301 0.2120034 0.8008051 0.5045893 0.4359113

This will return a vector of the random values assigned to each edge.

Summary of Attribute Values

We can get a summary of the edge attribute values using the summary() function:

summary(adjacency_network %e% "rndval")
Min.     1st Qu.   Median   Mean     3rd Qu.   Max. 
0.2120   0.3620    0.4703   0.4838   0.5853    0.8008  

This will return statistical measures such as the minimum, maximum, and mean of the attribute values.

Exercise

Create a vector as edge attribute times_texted. This vector contains frequency of which the friends interacted with each other.

  1. Adam sent two texts to Carol.
  2. Bob sent one text to Adam, three to Carol and two to Diesel
  3. Carol sent one text to Bob.
  4. Erika sent one text to Adam and three to Diesel.
Add this vector to the network friends_network from the previous exercise. You can look at the edgelist to see which order the edges are in with the as.edgelist(friends_network) function.

Assume that: