jsviz: Create a list of required objects from fitted topic model to...

Description Usage Arguments Examples

Description

Create a list of required objects from fitted topic model to visualize using d3

Usage

1
2
3
jsviz(text = character(), doc.id = integer(), word.id = integer(),
  topic.id = integer(), vocab = character(), K = integer(),
  k.clusters = 1, lambda = 0.5, n.terms = 30, n.docs = 10)

Arguments

text

A character vector of all training documents used to fit the LDA model

doc.id

An integer vector of the document ID numbers for each token occurrence in the data

word.id

An integer vector of the token ID numbers for each token occurrence in the data

topic.id

An integer vector of the topic ID numbers for each token occurrence in the data (from the fitted topic model)

vocab

A character vector of the tokens in the vocabulary

K

The number of topics in the fitted topic model

k.clusters

The number of clusters into which to group the topics

lambda

A number in [0,1] to govern the weighted average that defines a given token's relevance for a given topic. Default to 0.5.

n.terms

The number of terms to display on the right panel of the interactive visualization for each topic

n.docs

The number of example documents to display for each topic

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data(APinput, package="ldatools")
names(APinput)  # [1] "word.id"  "doc.id"   "vocab"    "category"
data(APtopics, package="ldatools")
names(APtopics)  # [1] "topics" "loglik"
data(APcorpus)
length(APcorpus)  # [1] 2250

# select only the documents that were used in training the model (i.e. remove a few very short, or empty docs)
text <- APcorpus[APinput$category == 0]

# Run the function and write the JSON file:
z <- jsviz(text=text, doc.id=APinput$doc.id, word.id=APinput$word.id, topic.id=APtopics$topics, vocab=APinput$vocab,
          K=30, k.clusters=1, lambda=0.5, n.terms=30, n.docs=10)

# Write the list to a JSON object and place in a directory from which to serve the d3 webpage:
library(RJSONIO)
z.out <- toJSON(z)
cat(z.out, file="path/lda.json")
# Now serve index.html from path/

kshirley/LDAtools documentation built on May 20, 2019, 7:03 p.m.