Message Boards Message Boards

0
|
6055 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

[?] Perform a nonlinear model fit?

Posted 7 years ago

Dear All, I have some "x, y" data values, and I am trying to use non-linear model fit command to fit Inverse Gaussian Distribution to the data. Yet (perhaps due to the negativity in a square root), I am getting an error. Can you please look at the attached code, and kindly let me know how can I avoid such errors and solve the particular problem? Thanks a lot.

Attachments:
POSTED BY: Alex Token
4 Replies
Posted 7 years ago

Thank you all for your great and detailed replies. Alex.

POSTED BY: Alex Token
Posted 7 years ago

The error message gives a strong hint as to what the problem is: Error message

One can see that NonlinearModelFit tries $\lambda=-1.13888$ but you want to restrict $\lambda$ to be greater than zero.

modelinvgauss = PDF[InverseGaussianDistribution[\[Mu], \[Lambda]]];
invgauss = 
  NonlinearModelFit[
   datanew, {modelinvgauss[x], \[Lambda] > 0}, {{\[Mu], 
     10}, {\[Lambda], 10}}, x];
invgauss["BestFitParameters"]
(* {\[Mu] -> 11.098760475474151, \[Lambda] -> 35.72763989840714} *)
Show[ListPlot[datanew, PlotRange -> {{0, 20}, {0, 0.12}}],
 Plot[invgauss[x], {x, 0, 20}]]

Data and fit

The fit isn't so great. I have to wonder why you want to fit a probability density function using a regression. Usually a probability density function is fit with a random sample from that distribution. If what you have is really a regression and you're just interested in the form of the density function being an inverse Gaussian, then usually translation and/or scaling parameters are usually added.

POSTED BY: Jim Baldwin
Posted 7 years ago

The error message gives a strong hint as to what the problem is: Error message

One can see that NonlinearModelFit tries $\lambda=-1.13888$ but you want to restrict $\lambda$ to be greater than zero.

modelinvgauss = PDF[InverseGaussianDistribution[\[Mu], \[Lambda]]];
invgauss = 
  NonlinearModelFit[
   datanew, {modelinvgauss[x], \[Lambda] > 0}, {{\[Mu], 
     10}, {\[Lambda], 10}}, x];
invgauss["BestFitParameters"]
(* {\[Mu] -> 11.098760475474151, \[Lambda] -> 35.72763989840714} *)
Show[ListPlot[datanew, PlotRange -> {{0, 20}, {0, 0.12}}],
 Plot[invgauss[x], {x, 0, 20}]]

Data and fit

The fit isn't so great. I have to wonder why you want to fit a probability density function using a regression. Usually a probability density function is fit with a random sample from that distribution. If what you have is really a regression and you're just interested in the form of the density function being an inverse Gaussian, then usually translation and/or scaling parameters are usually added.

POSTED BY: Jim Baldwin

This is a small set of data and does not really require an attached notebook. It can all be placed in the question (less clicking and downloading that way).

POSTED BY: Daniel Lichtblau
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