I'm trying to fit some data with lsqnonlin. I have 57 arguments in the objective function, and 1708 data entries. I've run the lsqnonlin and got the results:
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(@model.objective_hdl,x0,lb,ub,options,model);
Which I then fed to nlparci:
ci = nlparci(x,residual,'jacobian',jacobian);
The residual array is 1708x1 and the jacobian is 1708x57 sparse matrix. Both look legit and do not have any Infs or NaNs. I'm also plotting the x so I know it's fine too.
The ci however is a 57x2 matrix, with the first 29 rows filled with NaNs.
Thanks in advance to anyone who can help,
Best regards,
Slava
After further investigation I found that the problem arises in nlparci during matrix inversion:
% Calculate covariance matrix
[~,R] = qr(J,0);
Rinv = R\eye(size(R)); %<===== Problem is here, R is singular to working precision - inversion produces bad results
diag_info = sum(Rinv.*Rinv,2);
I noticed that many of the jacobian (J) entries contain zeroes. Does it mean that the arguments are not "significant" for the fit - i.e. that a change in those arguments does not produce any effect on the quality of the fit, and thus the model I'm using is, perhaps, not the best one for the task, and could be significantly simplified? Is this the only solution to this problem, or are there some guidelines for "normalizing" the jacobian?
Thanks.