开始使用免费开始使用

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.

本练习是课程的一部分

Predictive Analytics using Networked Data in R

查看课程

练习说明

  • 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.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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[___:___, ___:___]
编辑并运行代码