stminsights icon indicating copy to clipboard operation
stminsights copied to clipboard

Inconsistent Results from get_effects()

Open selimyaman opened this issue 3 years ago • 1 comments

I'm not sure if I'm doing something wrong, but I found inconsistent results between stminsights::get_effects and stm::plot.estimateEffect.

First I wanted to plot the estimations of an effect of a continuous variable on topics, so I used stm::plot.estimateEffect. But the original package uses base R graphics device, which is not very flexible. I wanted to use facet_wrap in ggplot - so came across your package. I plotted the effect of 'ideology' (my continuous variable) both using plot.estimateEffect and get_effects from stminsights. When visually inspecting the lines for the estimates, I saw widely different graphs for same topics, obtained in two methods.

Anyways, eventually I found a workaround looking at your source code (I never thought storing the result of plot.estimateEffect in my env) - but just wanted to let you know in case you may want to have a look at it.

Below is an example code - (by no means it's reproducible).

effects <- stminsights::get_effects(estimates = prep,  
                      variable = 'ideal_point',  
                      type = 'continuous'). 
effects$topic <- as.integer(effects$topic)
effects$topicnums <- effects$topic
effects <- subset (effects,topic %in% top10top)
effects2 <- left_join(effects, t)
effects2 %>%
  ggplot(aes(x = value, y = proportion, colour=topic_names)) +
  xlim(-2,2)+
   geom_line() +
   geom_ribbon(aes(ymin = lower, ymax = upper), alpha = 0.4, show.legend = FALSE,linetype=0)+
   theme_light() + 
  theme(legend.position = "none") +
   labs(x = 'More Liberal...More Conservative', y = 'Topic Proportion')+
  facet_wrap(~ topic_names)

vs.

plot(prep, 
     covariate="ideal_point", 
     topics=t_select, 
     model=k16, 
     method="continuous", 
     xlab="More Liberal ... More Conservative", 
     main="Ideal Point Changes by (Select) Topics",
     xlim=c(-2,2),
     labeltype ="custom",
     custom.labels=t_select_names,
     printlegend = TRUE)

selimyaman avatar Feb 15 '22 06:02 selimyaman

Hi, thanks for letting me know. I would need a reproducible example though to be able to look into this. It would be helpful if you could reproduce this with publicly available datasets such as the poliblog5k that is included in the STM package? Another option would be to send me your dataset (if possible) and code, e.g. per e-mail.

cschwem2er avatar Mar 24 '22 07:03 cschwem2er

Closed due to inactivity

cschwem2er avatar May 05 '23 07:05 cschwem2er