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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Nonlinear least squares with minerr

tburch
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

Additional remark

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

Werner_E_0-1618773074273.png

 

View solution in original post

8 REPLIES 8
FDS
12-Amethyst
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.

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

Werner_E
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

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

 

 

Additional remark

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

Werner_E_0-1618773074273.png

 

tburch
4-Participant
(To:Werner_E)

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

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

tburch
4-Participant
(To:Werner_E)

?Thanks.

tburch
4-Participant
(To:tburch)

Thanks again for your replies. The one with your worksheet was particularly helpful.

Regarding my worksheet attachment, I don't know why you didn't receive it. But I'm not very familiar with the procedures here. Maybe next time.

I note that n is used for plotting but also in calculating mean-squared error. No documentation I can find sheds much light on this. Degrees of freedom presumably equals n - p, where p = the number of parameters to be estimated -- not 100% sure of this. 

 

 

Top Tags