View source: R/utils-textnets.R
| doc_centrality | R Documentation |
Given a document-term matrix or a document-similarity matrix, this function returns specified text network-based centrality measures. Currently, this includes degree, eigenvector, betweenness, and spanning.
doc_centrality(mat, method, alpha = 1L, two_mode = TRUE)
mat |
Document-term matrix with terms as columns or a document-similarity matrix with documents as rows and columns. |
method |
Character vector indicating centrality method, including "degree", "eigen", "span", and "between". |
alpha |
Number (default = 1) indicating the tuning parameter for weighted metrics. |
two_mode |
Logical (default = TRUE), indicating whether the input matrix is two mode (i.e. a document-term matrix) or one-mode (i.e. document-similarity matrix) |
If a document-term matrix is provided, the function obtains the one-mode
document-level projection to get the document-similarity matrix using
tcrossprod(). If a one-mode document-similarity matrix is provided, then
this step is skipped. This way document similarities may be obtained
using other methods, such as Word-Mover's Distance (see doc_similarity).
The diagonal is ignored in all calculations.
Document centrality methods include:
degree: Opsahl's weighted degree centrality with tuning parameter "alpha"
between: vertex betweenness centrality using Brandes' method
eigen: eigenvector centrality using Freeman's method. When the top two eigenvalues are tied or nearly tied (e.g. a corpus with duplicate or highly symmetric documents), the leading eigenvector is only defined up to an arbitrary rotation within that tied subspace, and results can be unstable under tiny perturbations to the similarity matrix; prefer "degree" or "between" for such corpora.
span: Modified Burt's constraint following Stoltz and Taylor's method, uses a tuning parameter "alpha" and the output is scaled.
A dataframe with two columns
Dustin Stoltz
Brandes, Ulrik
(2000) 'A faster algorithm for betweenness centrality'
Journal of Mathematical Sociology. 25(2):163-177
\Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/0022250X.2001.9990249")}.
Opsahl, Tore, et al.
(2010) 'Node centrality in weighted networks: Generalizing degree
and shortest paths.' Social Networks. 32(3)245:251
\Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.socnet.2010.03.006")}
Stoltz, Dustin; Taylor, Marshall
(2019) 'Textual Spanning: Finding Discursive Holes in Text Networks'
Socius. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1177/2378023119827674")}
# load example text
data(jfk_speech)
# minimal preprocessing
jfk_speech$sentence <- tolower(jfk_speech$sentence)
jfk_speech$sentence <- gsub("[[:punct:]]+", " ", jfk_speech$sentence)
# create DTM
dtm <- dtm_builder(jfk_speech, sentence, sentence_id)
ddeg <- doc_centrality(dtm, method = "degree")
if (requireNamespace("RSpectra", quietly = TRUE)) {
deig <- doc_centrality(dtm, method = "eigen")
}
dbet <- doc_centrality(dtm, method = "between")
dspa <- doc_centrality(dtm, method = "span")
# with a document-similarity matrix (dsm)
dsm <- doc_similarity(dtm, method = "cosine")
ddeg <- doc_centrality(dsm, method = "degree", two_mode = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.