Message Boards Message Boards

MultiNonlinearModelFit problem with covariance matrix

I am using the MultiNonlinearModelFit function (https://resources.wolframcloud.com/FunctionRepository/resources/MultiNonlinearModelFit). I've noticed that every time I call the command "CovarianceMatrix", the values on the matrix changes. You can verify that by evaluating the following lines few times:

ClearAll["Global`*"]

(*generating two dataset*)

data = RandomVariate[BinormalDistribution[0.7], {2, 100}];

data[[1, All, 2]] += 1.;

data[[2, All, 2]] += -1.;

(*fit*) 

fit = ResourceFunction["MultiNonlinearModelFit"][
  data, {a x + b1, a x + b2}, {a, b1, b2}, {x}]

(*extracting the covariance matrix*)

covmat= fit["CovarianceMatrix"] // MatrixForm

Do you know why this happen?

Thank you in advance. Edoardo

2 Replies
Posted 3 years ago

With Mathematica 12.3 (Windows 10) it doesn't change with multiple executions such as

covmat= fit["CovarianceMatrix"] // MatrixForm
covmat= fit["CovarianceMatrix"] // MatrixForm
covmat= fit["CovarianceMatrix"] // MatrixForm

But it will change if you re-run all commands (i.e., generating the data again) as the random number seed will change each time.

POSTED BY: Jim Baldwin
Posted 3 years ago

Use SeedRandom if you want reproducible data & results.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract