Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I was doing some fitting with Mathematica7 using NonlinearModelFit. It's quite long the program to do the fit and that's why I am not displaying here ...

It goes ok, and I can get the fit parameters as well as the covariance matrix

In[81]:= {Subscript[a, 0], Subscript[a, 1]}/.fitCCBA34["BestFitParameters"]

In[78]:= fitCCBA34["CovarianceMatrix"]

When testing it is Symmetric, it goes ok, as should be by construction of the matrix:

In[80]:= SymmetricMatrixQ[b] 
Out[80]= True

However, it turns out, that, when trying to get some Multinormal distribution of the parameters, it complains about the matrix which is non-symmetric ...

In[84]:= MultinormalDistribution[{Subscript[a, 0], Subscript[a, 
   1]} /. fitCCBA34[
   "BestFitParameters"], {{fitCCBA34["CovarianceMatrix"][[1, 1]], 
   fitCCBA34["CovarianceMatrix"][[1, 2]]}, {fitCCBA34[
     "CovarianceMatrix"][[2, 1]], 
   fitCCBA34["CovarianceMatrix"][[2, 2]]}}]

During evaluation of In[84]:= MultinormalDistribution::cmsym: The covariance matrix must be symmetric. >>

Out[84]= MultinormalDistribution[{0.275723, 
  0.246948}, {{0.00001521, -0.0000535383}, {-0.0000535383, 11.6061}}]

Of course, if now you do copy paste, it works perfectly, so I guess it's some numerical issue, any clue about how to fix this? I need to encode this inside a function rather than copy paste each time ...

Thanks in advance!

share|improve this question
2  
The routines here might be useful to you... –  J. M. Oct 29 '12 at 16:30
1  
It's hard to know without some data. But, wouldn't fitCCBA34["CovarianceMatrix" already return the matrix? I mean, why all the indexing? –  Rojo Oct 29 '12 at 18:41
    
@Pablo Please check that your matrix is definite positive. The one above in your example is. –  chris Oct 30 '12 at 8:51
1  
@J.M. Thanks for your suggestion, I freaked out doing some similar things not working, but finaly just taking (fitCCBA34["CovarianceMatrix"] + Transpose[fitCCBA34["CovarianceMatrix"]])/2 solved the problem without spoiling precission Thanks a lot! –  pablo Oct 30 '12 at 14:25
1  
@chris Yes, I am, is just that mathematica was complaining about symmetric only .. Indeed sometimes complains about non-singularity but keeps on working ... the point is that sometimes the errors as well as the coefficients of the fit are quite small, then the determinant is too small ... Ir seems to me like this random distribution has some limited precision or some numerical issue, not pretty sure .. Thanks for the comment ;) –  pablo Oct 30 '12 at 14:42
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.