6
$\begingroup$

I am trying to replicate an example give here of correlated variables (it's similar to a more complex problem I'm working on).

I've included the example data and method for convenience:

data = {{1.521, -0.171}, {2.012, -0.169}, {2.512, -0.166}, {3.003, -0.159}, {3.507, -0.164}, {3.999, -0.165}, {4.513, -0.156}, {5.002, -0.157}, {5.503, -0.159}, {6.010, -0.161}, {6.511, -0.160}};
fit = LinearModelFit[data, \[Theta], \[Theta]]
{a, b} = fit["BestFitParameters"]
cov = fit["CovarianceMatrix"]

The values returned up to this point agree with those in the linked example page. However when I try this:

AroundReplace[A + 10 B, {A, B} -> VectorAround[{a, b}, cov]]

I get the error: VectorAround: Invalid covariance matrix.

I can't see anything wrong with the covariance matrix (and I verified its values by another method). I am using version 13.1 on Windows 10. Perhaps this is a version related issue, does anyone see the same issue?

$\endgroup$
2
  • $\begingroup$ In V12.3 I get NO error or warning, same result as in the page you linked to. Btw, the link does not work, you introduced an extra space. $\endgroup$
    – user293787
    Jul 17, 2022 at 20:58
  • $\begingroup$ Oops, I'll edit the link $\endgroup$
    – EstabanW
    Jul 17, 2022 at 21:13

1 Answer 1

6
$\begingroup$

Its hard to say if this answers it for you since it seems to be version dependent and my current 12.3 runs error free.

But i had these error often before. It got better in 13.1. for me. Essentially what happens is that the CovarianceMatrix reported back by mathematica is not exactly symmetric. It usually has an asymmetry in the order of a few $MachinePrecision.

If this is the case, then just symmetrize the small deviations away by doing:

covSym=(cov+Transpose[cov])/2;
AroundReplace[A+10 B,{A,B}->VectorAround[{a,b},covSym]]

Btw, if a Mathematica dev reads here: its a shame Mathematica doesn't already offer full Around and VectorAround outputs like fit["BestFitParametersAround"] or something like that.

$\endgroup$
2
  • 1
    $\begingroup$ +1 I get the error with 13.0.1 and symmetrizing cov as you show does the trick. $\endgroup$
    – JimB
    Jul 17, 2022 at 22:04
  • 1
    $\begingroup$ Thanks @Julien that works for me in 13.1 and I agree with your comment about the Around framework being more fully integrated and supported elsewhere in the language $\endgroup$
    – EstabanW
    Jul 18, 2022 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.