-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated demo Chap 3 and 8. Cleaned some plot code and corrected some …
…bugs
- Loading branch information
1 parent
24b792d
commit a537201
Showing
12 changed files
with
294 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
### Accompanying Code for the PLS Primer in R Workbook | ||
## Chapter 3: Introduction to SEMinR | ||
|
||
# Load the SEMinR library | ||
library(seminr) | ||
|
||
# Inspect the head of corp_rep_data dataset ---- | ||
head(corp_rep_data) | ||
|
||
# Create measurement model ---- | ||
simple_mm <- constructs( | ||
composite("COMP", multi_items("comp_", 1:3), weights = mode_A), | ||
composite("CSOR", multi_items("csor_", 1:5), weights = mode_B), | ||
composite("ATTR", multi_items("attr_", 1:3), weights = mode_B) | ||
) | ||
|
||
# Create structural model ---- | ||
simple_sm <- relationships( | ||
paths(from = c("CSOR", "ATTR"), to = "COMP") | ||
) | ||
|
||
# Estimate the model | ||
corp_rep_simple_model <- estimate_pls(data = corp_rep_data, | ||
measurement_model = simple_mm, | ||
structural_model = simple_sm, | ||
inner_weights = path_weighting, | ||
missing = mean_replacement, | ||
missing_value = "-99") | ||
|
||
# Estimate the model with default settings | ||
corp_rep_simple_model <- estimate_pls(data = corp_rep_data, | ||
measurement_model = simple_mm, | ||
structural_model = simple_sm) | ||
|
||
# Summarize the model results | ||
summary_simple_corp_rep <- summary(corp_rep_simple_model) | ||
|
||
# Inspect the structural paths | ||
summary_simple_corp_rep$paths | ||
|
||
# Inspect the construct reliability metrics | ||
summary_simple_corp_rep$reliability | ||
|
||
# Bootstrap the model | ||
boot_simple_corp_rep <- bootstrap_model(seminr_model = corp_rep_simple_model, | ||
nboot = 1000, | ||
cores = NULL, | ||
seed = 123) | ||
|
||
# Store the summary of the bootstrapped model | ||
sum_boot_simple_corp_rep <- summary(boot_simple_corp_rep) | ||
|
||
# Inspect the bootstrapped structural paths | ||
sum_boot_simple_corp_rep$bootstrapped_paths | ||
|
||
# Inspect the bootstrapped outer weights | ||
sum_boot_simple_corp_rep$bootstrapped_weights | ||
|
||
# Write the bootstrapped paths object to csv file | ||
write.csv(x = sum_boot_simple_corp_rep$bootstrapped_weights, file = "boot_paths.csv") | ||
|
||
# Generate the plot for exporting | ||
plot(summary_simple_corp_rep$reliability) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
library(seminr) | ||
|
||
# Load the data | ||
corp_rep_data <- corp_rep_data | ||
|
||
# Create measurement model ---- | ||
corp_rep_mm_mod <- constructs( | ||
composite("QUAL", multi_items("qual_", 1:8), weights = mode_B), | ||
composite("PERF", multi_items("perf_", 1:5), weights = mode_B), | ||
composite("CSOR", multi_items("csor_", 1:5), weights = mode_B), | ||
composite("ATTR", multi_items("attr_", 1:3), weights = mode_B), | ||
composite("COMP", multi_items("comp_", 1:3)), | ||
composite("LIKE", multi_items("like_", 1:3)), | ||
composite("CUSA", single_item("cusa")), | ||
composite("SC", multi_items("switch_", 1:4)), | ||
composite("CUSL", multi_items("cusl_", 1:3)), | ||
interaction_term(iv = "CUSA", moderator = "SC", method = two_stage, weights = mode_A) | ||
) | ||
|
||
# Create structural model ---- | ||
corp_rep_sm_mod <- relationships( | ||
paths(from = c("QUAL", "PERF", "CSOR", "ATTR"), to = c("COMP", "LIKE")), | ||
paths(from = c("COMP", "LIKE"), to = c("CUSA", "CUSL")), | ||
paths(from = c("CUSA", "SC", "CUSA*SC"), to = c("CUSL")) | ||
) | ||
|
||
# Estimate the model ---- | ||
corp_rep_pls_model_mod <- estimate_pls(data = corp_rep_data, | ||
measurement_model = corp_rep_mm_mod, | ||
structural_model = corp_rep_sm_mod, | ||
missing = mean_replacement, | ||
missing_value = "-99") | ||
|
||
# Extract the summary | ||
sum_corp_rep_mod <- summary(corp_rep_pls_model_mod) | ||
|
||
# Bootstrap the model ---- | ||
boot_corp_rep_mod <- bootstrap_model(seminr_model = corp_rep_pls_model_mod, | ||
nboot = 10000) | ||
|
||
# Summarize the results of the bootstrap | ||
sum_boot_corp_rep_mod <- summary(boot_corp_rep_mod, | ||
alpha = 0.05) | ||
|
||
# Inspect the bootstrapped structural paths | ||
sum_boot_corp_rep_mod$bootstrapped_paths | ||
|
||
# Simple slope analysis plot | ||
slope_analysis(moderated_model = corp_rep_pls_model_mod, | ||
dv = "CUSL", | ||
moderator = "SC", | ||
iv = "CUSA", | ||
leg_place = "bottomright") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.