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

error in pls_predict with HCO #222

Open robertogilsaura opened 3 years ago

robertogilsaura commented 3 years ago

Hi, I'm trying to get predictions in seminR model using predict_pls with HCO, but i get an error relate with parallel package:

Error in parallel::stopCluster(cl) : object 'cl' not found

I assume that the error is related to the HCO (other simple models run properly), but I cannot understand what the problem is, since I do not relate the message error to the analysis performed. In my model object build with estimate_pls() all manifest variables are present, including the data created in the HCO. This is my project.

# ======================================
# Create measurement model
# ======================================
mm <- constructs (
     composite ("ICT", multi_items ("ICT", c (1: 4))),
     composite ("SUSA", multi_items ("SUS", c (1: 8))),
     composite ("SUSB", multi_items ("SUS", c (10:12))),
     composite ("SUSC", multi_items ("SUS", c (13:15))),
     higher_composite ("SUS", dimensions = c ("SUSA", "SUSB", "SUSC"), method = two_stage),
     composite ("SUS", multi_items ("SUS", c (1: 8,10: 15))),
     composite ("BEQ", multi_items ("BEQ", c (7:10))),
     composite ("SST", multi_items ("SST", c (1: 3))),
     composite ("EST", multi_items ("EST", c (1: 3))))
# ======================================
# Create structural model
# ======================================
sm <- relationships (
     paths (from = c ("ICT"), to = c ("BEQ")),
     paths (from = c ("SUS"), to = c ("BEQ")),
     paths (from = c ("BEQ"), to = c ("SST")),
     paths (from = c ("SST"), to = c ("EST"))
     )
#...
model <- estimate_pls(data = df,
                                      measurement_model = mm,
                                      structural_model  = sm,
                                      inner_weights = path_weighting,
                                      missing = mean_replacement,
                                      missing_value = NA)
#...
predict_simple_model <- predict_pls(model = model,technique = predict_DA, noFolds = 10,reps = 10)

Any ideas on where the problem can be located?

Thanks in advance!!! @robertogilsaura

NicholasDanks commented 3 years ago

Dear @robertogilsaura

Thank you for your interest in SEMinR! First, my apologies for the delayed response-this has been a busy year. I am sorry that you have encountered this bug. Unfortunately, there is no accepted or documented method for generating predictions from a PLS model that includes higher-order-composites (or non-linear terms). On the face of it, it seems simple to conduct the prediction, however, under the hood there are a lot of considerations. Since we have no published article describing the process more fully, we are not willing to implement this feature. The good news is that we have some proposed solutions for the method that we hope to get published in the upcoming year.

In the interim, I would recommend that you include the HOC for the explanatory model. Then for the predictive model, you exclude the HOC, and simply have the model where the second order constructs (SUSA, SUSB, SUSC) are directly related to the outcome (BEQ) of the higher order construct.

Alternatively, you are also welcome to share your data with me (via email) and I am also willing to manually code the predictions including the HOC model. This way you can get the predictions from the model including the HOC (I am fairly sure there will be little or no predictive improvement of the model excluding the HOC over including the HOC as the hOC is more an explanatory tool than a predictive tool).

I look forward to hearing from you. Happy modeling!

Nick

robertogilsaura commented 3 years ago

Hi Mr Danks.

Very grateful for his response. I share with you how busy and difficult this year was for everyone.

I will use the HCO score values for the prediction.

You really do a magnificent job that from the scientific community we never appreciate enough. I look forward to those news.

Thank you.

soumyaray commented 3 years ago

Thanks @robertogilsaura for bringing this to our attention and thanks @NicholasDanks for attending to it. I too await to see how we will handle HOCs and non-linear terms in future :)

I will reopen this issue so that it stays on our list of things to do.

NicholasDanks commented 2 years ago

@robertogilsaura I haven't solved this problem yet. But inspired by this issue, I have added a warning to let users know that predict functions don't work on HOC or moderated models.

robertogilsaura commented 2 years ago

Hi @NicholasDanks; great job with package. Very grateful with inclusion of a warning. I'm working with predict_pls using simple_model$data where I found values for HOC estimation.

Regards ...