Skip to content

Instantly share code, notes, and snippets.

@soumyaray
Last active June 28, 2020 02:40
Show Gist options
  • Save soumyaray/a5bc9ad2d39c08f142b05e509b170fdd to your computer and use it in GitHub Desktop.
Save soumyaray/a5bc9ad2d39c08f142b05e509b170fdd to your computer and use it in GitHub Desktop.
Simulating singular matrix error in SEMinR
library(seminr)
comp1_items <- multi_items("IMAG", 1:5)
comp2_items <- multi_items("CUEX", 1:3)
comp3_items <- multi_items("CUSA", 1:3)
mobi_mm <- constructs(
# Three first-order composites
composite("Comp1", comp1_items),
composite("Comp2", comp2_items),
composite("Comp3", comp3_items),
# First-order representation of higher-order composite (repeated indicators)
composite("Comp_1_2", c(comp1_items, comp2_items)),
# Second-order composite of two composites
higher_composite("HOC_1_2", c("Comp1", "Comp2"))
)
# HAPPY: no duplicate constructs
happy_sm_lower <- relationships(
paths(from="Comp3", to="Comp1"),
paths(from="Comp3", to="Comp2")
)
happy_pls_lower <- estimate_pls(mobi, mobi_mm, happy_sm_lower)
summary(happy_pls_lower)
# Path Coefficients:
# Comp1 Comp2
# R^2 0.484 0.266
# AdjR^2 0.482 0.263
# Comp3 0.695 0.516
# SAD: duplicate endogenous constructs
sad_sm_lower <- relationships(
paths(from="Comp3", to="Comp1"),
paths(from="Comp3", to="Comp1")
)
sad_pls_lower <- estimate_pls(mobi, mobi_mm, sad_sm_lower)
# Error: Lapack routine dgesv: system is exactly singular: U[2,2] = 0
# [Traceback]: inner_paths[independant,dependant[i]] = solve(t(construct_scores[,independant]) %*% construct_scores[,independant], t(construct_scores[,independant]) %*% construct_scores[,dependant[i]])
# SAD: duplicate construct in higher-order
sad_sm_higher <- relationships(
paths(from="Comp3", to="Comp1"),
paths(from="Comp3", to="HOC_1_2")
)
sad_pls_higher <- estimate_pls(mobi, mobi_mm, sad_sm_higher)
# Error: Lapack routine dgesv: system is exactly singular: U[2,2] = 0
# [Traceback]: inner_paths[independant,dependant[i]] = solve(t(construct_scores[,independant]) %*% construct_scores[,independant], t(construct_scores[,independant]) %*% construct_scores[,dependant[i]])
# HAPPY: Duplicate items in constructs, but repeated indicators HOC
happy_sm_compcomp <- relationships(
paths(from="Comp3", to="Comp1"),
paths(from="Comp3", to="CompComp")
)
happy_pls_compcomp <- estimate_pls(mobi, mobi_mm, happy_sm_compcomp)
summary(happy_pls_compcomp)
# Path Coefficients:
# Comp1 CompComp
# R^2 0.485 0.519
# AdjR^2 0.482 0.517
# Comp3 0.696 0.720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment