## bsem

### An R package for Bayesian structural equation modeling.

The package allows Bayesian analysis for particular cases of structural equation models (SEMs) based on rstan integration. Examples in get started and exploring bsem include confirmatory factor analysis and confirmatory SEM. The full SEM model (outer and inner models), enables the evaluation of user-defined latent variables along with the analysis of established linear relationships among the latent scores.

## Install

Please install remotes package and devtools before installing:

install.packages("remotes")
install.packages("devtools")

Due to R 4.0 chain info is not working properly. As discussed here a possible fix is to get the under development version with:

remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")

Afterwards, you can install bsem using:

devtools::install_github("rvpanaro/bsem", dependencies = TRUE)

## Basic working example

• Get some simulated data.
dt <- bsem::simdata()
semfit <- bsem::sem(
data = dt$data, blocks = dt$blocks,
paths = dt$paths, exogenous = dt$exogenous,
signals = dt\$signals,
iter = 2000,
warmup = 1000,
chains = 4
)
• Print the outcome:
print(semfit)
• Get posterior summary statistics:
summary(semfit)
• Plot a diagram with the relatioships between variables:
plot(semfit)

bsem::runShiny()
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.4846773147583008, "perplexity": 13502.235557455819}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-43/segments/1634323585561.4/warc/CC-MAIN-20211023033857-20211023063857-00447.warc.gz"}