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

Predicting latent factors #380

Open
AroobIqbal opened this issue Aug 20, 2024 · 1 comment
Open

Predicting latent factors #380

AroobIqbal opened this issue Aug 20, 2024 · 1 comment

Comments

@AroobIqbal
Copy link

I am using lavpredict however I am getting this error:
"Error: lavaan->lav_predict_fy_eta.i():
unknown type: `character' for variable: as1"
I see there is an earlier thread on this. And lionel posted this response. I follow the advice but still get the error. Would really appreciate advice on what to do.

The labelled class is considered to be a temporary class, and the onus is on the user to convert labelled classes to factors before getting into data analysis. In any case, lavaan should not do anything. I am not sure how converting to data frame fixes the issue with inputs containing haven-labelled columns.

Regarding:

lavaan/R/xxx_lavaan.R

Lines 64 to 67 in 290cc70

if(inherits(data, "tbl_df")) {
# a tibble df: convert to data.frame and hope for the best
data <- as.data.frame(data)
}

I recommend doing this for any classes that inherit from data frame. For instance data.table does data-masking among other special interpretation of subsetting. This could introduce scoping issues in your code. Another example, sf data frames maintain a sticky geometry column, which means that the usual invariant length(sf[1:n]) == n is not applicable.

If you convert inputs to a data frame, there is no need to hope for the best because you control exactly the interface you're using.

Originally posted by @lionel- in #163 (comment)

@yrosseel
Copy link
Owner

In 0.6-18, we do convert all objects that inherit from data.frame to a regular data.frame. See
https://github.com/yrosseel/lavaan/blob/6e8866831497b0bf810b02e0e4987b58b9819a0f/R/lav_lavaan_step00_init.R#L106C2-L108C34

Are you using 0.6-18? If so, could you please provide a minimal reprex?

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