cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

4-Participant

## Nonlinear least squares with minerr

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.

1 ACCEPTED SOLUTION

Accepted Solutions
24-Ruby V
(To:Werner_E)

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

8 REPLIES 8
12-Amethyst
(To:tburch)

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.

4-Participant
(To:FDS)
?

?

?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.

24-Ruby V
(To:tburch)

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

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:

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)).

24-Ruby V
(To:Werner_E)

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

4-Participant
(To:Werner_E)
?Thanks. I haven't tried that yet. Do you think it's a better algorithm?

24-Ruby V
(To:tburch)

@tburch wrote:
?Thanks. I haven't tried that yet. Do you think it's a better algorithm?

I don't think so. But using a solve block with minerr can offer additional possibilities to introduce further conditions and weighting them.

4-Participant
(To:Werner_E)
?Thanks.

4-Participant
(To:tburch)