Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Natural feeling domain-specific language for building structural equation models in R for estimation by covariance-based methods (like LISREL/Lavaan) or partial least squares (like SmartPLS)

NotificationsYou must be signed in to change notification settings

sem-in-r/seminr

Repository files navigation

CRAN_Status_Badgemetacran downloads

SEMinR allows users to easily create and modify structural equationmodels (SEM). It allows estimation using either covariance-based SEM(CBSEM, such as LISREL/Lavaan), or Partial Least Squares Path Modeling(PLS-PM, such as SmartPLS/semPLS).

First Look

Main features of using SEMinR:

  • Anatural feeling,domain-specific language to build and estimateSEMs in R
  • High-level functions to quickly specify interactions and complicatedstructural models
  • Modular design of models that promotes reuse of model components
  • Encouragesbest practices by use of smart defaults and warnings

Take a look at the easy syntax and modular design:

# Define measurements with famliar terms: reflective, composite, multi-item constructs, etc.measurements<- constructs(  reflective("Image",       multi_items("IMAG",1:5)),  composite("Expectation", multi_items("CUEX",1:3)),  composite("Loyalty",     multi_items("CUSL",1:3),weights=mode_B),  composite("Complaints",  single_item("CUSCO")))# Create four relationships (two regressions) in one line!structure<- relationships(  paths(from= c("Image","Expectation"),to= c("Complaints","Loyalty")))# Estimate the model using PLS estimation scheme (Consistent PLS for reflectives)pls_model<- estimate_pls(data=mobi,measurements,structure)#> Generating the seminr model#> All 250 observations are valid.# Re-estimate the model as a purely reflective model using CBSEMcbsem_model<- estimate_cbsem(data=mobi, as.reflective(measurements),structure)#> Generating the seminr model for CBSEM

SEMinR can plot models using the semplot (for CBSEM models) orDiagrammeR (for PLS models) packages with a simpleplot method.

plot(pls_model,title="PLS Model")save_plot("myfigure.pdf")

SEMinR allows various estimation methods for constructs and SEMs:

  • Covariance-based Structural Equation Modeling (CBSEM)
    • Covariance-based estimation of SEM using the popularLavaan package
    • Currently supports mediation and moderation models with constructs
    • Easilyspecify interactions between constructs
    • Adds ten Bergefactor score extraction to get same correlationpatterns as latent factors
    • AddsVIF and other validity assessments
  • Confirmatory Factor Analysis (CFA) using Lavaan
    • UsesLavaan package andreturns results and syntax
    • Adds ten Bergefactor score extraction to get same correlationpatterns as latent factors
  • Partial Least Squares Path Modeling (PLS-PM)
    • Uses non-parametricvariance-based estimation to constructcomposites andcommon-factors
    • Automaticallyestimates using Consistent PLS (PLSc) when emulatingreflective common factors
    • Adjusts for known biases in interaction terms in PLS models
    • Continuously tested against leading PLS-PM software to ensure parityof outcomes: SmartPLS, ADANCO, semPLS, and matrixpls
    • High performance, multi-core bootstrapping function

Researchers can now create a SEM and estimate it using differenttechniques (CBSEM, PLS-PM).

Installation

You can install SEMinR from R with:

install.packages("seminr")

Usage and Examples

Load the SEMinR package:

library(seminr)

Describe measurement and structural models and then estimate them. Seethe various examples below for different use cases:

  1. CFA + CBSEM Example with CommonFactors
  2. Consistent-PLS (PLSc) Example with CommonFactors
  3. PLS-PM Example with Composites
  4. Comparing CBSEM and PLS-PMExample

CFA + CBSEM Example with Common Factors

Note that CBSEM models reflective common-factor constructs, notcomposites. SEMinR uses the powerful Lavaan package to estimate CBSEMmodels – you can even inspect the more complicated Lavaan syntax that isproduced.

Describe reflective constructs and interactions:

# Distinguish and mix composite or reflective (common-factor) measurement models# - composite measurements will have to be converted into reflective ones for CBSEM (see below)measurements<- constructs(  reflective("Image",       multi_items("IMAG",1:5)),  reflective("Expectation", multi_items("CUEX",1:3)),  interaction_term(iv="Image",moderator="Expectation",method=two_stage),  reflective("Loyalty",     multi_items("CUSL",1:3)),  reflective("Complaints",  single_item("CUSCO")))

Describe the causal relationships between constructs and interactions:

# Quickly create multiple paths "from" and "to" sets of constructsstructure<- relationships(  paths(from= c("Image","Expectation","Image*Expectation"),to="Loyalty"),  paths(from="Image",to= c("Complaints")))

Put the above elements together to estimate the model using Lavaan:

# Evaluate only the measurement model using Confirmatory Factor Analysis (CFA)cfa_model<- estimate_cfa(data=mobi,measurements)summary(cfa_model)# Dynamically compose full SEM models from individual parts# - if measurement model includes composites, convert all constructs to reflective using:#     as.reflective(measurements)cbsem_model<- estimate_cbsem(data=mobi,measurements,structure)sum_cbsem_model<- summary(cbsem_model)sum_cbsem_model$meta$syntax# See the Lavaan syntax if you wish

Consistent-PLS (PLSc) Example with Common Factors

Models with reflective common-factor constructs can also be estimated inPLS-PM, using Consistent-PLS (PLSc). Note that the popular SmartPLSsoftware models constructs as composites rather than common-factors(see below) but can also do PLSc as aspecial option.

We will reuse the measurement and structural models from earlier:

# Optionally inspect the measuremnt and structural modelsmeasurementsstructure

Estimate full model using Consistent-PLS and bootstrap it for confidenceintervals:

# Models with reflective constructs are automatically estimated using PLScpls_model<- estimate_pls(data=mobi,measurements,structure)summary(pls_model)# Use multi-core parallel processing to speed up bootstrapsboot_estimates<- bootstrap_model(pls_model,nboot=1000,cores=2)summary(boot_estimates)

PLS-PM Example with Composites

PLS-PM typically models composites (constructs that are weighted averageof items) rather than common factors. Popular software like SmartPLSmodels composites either as Mode A (correlation weights) or Mode B(regression weights). We also support both modes as well as second-ordercomposites. rather than common factors. Popular software like SmartPLSmodels composites by default, either as Mode A (correlation weights) orMode B (regression weights). We also support second-order composites.

Describe measurement model for each composite, interaction, or higherorder composite:

# Composites are Mode A (correlation) weighted by defaultmobi_mm<- constructs(  composite("Image",        multi_items("IMAG",1:5)),  composite("Value",        multi_items("PERV",1:2)),  higher_composite("Satisfaction",dimensions= c("Image","Value"),method=two_stage),  composite("Expectation",  multi_items("CUEX",1:3)),  composite("Quality",      multi_items("PERQ",1:7),weights=mode_B),  composite("Complaints",   single_item("CUSCO")),  composite("Loyalty",      multi_items("CUSL",1:3),weights=mode_B))

Define a structural (inner) model for our PLS-PM:

mobi_sm<- relationships(  paths(from= c("Expectation","Quality"),to="Satisfaction"),  paths(from="Satisfaction",to= c("Complaints","Loyalty")))

Estimate full model using PLS-PM and bootstrap it for confidenceintervals:

pls_model<- estimate_pls(data=mobi,measurement_model=mobi_mm,structural_model=mobi_sm)summary(pls_model)# Use multi-core parallel processing to speed up bootstrapsboot_estimates<- bootstrap_model(pls_model,nboot=1000,cores=2)summary(boot_estimates)

Plotting the model results

SEMinR can plot all supported models using the dot language and thegraphViz.js widget from theDiagrammeR package.

# generate a small model for creating the plotmobi_mm<- constructs(  composite("Image",        multi_items("IMAG",1:3)),  composite("Value",        multi_items("PERV",1:2)),  higher_composite("Satisfaction",dimensions= c("Image","Value"),method=two_stage),  composite("Quality",      multi_items("PERQ",1:3),weights=mode_B),  composite("Complaints",   single_item("CUSCO")),  reflective("Loyalty",      multi_items("CUSL",1:3)))mobi_sm<- relationships(  paths(from= c("Quality"),to="Satisfaction"),  paths(from="Satisfaction",to= c("Complaints","Loyalty")))pls_model<- estimate_pls(data=mobi,measurement_model=mobi_mm,structural_model=mobi_sm)#> Generating the seminr model#> Generating the seminr model#> All 250 observations are valid.#> All 250 observations are valid.boot_estimates<- bootstrap_model(pls_model,nboot=100,cores=1)#> Bootstrapping model using seminr...#> SEMinR Model successfully bootstrapped

When we have a model, we can plot it and save the plot to files.

plot(boot_estimates,title="Bootstrapped Model")save_plot("myfigure.pdf")

Themes

We can customize the plot using an elaborate theme. Themes can be usedfor individual plots as a parameter or set as a default. Using theseminr_theme_create() function allows to define different themes.

# Tip: auto complete is your friend in finding all possible themeing options.thm<- seminr_theme_create(plot.rounding=2,plot.adj=FALSE,sm.node.fill="cadetblue1",mm.node.fill="lightgray")# change new default theme - valid until R is restartedseminr_theme_set(thm)# the new plotplot(boot_estimates)

Comparing CBSEM and PLS-PM Example

We can re-estimate a composite PLS-PM model as a common-factor CBSEM.Such a comparison might interest researchers seeking to evaluate howtheir constructs behave when modeled as composites versuscommon-factors.

# Define measurements with famliar terms: reflective, multi-item constructs, etc.measurements<- constructs(  composite("Image",       multi_items("IMAG",1:5)),  composite("Expectation", multi_items("CUEX",1:3)),  composite("Loyalty",     multi_items("CUSL",1:3)),  composite("Complaints",  single_item("CUSCO")))# Create four relationships (two regressions) in one line!structure<- relationships(  paths(from= c("Image","Expectation"),to= c("Complaints","Loyalty")))# First, estimate the model using PLSpls_model<- estimate_pls(data=mobi,measurements,structure)# Reusable parts of the model to estimate CBSEM results# note: we are using the `as.reflective()` function to convert composites to common factorscbsem_model<- estimate_cbsem(data=mobi, as.reflective(measurements),structure)# Re-estimate the model using common factors in Consistent PLS (PLSc)pls_model<- estimate_pls(data=mobi, as.reflective(measurements),structure)

Documentation

Thevignette for Seminr can be found onGitHub or by running thevignette("SEMinR") command after installation.

Demo code for various use cases with SEMinR can be found in theseminr/demo/folder or by running commands such asdemo("seminr-contained") afterinstallation.

Model Specification:

Model Visualization:

Syntax Style:

Sister Projects

  • seminrstudio: A set ofaddins for RStudio to simplify using SEMinR.

Partner Projects

We communicate and collaborate with several other open-source projectson SEM related issues.

  • plspm package for R: an earlyand limited PLS path modeling package for R that inspired thedevelopment of SEMinR, among others; it is no longer maintained.
  • plspm package forPython: awell-maintained PLS modeling pakage for Python; it is tested againstSEMinR and borrows some syntactic ideas from SEMinR.
  • cSEM: a well-maintained andcomprehensive composite analysis project implementing PLS and GSCA forR, using Lavaan style syntax

Contact Us

Facebook Group:https://www.facebook.com/groups/seminr

You will find the developers and other users here who might also be ableto help or discuss.

Issue Tracker:https://github.com/sem-in-r/seminr/issues

This is the official place to submit potential bugs or request newfeatures for consideration.

About Us

Primary Authors:

Key Contributors:

And many thanks to the growing number of folks who have reached out withfeature requests, bug reports, and encouragement. You keep us going!

About

Natural feeling domain-specific language for building structural equation models in R for estimation by covariance-based methods (like LISREL/Lavaan) or partial least squares (like SmartPLS)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors8

Languages


[8]ページ先頭

©2009-2025 Movatter.jp