Message Boards Message Boards

Rationalize NonlinearModelFit

As a physicist, I cringe when I see errors with so many significant figures.

data

I usually fit my data and use it as input for another simulation (in another program). I could interpolate the result, but this leads to bad derivatives. I could simply fit it and use the fit result, but it has so many significant figures and this makes the final expression barely readable...

One approach I found interesting it is to rationalize the parameters give the given error. This leads to nicer looking expressions. The code is as follows:

RationalizeModel[model_FittedModel, n_: 2] := Thread[
  model["BestFitParameters"][[All,1]] -> (Rationalize[#1, #2/n] & @@@ model["ParameterTableEntries"][[All, {1, 2}]])]

Usage would be:

data = Table[{x, 1/4 Cos[2/3 x]} + RandomReal[{-1, 1}/50, 2], {x, 0, 2 Pi, 2 Pi/100}];
model = NonlinearModelFit[data, a Cos[b x] + c, {a, b, c}, x, Method -> NMinimize]
model["ParameterTable"]
A = RationalizeModel[model]
B = model["BestFitParameters"]
A[[All, 2]] - B[[All, 2]] (* Errror *)

res

POSTED BY: Thales Fernandes
Posted 7 years ago

I don't see a question so I'm assuming you're inviting discussion.

As a statistician I would agree that many times too many less than significant digits are included in summary tables. I wouldn't, however, do any rounding if those numbers were going to go into a further analysis. Nor do I think that showing the results as ratios of rational numbers helps with interpretation. (How would one get an appropriate assessment of 11/7 vs. 143/95 ?)

I also think that there's more to how one rounds than what is intrinsically in the numbers. When rounding (for a display in a summary table) I generally use a two-step rule. First I look at the standard error of the estimate and keep either 3 or 4 significant digits for that value and also keep the corresponding significant digits for the estimator. Then subject matter knowledge is applied to potentially reduce the number of digits. (When there is no consensus about subject matter knowledge, then I'd let the standard error rule apply.)

For example, maybe for the estimate of a above, it is known that any value between 0.2 and 0.3 is in practice the same. In that case I would use at most 2 significant digits no matter if the standard error might warrant many more digits.

In short, I agree that some thinking needs to occur before rounding.

POSTED BY: Jim Baldwin
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