Graphical User Interface of ‘hbsaems’ Using ‘shiny’

Introduction

The run_sae_app() function in the hbsaems package provides an interactive Shiny Dashboard for Hierarchical Bayesian Small Area Estimation (HBSAE) using brms for Bayesian inference with Stan. This application offers a user-friendly interface to upload data, define models, and obtain estimation results without requiring extensive R coding.

Install Required Packages

Ensure that you have installed the hbsaems package:

install.packages("hbsaems")

Load Required Packages

library(hbsaems)

Running the Shiny App

To launch the application, simply call:

run_sae_app()

This will start a Shiny application that runs in your web browser.

App Structure

1. Data Upload

Users can either upload a .csv file or select a data frame available in the current R environment.

2. Data Exploration

This tab provides four types of data exploration tools to help users understand the characteristics of the dataset:

3. Modeling

a. Modeling Configuration

Users can define key model components:

  • Basic Settings:
    • Response Variable
    • Auxiliary Variables (linear and nonlinear covariates)
    • Group Variables (for hierarchical modeling)
    • Distribution Type (e.g., Lognormal, Logitnormal, Beta, or Custom)
    • HB Family & Link Function (for Custom models)
  • Spatial Modeling:
    • Choose spatial type (SAR or CAR)
    • Specify neighborhood structure
    • Upload spatial weight matrix (.csv)
  • Missing Data Handling:
    • Choose between deletion, imputation, or model-based handling

b. Prior Checking

Before fitting the model, users can configure prior distributions and perform prior predictive checks:

  • Summarize prior settings
  • Simulate from prior distributions
  • Visualize prior predictive plots

c. MCMC Settings

Configure sampling parameters for Bayesian estimation:

  • Seed
  • Chains
  • Cores
  • Thinning Rate
  • Iterations
  • Warm-up
  • Adapt Delta

Click “Fit Model” to begin model fitting using brms.

4. Results

After fitting, results are available through multiple tabs:

Example Workflow

  1. Upload Dataset: Use .csv or select data from environment.
  2. Explore Data: Summarize and visualize key variables.
  3. Define Model: Set model structure, priors, and MCMC settings.
  4. Prior Checking: Validate prior assumptions before sampling.
  5. Fit Model: Run HBSAE using brms.
  6. Review Results: Interpret summary and diagnostics.
  7. Predict & Save: Generate estimates and export outputs.

Troubleshooting

If you encounter errors when launching the app:

  1. Ensure all dependencies are installed manually:

    install.packages(c("shiny", "shinyWidgets", "shinydashboard", "readxl", "DT"))
  2. Reinstall hbsaems:

    remove.packages("hbsaems")
    install.packages("hbsaems")
  3. Check the app directory:

    system.file("shiny/sae_app", package = "hbsaems")

Conclusion

run_sae_app() provides an intuitive way to perform HBSAE modeling using a Shiny interface, making Bayesian small area estimation accessible without requiring in-depth coding knowledge. Users can define models, inspect results, and generate predictions interactively.