get_cooccurrence_matrix: Get Topic Cooccurrence Matrix

Description Usage Arguments Value Author(s) Examples

View source: R/cooccurrence_matrix.R

Description

Given a document-topic matrix, the function returns a topic cooccurrence matrix (also called an adjacency matrix).

Usage

1

Arguments

x

A dataframe representing a document-topic matrix. Each row i and column j in the matrix should represent a document and topic, respectively. Each element x[i,j] can be either 1 if document i contains topic j, or 0 otherwise.

Value

A dataframe representing the topic cooccurrence matrix

Author(s)

Chinmay Kakatkar

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(coocmat)
#simulate some data (rows are documents, cols are topics)
df <- data.frame(t(matrix(c(c(1,0,0,1,0,1),
                            c(0,1,1,1,0,1),
                            c(1,0,0,0,0,0),
                            c(0,0,1,1,0,1),
                            c(1,1,1,0,0,0)),
                          ncol = 5, nrow = 6)))

#derive topic cooccurrence matrix
cooccurrence_matrix <- get_cooccurrence_matrix(df)

#get list of topics
names(cooccurrence_matrix)

#print how many times topic "2" cooccurred with topic "3"
print(cooccurrence_matrix["2","3"])

ckstash/coocmat documentation built on Nov. 12, 2020, 7:44 p.m.