I have the following binary matrix that show in which article each keyword shows up.
keyword1 keyword2 keyword3
art1 0 1 0
art2 1 1 0
art3 0 0 1
I tried the technique below to create an adjacency matrix but I am not sure if it is right and what the values mean
df1 <- data.frame(keyword1=c(0,1,0),keyword2=c(1,1,0),keyword3=c(0,0,1),row.names=c("art1","art2","art3"))
df1.mt <- as.matrix(df1)
df1.adj <- t(df1.mt) %*% df1.mt
at this point I have created the following adjacency matrix
keyword1 keyword2 keyword3
keyword1 1 1 0
keyword2 1 2 0
keyword3 0 0 1
Is this an adjacency matrix? does it show the relationship between the keywords by the articles? Can I use this to draw a network diagram, and please how?
Thank you for the help.
If you're not familiar with the igraph
package it is one networking package that works for this type of task rather easily:
library(igraph)
g <- graph.adjacency(df1.adj)
plot(g)
The first matrix is a Boolean matrix. The conversion you do is an adjacency matrix and the diagonal is the number of times the keywords displayed total. The off diagonals are the link (edges) between two keywords (nodes). These edges could be weighted as well.
This gives:
You could also set the diagonal to zero to avoid the edges that are loops:
diag(df1.adj) <- 0
g <- graph.adjacency(df1.adj)
plot(g)
yielding: