Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to output the themes with time trends #2

Open
reve0913 opened this issue Jul 24, 2023 · 2 comments
Open

How to output the themes with time trends #2

reve0913 opened this issue Jul 24, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@reve0913
Copy link

May I ask how to write code that can output the results of theme trends over time? I always get overall topic matrices, but not topics with time series.

Many thanks,

@JonasRieger JonasRieger self-assigned this Jul 27, 2023
@JonasRieger JonasRieger added the enhancement New feature or request label Jul 27, 2023
@JonasRieger
Copy link
Owner

JonasRieger commented Jul 31, 2023

There is no built-in package function for things like this. But it is quite easy to extract such information from the object:

library(rollinglda)

# roll = rollinglda object
dates = getDates(roll)

# to extract monthly topic matrices:
months = lubridate::floor_date(dates, "month")
xmonth = sort(unique(months))

topicsm = lapply(xmonth, function(x){
  tmp = table(factor(unlist(getAssignments(getLDA(roll))[months == x])+1, levels = 1:getK(getLDA(roll))), 
              factor(unlist(lapply(getDocs(roll)[months == x], function(y) y[1,]))+1,
                     levels = seq_len(length(getVocab(roll)))))
  tmp = matrix(as.integer(tmp), nrow = getK(getLDA(roll)))
  colnames(tmp) = getVocab(roll)
  tmp
})

# then, you can, e.g., extract monthly topWords
topwordsm = lapply(topicsm, tosca::topWords, numWords = 50)

Maybe I'll include such a function for postprocessing in a future version of rollinglda. It feels quite convenient.

If you have any further questions, feel free to reach out.

@reve0913
Copy link
Author

Thank you so much for your explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants