Lorenzian and gaussian pdf-function fitting with Matlabs nlinfit, confidence interval

In summary, the conversation discusses the use of Matlab's nlinfit function to fit data to both Gaussian and Lorentzian distributions. The speaker shares their experience with using the function and notes that the Lorentzian fit produces smaller errors for the width, even though the data appears to be better fit by a Gaussian curve. Possible explanations for this discrepancy are offered, such as the algorithm used by nlinfit being better suited for Lorentzian distributions or the data being too complex for either distribution to accurately capture. Suggestions are made to try out other curve fitting algorithms for potentially different results.
  • #1
deccard
30
0
I have data that I want to fit to both Gaussian and Lorentzian (Cauchy) distribution. I have been using Matlab's nlinfit as follows:

gaus = @(p,xdata) (p(1)/(sqrt(2*pi*p(2)))*exp(-(xdata-p(3)).^2/(2*p(2)))+min).*weights;
[g_pfit,g_residual,g_J]=nlinfit(data(:,1), data(:,2).*weights, gaus, [4030 2 -5]);
g_ci=nlparci(g_pfit,g_residual,'jacobian',J,'alpha',0.317);

loren = @(p,xdata) p(1)./(pi*p(2)*(1+((xdata-p(3))./p(2)).^2))+p(4);
[l_pfit,l_residual,l_J]=nlinfit(data(:,1), data(:,2), loren, [10030 0.5 -5 4]);
l_ci=nlparci(l_pfit,l_residual,'jacobian',l_J,'alpha',0.317);

The strange thing, however, is that my data is more like Gaussian-shaped and Gaussian curve, is by eye way more better fit. Still I get smaller errors for the width of Lorentzian fit than Gaussian (using the nlparci function).

Why would I get smaller errors for the width of the Lorentzian curve than for the width of the Gaussian curve, which is a better fit?

deccard
 
Physics news on Phys.org
  • #2
1: That's an interesting question! It could be that the curve fitting algorithms used by Matlab's nlinfit function are better for Lorentzian distributions than for Gaussian distributions, so it's possible that you're getting more accurate results with the Lorentzian fit. It could also be that the data is more complex than either of the two distributions can capture, so the algorithm is getting a better result with the Lorentzian fit. You might want to try out some other curve fitting algorithms to see if you can get different results.
 
  • #3
,

Thank you for sharing your method of fitting data to both Gaussian and Lorenzian distributions using Matlab's nlinfit function. It is not uncommon to use this approach when dealing with data that may have a mixture of both distributions present. However, it is important to understand the limitations of this approach and the potential reasons for the differences in the errors for the width of the two curves.

Firstly, it is important to note that the Gaussian and Lorenzian distributions have different shapes and therefore may not be equally suitable for fitting a given dataset. The Gaussian distribution is typically used for data that follows a normal distribution, while the Lorenzian distribution is often used for data that has a heavy-tailed or skewed distribution. Therefore, it is possible that your data may not be a perfect fit for either distribution, which could explain why the Gaussian curve appears to fit better by eye.

Secondly, the nlparci function calculates the confidence interval for the parameters based on the assumption that the model is linear in the parameters. This means that the confidence interval may not accurately reflect the uncertainty in the parameters for non-linear models such as the Gaussian and Lorenzian distributions. Therefore, the smaller errors for the width of the Lorenzian curve may not necessarily indicate a better fit, but rather a limitation of the method used to calculate the confidence interval.

In summary, it is important to carefully consider the shape of your data and the assumptions made when fitting it to a particular distribution. It is also worth exploring alternative methods for calculating the confidence interval for non-linear models to ensure more accurate results.
 

Related to Lorenzian and gaussian pdf-function fitting with Matlabs nlinfit, confidence interval

1. What is the difference between Lorenzian and Gaussian pdf-function?

The Lorenzian and Gaussian pdf-functions are two different mathematical models used to fit data points in a distribution. The Lorenzian function has a wider peak and heavier tails compared to the Gaussian function which has a narrower peak and lighter tails.

2. How do I use Matlabs nlinfit to fit a Lorenzian or Gaussian pdf-function?

To fit a Lorenzian or Gaussian pdf-function using Matlabs nlinfit, you need to first define your data points and then specify the model you want to use. Then, you can use the nlinfit function with your data and model to find the best fitting parameters.

3. What is a confidence interval in the context of Lorenzian and Gaussian pdf-function fitting?

A confidence interval is a range of values that is likely to contain the true value of a parameter. In Lorenzian and Gaussian pdf-function fitting, the confidence interval is used to determine the uncertainty in the estimated parameters and to assess the goodness of fit of the model.

4. How do I interpret the confidence interval in Lorenzian and Gaussian pdf-function fitting?

In Lorenzian and Gaussian pdf-function fitting, the confidence interval can be interpreted as a measure of the uncertainty in the estimated parameters. A narrower confidence interval indicates a more precise estimate of the parameter, while a wider confidence interval suggests a higher degree of uncertainty in the estimation.

5. Can I use nlinfit to fit other types of pdf-functions?

Yes, nlinfit can be used to fit a variety of pdf-functions, not just Lorenzian and Gaussian. However, the choice of the appropriate model will depend on the nature of the data and the underlying distribution. It is important to understand the characteristics of different pdf-functions and choose the most suitable one for your data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
11K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
15K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
4K
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
6K
Back
Top