A Guide to Using stminsights: Your Interactive STM Companion

Nov 20, 2022 | Data Science

If you’re delving into the fascinating world of Structural Topic Models (STM), then you’ve stumbled upon a treasure trove in the form of the stminsights Shiny application! In this article, we’ll walk you through the installation, usage, and deployment steps, ensuring you can interactively validate, interpret, and visualize your STM findings. Let’s get started!

What is stminsights?

The stminsights application is designed to simplify your post-modeling journey by providing an interactive interface for analyzing Structural Topic Models. It’s your go-to when trying to make sense of STM results, and it works seamlessly with the STM package.

Installation Steps

To unleash the power of stminsights, you’ll first need to install it. Here’s how:

  • For the latest development version, execute the following in your R console:
  • devtools::install_github("cschwem/stminsights")
  • Windows users must have Rtools properly set up from CRAN Rtools.
  • If you prefer, you can also install it from CRAN with:
  • install.packages("stminsights")

Using stminsights

Once installed, it’s time to launch the stminsights Shiny app. Here’s how to get it running:

  • Load the package into your R environment:
  • library(stminsights)
  • Start the app using:
  • run_stminsights()
  • Upload your .RData file containing:
    • One or several STM objects
    • One or several estimateEffect objects
    • A corresponding object from which your STM models were fitted

For example, you could fit two models using the Political Blog Corpus with the following snippets:

library(stm)
out <- list(documents = poliblog5k.docs,
            vocab = poliblog5k.voc,
            meta = poliblog5k.meta)

poli <- stm(documents = out$documents,
            vocab = out$vocab,
            data = out$meta,
            prevalence = ~ rating * s(day),
            K = 20)

prep_poli <- estimateEffect(1:20 ~ rating * s(day), poli, meta = out$meta)

poli_content <- stm(documents = out$documents,
                     vocab = out$vocab,
                     data = out$meta,
                     prevalence = ~ rating + s(day),
                     content = ~ rating,
                     K = 15)

prep_poli_content <- estimateEffect(1:15 ~ rating + s(day), poli_content, meta = out$meta)

save.image("stm_poliblog5k.RData")

Analogy for Understanding the Code

Think of the above code as preparing a special recipe for a complex dish. You start by gathering all your ingredients (the STM objects, effects estimates, and fitting object) and carefully measuring them out before cooking (saving your model results). Just like how each ingredient plays a role in the final flavor of your dish, each component of your models contributes to the story within your data.

Deploying stminsights on Shiny Server

If you're keen to share this fabulous tool, deployment on your own Shiny server is straightforward:

  • Navigate to the inst/app folder of stminsights and locate the app.R file.
  • Place the app.R file into a directory on your server.

Troubleshooting

If you encounter issues during installation or usage, here are a few troubleshooting tips:

  • Ensure you have the necessary dependencies installed, including the STM package.
  • Check the console for error messages and resolve any missing files or packages.
  • If you're experiencing network errors while trying to download from GitHub, ensure your internet connection is stable.
  • For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Final Thoughts

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Enjoy unraveling your Structural Topic Models with stminsights! Happy modeling!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox