sem-in-r / seminr

Natural feeling domain-specific language for building structural equation models in R for estimation by covariance-based methods (like LISREL/Lavaan) or partial least squares (like SmartPLS)
58 stars 19 forks source link

Missing Value Error when estimating the model #336

Closed PrabathRanatunga closed 10 months ago

PrabathRanatunga commented 10 months ago

This is my code and I receive the following error when run the code. My analysis used higher-order constructs. Please help me.

install.packages("seminr") library(seminr)

Loading CSV file

EML_JS_OC_data <- read.csv(file = "Tepuli Data Sheet 2.csv", header = TRUE, sep = ",") head(EL_JS_OC_data)

Create measurement model, Emotional Labour, Job Satisfaction, Organizational commitment

EML_JS_OC_mm <- constructs( composite("EML1", multiitems("EML1", 1:16)), composite("EML2", multiitems("EML2", 1:9)), composite("EML3", multiitems("EML3", 1:3)), composite("EML4", multiitems("EML4", 1:3)), higher_composite("EML", c("EML1","EML2", "EML3", "EML4"), method = "two stage"),

composite("JS1", multiitems("JS1", 1:4)), composite("JS2", multiitems("JS2", 1:4)), composite("JS3", multiitems("JS3", 1:4)), composite("JS4", multiitems("JS4", 1:4)), composite("JS5", multiitems("JS5", 1:4)), composite("JS6", multiitems("JS6", 1:4)), composite("JS7", multiitems("JS7", 1:4)), composite("JS8", multiitems("JS8", 1:4)), composite("JS9", multiitems("JS9", 1:4)), higher_composite("JS", c("JS1","JS2", "JS3", "JS4", "JS5", "JS6", "JS7", "JS8", "JS9"), method = "two stage"),

composite("OC1", multiitems("OC1", 1:8)), composite("OC2", multiitems("OC2", 1:8)), composite("OC3", multiitems("OC3", 1:8)) ) higher_composite("OC", c("OC1","OC2", "OC3" ), method = "two stage")))

Create structural model

EML_JS_OC_sm <- relationships( paths(from = c("EML"), to = c("JS")), paths(from = c("EML"), to = c("OC")), paths(from = c("JS"), to = c("OC")))

Estimate the Model

EML_JS_OC_PLS_model <- estimate_pls(data = EML_JS_OC_data, measurement_model = EML_JS_OC_mm, structural_model = EML_JS_OC_sm, inner_weights = path_weighting, missing = mean_replacement, missing_value = "-99")

Generating the seminr model Generating the seminr model All 355 observations are valid. Error in if ((mmMatrix[mmMatrix[, "construct"] == construct, "type"][1] == : missing value where TRUE/FALSE needed

soumyaray commented 10 months ago

Greetings, please try method = two_stage instead of method = "two stage" and see if that resolves some issues?

PrabathRanatunga commented 10 months ago

Thanks for the prompt reply. I tried method = two_stage. However, it doesn't work and the following error comes.

Error: unexpected symbol in: " composite("EML4", multiitems("EML4", 1:3)), higher_composite("EML", c("EML1","EML2", "EML3", "EML4"), method = two stage"

soumyaray commented 10 months ago

greetings, please see my instructions again: it should be method = two_stage. Note the underscore between the words two and stage.

PrabathRanatunga commented 10 months ago

I am very sorry. It is my mistake. Now it is working. Thanks again for your helping.

soumyaray commented 10 months ago

Not at all – typos are a part of programming. Best of luck!