mcallaghan / text-as-data

13 stars 20 forks source link

Merging the model and with the original corpus #10

Open kraessa16 opened 1 year ago

kraessa16 commented 1 year ago

As many had the issues, Max asked me to share my solution for merging the result of the model analysis with the original corpus in order to visualize it:


length(topics(lda.model)) #the length of the lda-model I have created

#both objects do not share the same length
#therefore, we create a new dataframe with the original corpus

df <- data.frame(text=as.character(corp_manif)) 
df$id <- names(corp_manif)
df$partyyear <- manif$partyyear #I add the partyyear variable to identify the resepctive party manifesto

#now we create a document with the model data
doc_topics <- tidy(lda.modell, matrix="gamma") %>%
left_join(df, by=c("document"="id"))
#and we add the document to our new dataframe

names(corp_manif)```