I use the GLM package to compute a simple OLS regression with simulated data inside a loop. In some cases, the simulated data is such that OLS cannot be computed because PosDefException: matrix is not positive definite; Cholesky factorization failed.. That’s completely fine. However, it stops my loop. I would like to (pseudo-code):
if ols_is_feasible
return lm(@formula(y ~ x), df)
else
return Inf
end