Skip to content

default labeltype='prob' fails when stm object only contains content covariate, but not prevalence covariate #3

@cbjrobertson

Description

@cbjrobertson

To reproduce:

library(stm)
data(poliblog5k)
#Create date
dec312007 <- as.numeric(as.Date("2007-12-31"))
poliblog5k.meta$date <- as.Date(dec312007+poliblog5k.meta$day,
                                origin="1970-01-01")
out2 <- prepDocuments(poliblog5k.docs, poliblog5k.voc, poliblog5k.meta)
stm.out <- stm(out2$documents, out2$vocab, K=10,
               content=~ date,
               data=out2$meta,
               max.em.its=1)

stmBrowser(stm.out, data=out2$meta, c("date"),
           text="text")
>>> Error in 1:nrow(topics) : argument of length 0

This is because the topics object doesn't contain an attribute called probs when the model is called with only a content covariate, so topics <- labelTopics(stm.out, n=3)[[labeltype]] in line 103 of the function produces a NULL object and line 105 then errors out.

The error can be avoided by including labeltype = 'topic' in the function call to stmBrowser, so perhaps it's an issue for the docs... or a tryCatch() could be added. Sorry, I wouldn't have written a PR but I don't know R that well. Thanks for the cool function!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions