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

fix #333: Cross-Validation fails when using a tibble #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jhorzek
Copy link

@jhorzek jhorzek commented May 30, 2024

predict_pls uses a matrix with variable names to subset the data set. This works with data.frames, but not with tibbles, which results in the error reported in issue #333. This fix addresses the issue by first casting the matrix to a vector when subsetting the data.

Example:

library(seminr)
library(tibble)
mobi_mm <- constructs(
  composite("Image",        multi_items("IMAG", 1:5)),
  composite("Expectation",  multi_items("CUEX", 1:3)),
  composite("Value",        multi_items("PERV", 1:2)),
  composite("Satisfaction", multi_items("CUSA", 1:3))
)

mobi_sm <- relationships(
  paths(to = "Satisfaction",
        from = c("Image", "Expectation", "Value"))
)

mobi_pls <- estimate_pls(mobi, mobi_mm, mobi_sm)
cross_validated_predictions <- predict_pls(model = mobi_pls,
                                           technique = predict_DA,
                                           noFolds = 10,
                                           cores = NULL)
# The following fails in the current version of seminr:
mobi_pls <- estimate_pls(tibble::as_tibble(mobi), mobi_mm, mobi_sm)
cross_validated_predictions_tibble <- predict_pls(model = mobi_pls,
                                                  technique = predict_DA,
                                                  noFolds = 10,
                                                  cores = NULL)

…ble with a matrix (endogenous_items) fails. The fix casts the matrix to a vector when subsetting the data.
@jhorzek jhorzek requested a review from soumyaray as a code owner May 30, 2024 11:00
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

Successfully merging this pull request may close these issues.

None yet

1 participant