factor_analyzer icon indicating copy to clipboard operation
factor_analyzer copied to clipboard

The optimization routine failed to converge: b'ABNORMAL_TERMINATION_IN_LNSRCH'

Open tonytbui opened this issue 5 years ago • 4 comments

Hi, I ran cfa.fit() on a 33x119 dataset and got this error:

/Users/*/opt/anaconda3/lib/python3.7/site-packages/factor_analyzer/confirmatory_factor_analyzer.py:733: UserWarning: The optimization routine failed to converge: b'ABNORMAL_TERMINATION_IN_LNSRCH'
  'to converge: {}'.format(str(res.message)))
ConfirmatoryFactorAnalyzer(bounds=None, disp=True, impute='median',
                           is_cov_matrix=False, max_iter=200, n_obs=33,
                           specification=<factor_analyzer.confirmatory_factor_analyzer.ModelSpecification object at 0x1a1c2a7410>,
                           tol=None)

Here's the code I used:

model_dict = {"set_shifting": cued_cols+predict_cols,\ #15+15 columns
              "working_memory": DF_cols+nback_cols,\ #15+15 columns
              "attention": flanker_cols+shape_cols,\ #15+15 columns
              "response_inhibition": GNG_cols+stop_cols} #15+14 columns
model_spec = ModelSpecificationParser.parse_model_specification_from_dict(concat_mainDVs, model_dict)
cfa = ConfirmatoryFactorAnalyzer(model_spec, disp=True)
cfa.fit(concat_mainDVs.to_numpy())

tonytbui avatar Feb 19 '20 00:02 tonytbui

It looks like the minimization that is done as part of factor model fitting does not converge for your specific dataset. Can you replicate the issue using R?

desilinguist avatar Feb 19 '20 00:02 desilinguist

It looks like the minimization that is done as part of factor model fitting does not converge for your specific dataset. Can you replicate the issue using R?

Is there a setting that I can change in /Users/*/opt/anaconda3/lib/python3.7/site-packages/factor_analyzer/confirmatory_factor_analyzer.py to work around that minimization?

Also, by "using R," do you mean the Lavaan pakage?

tonytbui avatar Feb 19 '20 00:02 tonytbui

No, there’s no such setting because the minimization is a core part of the model fitting.

Yes, R + lavaan is a reasonable counterpart.

desilinguist avatar Feb 19 '20 00:02 desilinguist

No, there’s no such setting because the minimization is a core part of the model fitting.

Yes, R + lavaan is a reasonable counterpart.

I used lavaan and got somewhat more understandable errors:

Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  : 
  lavaan ERROR: sample covariance matrix is not positive-definite
In addition: Warning messages:
1: In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate
2: In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: small number of observations (nobs < nvar)
  nobs = 33 nvar = 119

Update: I cut down to 2 indicators per factor and 4 factors in total. This avoided the (nobs < nvar) error but showed another error that might corroborate with python's factor_analyzer:

Warning messages:
1: In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate
2: In lav_model_estimate(lavmodel = lavmodel, lavpartable = lavpartable,  :
  lavaan WARNING: the optimizer warns that a solution has NOT been found!

tonytbui avatar Feb 19 '20 01:02 tonytbui