Giter VIP home page Giter VIP logo

semcoa's Introduction

SEMCOA - Composite Overfit Analysis for Structural Equation Models

semcoa is an R package to conduct the Composite Overfit Analysis (COA) framework for Structural Equation Models (SEM), and to then report and plot results.

Installation

# install.packages("devtools")
devtools::install_github("sem-in-r/semcoa")

Required Libraries

Please install following packages:

  • seminr (composite model estimation)
  • rpart (decision tree)
  • maptools (plotting labels)

Testing

Run all tests using ‘Test Package’ of RStudio, or run specific test files using devtools:

test_active_file("tests/testthat/test-integration-coa.R")
test_active_file("tests/testthat/test-unit-dtree.R")

Demo

Look at demos folder for full examples. The following is a brief look at the code and output.

First, let’s setup our composite construct-based model using the seminr package for specifying structural equation models.

#> Generating the seminr model
#> All 216 observations are valid.

Now, we can conduct our Composite Overfit Analysis (COA). We start by loading the semcoa library:

library(semcoa)
library(rpart)
library(maptools)
#> Loading required package: sp
#> Checking rgeos availability: FALSE
#>      Note: when rgeos is not available, polygon geometry     computations in maptools depend on gpclib,
#>      which has a restricted licence. It is disabled by default;
#>      to enable gpclib, type gpclibPermit()

Now we can analyze our estimated composite SEM model using COA:

utaut_overfit <- coa(pls_model = utaut_model, 
                     focal_construct = "BI",
                     params = c("path_coef", "rSquared"))
#> Computing predictive deviance
#> Generating Deviance Tree
#> Identifying Unstable Paths

We can visualize our predictive deviant cases and groups as follows:

plot_pd(utaut_overfit)

# Inspect all the names of the groups
names(utaut_overfit$dtree$deviant_groups)
#> [1] "a" "b" "c" "d" "e"

And we can inspect more details about the groups by seeing the defining descriptive characteristics of each group.

# Get descriptive characteristics of one of the groups
group_rules("b", utaut_overfit$dtree)
#> BI < -0.53
#> -2.45 <= FC < -0.93
#> HAB < 1.00
#> -1.06 <= PE

And finally, we can examine unstable paths of any of our groups.

unstable <- unstable_params(analysis = utaut_overfit)
#> Identifying Unstable Paths

unstable$group_diffs$b
#> $group
#> [1] 12 71 99
#> 
#> $param_diffs
#> $param_diffs$path_coef
#>        PE EE SI FC HM PV HAB Exp Age Gender           BI
#> PE      0  0  0  0  0  0   0   0   0      0 -0.018426546
#> EE      0  0  0  0  0  0   0   0   0      0 -0.005368748
#> SI      0  0  0  0  0  0   0   0   0      0  0.004796548
#> FC      0  0  0  0  0  0   0   0   0      0  0.032766535
#> HM      0  0  0  0  0  0   0   0   0      0 -0.022661261
#> PV      0  0  0  0  0  0   0   0   0      0  0.033025676
#> HAB     0  0  0  0  0  0   0   0   0      0  0.004836042
#> Exp     0  0  0  0  0  0   0   0   0      0 -0.001911413
#> Age     0  0  0  0  0  0   0   0   0      0  0.010783469
#> Gender  0  0  0  0  0  0   0   0   0      0 -0.009425882
#> BI      0  0  0  0  0  0   0   0   0      0  0.000000000

Upcoming Work

Reporting

  • Create all_groups_* version of group_rules and other related posthoc methods that operate on individual groups
  • Create summary and print functions for COA object (can use all_groups_* functions)
  • Reposition labels on plot_pd()
  • Create group_competes function that reports competes for all rules, not just rule at group root

Refactoring

  • group_rules subroutines can reuse data structures

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.