LoslegenKostenlos loslegen

Adjacency matrices

In this exercise, you will extract and compute the first and second order adjacency matrices of the network.
You've already seen how to extract the first order adjacency matrix using the as_adjaceny_matrix() function in the slides. For the second-order adjacency matrix, you need to multiply the first order matrix with itself and replace all the positive values with 1 since we are working with unweighted networks only. You also need to make sure the elements on the diagonal are 0 since we do not allow self-edges.

Diese Übung ist Teil des Kurses

Predictive Analytics using Networked Data in R

Kurs anzeigen

Anleitung zur Übung

  • Extract the network's adjacency matrix using the as_adjacency_matrix() function. Name the matrix AdjacencyMatrix.
  • Compute the second order adjacency matrix by multiplying AdjacencyMatrix with itself and call it SecondOrderMatrix_adj.
  • Create a new matrix, SecondOrderMatrix, by conditioning on SecondOrderMatrix_adj to make all positive values equal to 1. The elements on the diagonal should be 0.
  • Inspect the first 10 rows and first 10 columns of SecondOrderMatrix.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Extract the adjacency matrix
AdjacencyMatrix <- as_adjacency_matrix(___)

# Compute the second order matrix
SecondOrderMatrix_adj <- ___ %*% ___

# Adjust the second order matrix
SecondOrderMatrix <- ((___) > 0) + 0
diag(SecondOrderMatrix) <- 0

# Inspect the second order matrix
SecondOrderMatrix[___:___, ___:___]
Code bearbeiten und ausführen