Skip to main content
1-Visitor
April 18, 2021
Solved

Nonlinear least squares with minerr

  • April 18, 2021
  • 1 reply
  • 4218 views

Why is n taken as length(y)-1 rather than simply the length of y? In both Mathcad 15 and Prime 6, sometimes this seems to result in throwing away one observation. E.g., in the Prime 6 example, there are 12 observations, but only 11 show up on the plot.

Best answer by Werner_E

Additional remark

You probably know that you could also use "genfit" to calculate the necessary parameters:

Werner_E_0-1618773074273.png

 

1 reply

13-Aquamarine
April 18, 2021

First it is always better to attach your worksheet. Mathcad starts counting at 0 but you can change this by changing the value for ORIGIN. That is the reason why for length(y)-1. Most likely for the same reason you only see 11 of the 12 points as you most likely started with 1 instead of 0. Hope this helps.

tburch1-VisitorAuthor
1-Visitor
April 18, 2021
?

?

?ORIGIN = 0, but the Prime 6 instruction sheet 'Example: Using minerr for Nonlinear Least Squares Fitting' explicitly states that n = length(y) - 1, and that i = 1..n. I think the problem is with this sheet.


My worksheet, however, gives the correct answer and plots all 12 observations for the Weibull example. See attachment.


Thanks.

25-Diamond I
April 18, 2021

You did not attach a sheet, but you are absolutely right. The example in the Prime help simply is wrong. It should read i:=0..n, if we assume that the default value for ORIGIN (0) is used.

That error is already present in the help for Mathcad 15, too, The example was (like most of the Prime help) copied from there without further check.

A far better approach would be

Werner_E_0-1618771017297.png

as this is independent from the chosen value for ORIGIN.

On the other hand there is no reason for the range i anyway. Its just used for plotting and we can as well plot one vector over the other:

Werner_E_0-1618771669176.png

An additional error is when the example sheet calculated the MSE. They devide by n-2 but it should rather be a division by n+1 (or better by length(y) or by rows(y)).