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

Error in factanal(covmat = Cov$Omega, factors = Cov$nF) : unable to optimize from this starting value #73

Open
igorkf opened this issue Jul 20, 2023 · 2 comments

Comments

@igorkf
Copy link

igorkf commented Jul 20, 2023

Hi, thanks for the BGLR package!

I'm trying to fit an FA1 model, but sometimes I get this error:

Checking variance co-variance matrix K  for linear term 1
Ok
Setting linear term 1
MSx=0.782358413511471
FA covariance matrix
df0 set to 23 for all the traits
S0 was set to: 
       DEH1        GAH1        GAH2        GEH1        IAH1        INH1        MIH1        MNH1        NCH1        NEH1        NEH2        NEH3        NYH2        NYH3        NYS1        SCH1        TXH1        TXH2        TXH3 
  7.9556863  20.2783135 173.7748939  43.4470011  56.2167504   3.7032637   6.7851079  15.6662375   5.6775808 101.9856404   8.3571794  15.3495887  47.5418310   1.9690249  51.6612751  58.9084196   0.6233221  17.9751277  19.7048923 
       WIH1        WIH2        WIH3 
 98.1848348  20.2203369   0.2596944 
var was set to 100
Error in factanal(covmat = Cov$Omega, factors = Cov$nF) : 
  unable to optimize from this starting value

Curiously, if I try to run a couple of times, the model works, so I suppose it could be to a random initialization.

After looking for this error, I saw this post in StackOverflow:
https://stackoverflow.com/questions/41146141/error-in-factor-analysis-starting-values

Does it make sense to increase the number of starting values or give us the option to change the lower bound?
The documentation of factanal says nstart = 1 and lower = 0.005.

Thanks!

@igorkf
Copy link
Author

igorkf commented Jul 20, 2023

To overcome this problem I did a try-catch approach to fit the model until it works:

fit_model <- function() {
  mod <- Multitrait(...)  # your arguments here
  return(mod)
}

run <- function() {
  mod <- T
  while (is.list(mod) == F) {
    mod <- tryCatch({fit_model()}, error = function(e) { return(TRUE) })
  }
  return(mod)
}

set.seed(2023)
mod <- run()

Seems overkill but it works in the first 2 or 3 tries.

@perpdgo
Copy link
Collaborator

perpdgo commented Jul 21, 2023 via email

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