brandmaier/semtree

varimp() fails for lavaan forest

cjvanlissa opened this issue · 2 comments

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

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 (78cf150). However, running variable importance with these warnings likely distorts the results. So, I would rather try to prune back the tree a little.

Fixed by 2db16b8