Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running moderator analysis #325

Open
tomryjo opened this issue Mar 14, 2023 · 2 comments
Open

Error when running moderator analysis #325

tomryjo opened this issue Mar 14, 2023 · 2 comments

Comments

@tomryjo
Copy link

tomryjo commented Mar 14, 2023

I got this error message when running moderator analysis:

Error in first_stage$construct_scores[, moderator] :
subscript out of bounds

This is the code I use:

Define measurements with familiar terms: reflective, composite, multi-item constructs, etc.

mobi_mm <- constructs(
composite("Overconfidence", multi_items("v1.", 1:7)),
composite("Illusion of control bias", multi_items("v2.", 1:4)),
composite("Self-attribution bias", multi_items("v3.", 1:9)),
composite("Herding behavior", multi_items("v4.", 1:5)),
composite("Information availability", multi_items("v5.", 1:5)),
composite("Financial literacy", multi_items("v6.", 1:6)),
interaction_term(iv= "Illusion of control bias", moderator = "Information availability",method = two_stage),
interaction_term(iv= "Self-attribution bias", moderator = "Information availability",method = two_stage),
interaction_term(iv= "Overconfidence", moderator = "Financial literacy",method = two_stage)
)

Create structural model

overriding_effects_sm <- relationships(
paths(from = c("Overconfidence","OverconfidenceFinancial literacy"), to = "Herding behavior"),
paths(from = c("Illusion of control bias","Self-attribution bias","Information availability","Illusion of control bias
Information availability","Self-attribution bias*Information availability"), to = "Herding behavior")
)

Plot the model

plot(overriding_effects_sm)

Models with reflective constructs are automatically estimated using PLSc

pls_model <- estimate_pls(data = my_data, mobi_mm, overriding_effects_sm
, missing = mean_replacement
, missing_value = "-99"
)
model_summary <- summary(pls_model)
model_summary


Please help as the deadline is coming! Many thanks.

@NicholasDanks
Copy link
Collaborator

Dear @tomryjo

thanks for sharing your code. I simulated data by munging the mobi dataset and renaming the columns. Ignore this part. But the subsequent code works. Essentially you forgot to use the "*" in the interaction term names. I also abbreviated the names for sanity.

# ignore the following 
my_data <- cbind(mobi,mobi[,1:12])
colnames(my_data) <- c(multi_items("v1.", 1:7),
                    multi_items("v2.", 1:4),
                    multi_items("v3.", 1:9),
                    multi_items("v4.", 1:5),
                    multi_items("v5.", 1:5),
                    multi_items("v6.", 1:6))
# ignore to here

mobi_mm <- constructs(
  composite("OC", multi_items("v1.", 1:7)),
  composite("ICB", multi_items("v2.", 1:4)),
  composite("SAB", multi_items("v3.", 1:9)),
  composite("HB", multi_items("v4.", 1:5)),
  composite("IA", multi_items("v5.", 1:5)),
  composite("FL", multi_items("v6.", 1:6)),
  interaction_term(iv= "ICB", moderator = "IA",method = two_stage),
  interaction_term(iv= "SAB", moderator = "IA",method = two_stage),
  interaction_term(iv= "OC", moderator = "FL",method = two_stage)
)

overriding_effects_sm <- relationships(
  paths(from = c("OC","OC*FL", "FL"), to = "HB"),
  paths(from = c("ICB","SAB","IA","ICB*IA","SAB*IA"), to = "HB")
)

plot(overriding_effects_sm)

pls_model <- estimate_pls(data = my_data, 
                          mobi_mm, 
                          overriding_effects_sm, 
                          missing = mean_replacement, 
                          missing_value = "-99"
)
model_summary <- summary(pls_model)
model_summary

@NicholasDanks
Copy link
Collaborator

Please close the issue if resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants