Giter Club home page Giter Club logo

jamesuanhoro / minorbsem Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 7.93 MB

An R package for Bayesian structural equation models that account for the influence of minor factors

Home Page: https://jamesuanhoro.github.io/minorbsem/

License: GNU General Public License v3.0

R 55.06% Stan 29.36% TeX 13.25% Shell 2.33%
structural-equation-modeling bayesian-statistics factor-analysis latent-variable-models multivariate-analysis psychometrics r-package

minorbsem's Introduction

minorbsem

Project Status: Active The project has reached a stable, usable state and is being actively developed. GitHub Codecov test coverage minimal R version GitHub R package version CRAN_Status_Badge GitHub last commit R-CMD-check

JOSS-paper

Table of Contents

Package overview

Structural equation models (SEMs) rarely reject the null hypothesis that there is no model misspecification. One explanation for this problem is that covariance structures are influenced by major factors which we can hypothesize about and minor factors which we cannot predict a-priori, e.g. MacCallum and Tucker (1991).

Goals

The goal of minorbsem is to facilitate fitting Bayesian SEMs that estimate the influence of minor factors on the covariance matrix, following the approach in Uanhoro (2023). Briefly, the method estimates all residual covariances with priors that shrink them towards zero, and the model returns the magnitude of the influence of minor factors.

The package also allows you set priors on all substantive model parameters directly. Importantly, prior distributions assume latent variables have a total variance of 1, even in latent regression models.

Permitted models and supported data types

The package is able to fit a variety of model configurations:

  • CFA, allowing automatically estimated penalized cross-loadings
  • Path models with latent and observed variables
    • Any observed variables in a structural model must be represented with a single-indicator latent variable with the error variance of the observed variable constrained to 0

The package is also able to analyze correlation structures using methods in Archakov and Hansen (2021). This includes polychoric correlation matrices as long as an asymptotic variance matrix is provided. The relevant paper is under review at Structural Equation Modeling.

The package does not support fitting multi-group or multilevel models. See the bayesianmasem package for multi-group factor analysis via meta-analysis methods.

Installation

minorbsem is hosted on GitHub, so we need the remotes package to install it. We also need to install the cmdstanr package and CmdStan in order to use Stan.

Instructions:

install.packages("remotes")  # install remotes

# next install cmdstanr and CmdStan:
install.packages(
  "cmdstanr",
  repos = c("https://mc-stan.org/r-packages/", getOption("repos"))
)
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
cmdstanr::install_cmdstan()

# Then finally minorbsem:
remotes::install_github("jamesuanhoro/minorbsem")

A reasonably complete demonstration

library(minorbsem)
# Basic Holzinger-Swineford model
syntax_1 <- "
F1 =~ x1 + x2 + x3
F2 =~ x4 + x5 + x6
F3 =~ x7 + x8 + x9"
# Expect a summary table output
fit_1 <- minorbsem(syntax_1, HS)

# Save output table to html file, see: ?pretty_print_summary for more options
pretty_print_summary(fit_1, save_html = "baseline_model.html")

# Histogram of parameters, see: ?parameter_hist for arguments
parameter_hist(fit_1)

# Traceplot of parameters, see: ?parameter_trace for arguments
parameter_trace(fit_1)

# Examine all standardized residual covariances
plot_residuals(fit_1)
plot_residuals(fit_1, type = "range")

Additional examples

Different methods to capture the influence of minor factors

Default method above is method = "normal" assuming standardized residual covariances are on average 0 and vary from 0 in continuous fashion.

# Fit same model as above but use global-local prior to estimate
# minor factor influences
fit_gdp <- minorbsem(syntax_1, HS, method = "GDP")
plot_residuals(fit_gdp)
parameter_hist(fit_gdp)
parameter_trace(fit_gdp)

# Ignoring minor factor influences
fit_none <- minorbsem(syntax_1, HS, method = "none")
parameter_hist(fit_none)
parameter_trace(fit_none)

# Error!!!: Plotting residuals will give an error message
# since minor factor influences are assumed null
plot_residuals(fit_none)

Relax simple structure

fit_complex <- minorbsem(syntax_1, HS, simple_struc = FALSE)

There are other methods, see details section in ?minorbsem.

Contributions are encouraged

All users of R (or SEM) are invited to submit functions or ideas for functions.

Feel free to:

  • open an issue to report a bug or to discuss recommendations;
  • submit pull requests to recommend modifications or suggest improvements.

You can also email the package maintainer, James Uanhoro (James dot Uanhoro at unt dot edu). Thank you for helping improve minorbsem :).

Citations

Archakov, Ilya, and Peter Reinhard Hansen. 2021. “A New Parametrization of Correlation Matrices.” Econometrica 89 (4): 1699–1715. https://doi.org/10.3982/ECTA16910.

MacCallum, Robert C., and Ledyard R. Tucker. 1991. “Representing Sources of Error in the Common-Factor Model: Implications for Theory and Practice.” Psychological Bulletin 109 (3): 502–11. https://doi.org/10.1037/0033-2909.109.3.502.

Uanhoro, James Ohisei. 2023. “Modeling Misspecification as a Parameter in Bayesian Structural Equation Models.” Educational and Psychological Measurement 0 (0): 00131644231165306. https://doi.org/10.1177/00131644231165306.

minorbsem's People

Contributors

aaronpeikert avatar jamesuanhoro avatar purple-skittles avatar smasongarrison avatar stonegold546 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

minorbsem's Issues

Present latent variable regression model results with standardized factors

Latent variable regression models are estimated with marker loadings set to 1, and this improves posterior sampling.

We then estimate a factor SD, it may be good for:

  • #8 This factor SD to share same prior as loadings(?)

Regardless:

  • Parameter estimates should be transformed within Stan such that loadings et al. are printed with standardized factors assumed, making presentation similar to CFA presentation.
  • #12

Add PPP

  • Compute within Stan, right?
  • Print it out

Additional approaches to incorporate

Would be good to see how current program structure holds up for different models, i.e. can we retain same helper functions for different models etc ...

  • Expand the model support, i.e. reflect the diversity of models offered by (b)lavaan
    • Basically follow (b)lavaan all the way through
    • Time consuming ...
  • Regular model with no modelled residual covariance structure
  • Has global-local (generalized double Pareto) priors for non-specified cross-loadings if simple_struc = FALSE
  • Alternative priors for estimating residual covariances, initial approach is normal (ridge-style)
  • Wu & Browne (2015): https://doi.org/10.1007/s11336-015-9451-3
    • Generalized matrix beta type-II approach (Wishart->Inverse-Wishart) that similarly assumes minor factor influences, referred to as adventitious error.
    • Issues calculating log-likelihood if using GMB dist, instead of sampling Inv-Wishart
  • [x] Uanhoro (2022): https://doi.org/10.1080/10705511.2022.2142128
    • Meta-analytic SEM approach (using Wu & Browne above as basis) that estimates error covariance structure.
    • [ ] Add moderators
    • [ ] Add missing data
    • Sent to bayesianmasem
  • Serious approach for modelling error in mean structures?
    • Would be useful for growth-curve models.
    • Current thinking: error in mean structures is already reflected in the residual variance parameter -- no need to model concurrently.
    • Practical approach is to compare saturated and unsaturated mean structures for fit.
  • Practical (or not too slow) approach for modelling error in non-continuous data?
    • Would be useful to have options for binary and ordinal, but these take too long.
    • Any credible moments-based (two-step) approaches so it does not take forever? Hotelling T-square?
    • Bring Archakov et al. approach over from bayesianmasem
  • Non-complete data
  • Standard multi-group models, so multi-group parameters ...
    • Or maintain that meta-analytic (hierarchical) approach is actually preferable especially once we have many groups?

make startup message more actionable

This is currently the result of:

> library(minorbsem)
 
###############################################################################
This is minorbsem 0.2.3
All users of R (or SEM) are invited to submit functions or ideas for functions.
###############################################################################

But it is unclear how users should submit such ideas (bugs?). Maybe suggest opening an issue on GH.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.