brandmaier / semtree

Recursive Partitioning for Structural Equation Models
https://brandmaier.github.io/semtree/
GNU General Public License v3.0
13 stars 11 forks source link

varimp() fails for lavaan forest #38

Closed cjvanlissa closed 2 years ago

cjvanlissa commented 2 years ago

The error below suggests that error catching is necessary, as sometimes the number of cases in terminal nodes is too low to compute the covariance matrix. This even happens though

> controls$semtree.control$min.bucket
[1] 10
> vim <- semtree::varimp(res_rf)
Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge.eps, x.idx = x.idx[[g]],  : 
  lavaan ERROR: sample covariance matrix is not positive-definite
In addition: Warning message:
In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: small number of observations (nobs < nvar)
  nobs = 3 nvar = 5
brandmaier commented 2 years ago

The current implementation of the score statistic ignores min.bucket but we are working on this. As an intermediate (not optimal) solution, you could prune the trees from all leafs that have a too small sample size.

I just uploaded a fix that wraps the likelihood evaluation in lavaan models and catches errors in the likelihood evaluation (https://github.com/brandmaier/semtree/commit/78cf150c23424a5ae94c659d639ea51660fe51ec). However, running variable importance with these warnings likely distorts the results. So, I would rather try to prune back the tree a little.

brandmaier commented 2 years ago

Fixed by https://github.com/brandmaier/semtree/commit/2db16b8ea91884146ddff732c9b2bd2dbcb13d16