knickodem / kfa

k-fold cross validation for factor analysis
GNU General Public License v3.0
7 stars 1 forks source link

`missing = "pairwise"` does not take effect #14

Open psychelzh opened 2 months ago

psychelzh commented 2 months ago

For example,

dat <- matrix(rnorm(1000), ncol = 10)
dat[sample(length(dat), 100)] <- NA
x <- kfa::kfa(dat, missing = "pairwise")
#> Power analysis indicates the sample size is too small for k-fold cross validation.
#>     Adjust assumptions or manually create a single holdout sample.
#> [1] "Using 19 cores for parallelization."
#> [1] "Finished EFAs. Starting CFAs"
lavaan::lavInspect(x$cfas[[1]][[1]], "options")$missing
#> [1] "listwise"

Created on 2024-04-14 with reprex v2.1.0

psychelzh commented 2 months ago

Based on these lines:

https://github.com/knickodem/kfa/blob/a91d785fe25d2fe386a679287b485be52a8dfa9e/R/k_cfa.R#L16-L21

and these lines:

https://github.com/knickodem/kfa/blob/a91d785fe25d2fe386a679287b485be52a8dfa9e/R/k_cfa.R#L31-L41

I understand it now. pairwise is used in sample_stats(), from which the statistics are calculated. And these statistics are then fed to cfa() and that, probably, lavaan will ignore the missing parameter then. Correct me in case I am wrong.

knickodem commented 2 months ago

You are correct. Nonetheless, I am going to keep this open as a reminder to add documentation and testing regarding this point.