Message Boards Message Boards

0
|
11230 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to get chi-squared and p-Value in NonlinearModelFit function?

Posted 10 years ago
Dear colleagues
I am trying to use Mathematica for statistic analysis. Concrete question is: what is the option of NonlinearModelFit function which gives chi^2, p-Value (probability that the fit is true hypothesis)? How "EstimatedVariance" is calculated there (over which formula), if there are nonzero weights?
And one more general question. Unfortunately, NonlinearModelFit fails to produce a fit with three and more parameters in my case. Playing with constraints, seed values for parameters does not give result. Can you advise something here?
Thank you in advance
POSTED BY: Konstantin B.
3 Replies
Does your integral have a closed form? If not, please make sure to use NIntegrate and ?NumericQ appropiately. You want to build a function that takes in parameters and the independant values and outputs the dependant values of the model.  Knowing how to do this requires some background in knowing how to program with Mathematica. Here's a simple example, which makes a model using NIntegrate:

dataset = {{1, 2}, {5, 4}, {7, 6}};
model[parameter1_?NumericQ][x_?NumericQ] :=  NIntegrate[parameter1 t + x, {t, 0, 1}];

NonlinearModelFit[dataset, model[param][x], {param}, x]

If your modeling problem isn't working, try making a simpler example of it and getting that to work first. I'm still not sure what messages you are seeing or what behavior you see when you run NonlinearModelFit.
But i need a probability that the fit itself is true.
 This isn't what is done in statistical modeling for a number of reasons. There's a lot of background that I can't cover here. In many cases it's hard to know what this means.  There's a very important staying statistical modeling "All models are wrong, but some are useful".

You can look at the parameter's confidence intervals and this should be reasonable way to compare how accurate the parameter estimate is for many cases.

http://reference.wolfram.com/mathematica/ref/ConfidenceLevel.html


The pvalue estimate might be useful also. In my experience, what counts acceptably accurate can depend on your field.
POSTED BY: Sean Clarke
Posted 10 years ago
Thank you very much for reply.

I suspected that chi-squared and p-Value are to be calculated separately from procedure of fitting with NonlinearModelFit function, and none of its available options can cover this.

My situation seems to be quite common in the tasks of data analysis.

I have an experimental dataset (with their errors), and theoretical function to fit them. I need to find the fitting parameters of theoretical function and a quality of this fit (what is the probability that this fit is true).

I use:
NonlinearModelFit[Data, {Function[a,b,x], a_min<a<a_max, b_min<b<1-a_max}, {{a,a_seed},{b,b_seed}}, x, Weights->1/Errors^2]

“Function” is given by some integral. (In general, there are more fitting parameters, but they break fitting.)

It seemed to me, that "EstimatedVariance” coincides with chi^2 value, but it does not look so.

The p-values, which are available in “ParameterTable", relate, as i understand, to probability of fitting parameters confidence interval, but not to a quality of the fit itself.
But i need a probability that the fit itself is true.

I would be grateful for any clarifications of these points.
POSTED BY: Konstantin B.
NonlinearModelFit returns a FittedModel expression. FittedModel expressions can be queried for these sorts of things when it is reasonable to ask for them. You can see what things are available in the documentation for NonlinearModelFit under "Details and Options". Anything that's not listed basically has to be programmed. Note that p-values can come from a number of tests and that a p-value is a bit different than a probability that the fit is correct. From what test do you want a p-value? If you don't know, there's "ParameterPValues", which offers "p-values for parameter z-statistics".

There are different possible variance estimators. See the documentation on VarianceEstimatorFunction which explains how these are made.

There are many different reasons why it may be hard to find a fit to a given model. It's hard to know without more information. Are there error/warning messages? Can you provide a small example?
POSTED BY: Sean Clarke
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