Calculate topic similarity for multiple dyads
Source:R/conversation_multidyads.R
topic_sim_dyads.Rd
This function calculates topic similarity over a sequence of conversation exchanges for multiple dyads. It uses the Latent Dirichlet Allocation (LDA) method for topic modeling and the "slam" package for efficient handling of sparse matrices.
Arguments
- conversations
A data frame with columns 'dyad_id', 'speaker', and 'processed_text'
- method
A character string specifying the method to use: currently only "lda" is supported
- num_topics
An integer specifying the number of topics to use in the LDA model
- window_size
An integer specifying the size of the sliding window
Value
A list containing the sequence of similarities for each dyad and the overall average similarity
Examples
convs <- data.frame(
dyad_id = c(1, 1, 1, 1, 2, 2, 2, 2),
speaker = c("A", "B", "A", "B", "C", "D", "C", "D"),
processed_text = c("i love pizza", "me too favorite food",
"whats your favorite topping", "enjoy pepperoni mushrooms",
"i prefer pasta", "pasta delicious like spaghetti carbonara",
"ever tried making home", "yes quite easy make")
)
topic_sim_dyads(convs, method = "lda", num_topics = 2, window_size = 2)
#> $similarities_by_dyad
#> $similarities_by_dyad$`1`
#> [1] 0 0 0
#>
#> $similarities_by_dyad$`2`
#> [1] 0 0 0
#>
#>
#> $overall_average
#> (Intercept)
#> 0
#>