Giter Club home page Giter Club logo

modsem's Introduction

This is a package which allows you to perform interactions between latent variables (i.e., moderation) in CB-SEM. See https://kss2k.github.io/intro_modsem/ for a tutorial.

To Install

# From CRAN 
install.packages("modsem")

# Latest version from Github
install.packages("devtools")
devtools::install_github("kss2k/modsem", build_vignettes = TRUE)

Methods/Approaches

There are a number of approaches for estimating interaction effects in SEM. In modsem(), the method = "method" argument allows you to choose which to use.

  • "ca" = constrained approach (Algina & Moulder, 2001)
    • Note that constraints can become quite complicated for complex models, particularly when there is an interaction including enodgenous variables. The method can therefore be quite slow.
  • "uca" = unconstrained approach (Marsh, 2004)
  • "rca" = residual centering approach (Little et al., 2006)
  • "dblcent" = double centering approach (Marsh., 2013)
    • default
  • "pind" = basic product indicator approach (not recommended)
  • "lms" = The Latent Moderated Structural equations (LMS) approach, see the vignette
  • "qml" = The Quasi Maximum Likelihood (QML) approach, see the vignette
  • "mplus"
    • estimates model through Mplus, if it is installed

New Features (01.06.2024-05-06-2024)

  • New function for plotting interaction effects (plot_interaction()), see the vignette
  • Interaction effects between endogenous and exogenous variables are now possible by default with QML-approach.
  • Interaction effects between two endogenous variables are now possible with the LMS and QML approach, using the 'cov.syntax' argument, see the vignette for more information. (only available on GitHub, not on CRAN)

Examples

One interaction

library(modsem)
m1 <- '
  # Outer Model
  X =~ x1 + x2 +x3
  Y =~ y1 + y2 + y3
  Z =~ z1 + z2 + z3
  
  # Inner model
  Y ~ X + Z + X:Z 
'

# Double centering approach
est1_dca <- modsem(m1, oneInt)
summary(est1_dca)

# Constrained approach
est1_ca <- modsem(m1, oneInt, method = "ca")
summary(est1_ca)

# QML approach 
est1_qml <- modsem(m1, oneInt, method = "qml")
summary(est1_qml, standardized = TRUE) 

# LMS approach 
est1_lms <- modsem(m1, oneInt, method = "lms") 
summary(est1_lms)

Theory Of Planned Behavior

tpb <- "
# Outer Model (Based on Hagger et al., 2007)
  ATT =~ att1 + att2 + att3 + att4 + att5
  SN =~ sn1 + sn2
  PBC =~ pbc1 + pbc2 + pbc3
  INT =~ int1 + int2 + int3
  BEH =~ b1 + b2

# Inner Model (Based on Steinmetz et al., 2011)
  # Causal Relationsships
  INT ~ ATT + SN + PBC
  BEH ~ INT + PBC
  BEH ~ PBC:INT
"

# double centering approach
est_tpb_dca <- modsem(tpb, data = TPB, method = "dblcent")
summary(est_tpb_dca)

# Constrained approach using Wrigths path tracing rules for generating
# the appropriate constraints
est_tpb_ca <- modsem(tpb, data = TPB, method = "ca") 
summary(est_tpb_ca)

# LMS approach 
est_tpb_lms <- modsem(tpb, data = TPB, method = "lms")
summary(est_tpb_lms, standardized = TRUE) 

# QML approach 
est_tpb_qml <- modsem(tpb, data = TPB, method = "qml") 
summary(est_tpb_qml, standardized = TRUE)

Interactions between two observed variables

est2 <- modsem('y1 ~ x1 + z1 + x1:z1', data = oneInt, method = "pind")
summary(est2)

## Interaction between an obsereved and a latent variable 
m3 <- '
  # Outer Model
  X =~ x1 + x2 +x3
  Y =~ y1 + y2 + y3
  
  # Inner model
  Y ~ X + z1 + X:z1 
'

est3 <- modsem(m3, oneInt, method = "pind")
summary(est3)

modsem's People

Contributors

kss2k avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

yihongfa

modsem's Issues

How to test a dummy variable as a moderator in a full SEM model (within lavaan)

Hello everyone ! I would like to ask a few questions.

I need to run a full SEM where latent Y is should be predicted by latent X and latent Z. X and Z are allowed to correlate.
The six indicators related to the variable Y are coming from a merge of data between two different scales/questionnary (each participant responded to only one of the two versions). So if we can assign V and W as the latent variables representing the two old versions of the questionnary coming from the pre-merged columns for each indicator, approximatively half the population responded to V and the other part responded to W.

In the dataset, we have a group dummy variable that mentions which old version (V or W, assigning at 0 or 1) participants have responded.

The main goal of the analysis is to test if we can ask in two different ways (so with two different questionnaries) what we think is supposed to be the same construct, so it's why we have merged the two different versions in order to have one. But of course, we want to test whether the original versions could act as a moderator in the relationship between X and Y or Z and Y, if there is an original effect of X (or Z) on Y.

How should I proceed exactly to test this moderation effect ? Should I run a multigroup SEM analysis even if the participants responded to a different version of the construct ? And even if I want to test in the same model the effect of X on Y within the all population ?
I'm note sure if I can use my dummy variable and in what extent. I'm a bit stuck with this so any kind answers are welcome !
Thanks a lot for reading,
Best,
Augustin

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.