# Fitting normal distribution to the data

I have been given a set of data points. How can I find the best fit of the form $$\frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(x-\mu)^2}{\sigma^2}}?$$ Even better if Sage can do it. And how can I approximate how good the fit is?

-
Is this homework? – Simon Hayward Nov 3 '12 at 10:42
At least for me it is not a homework. Another person asked me that. – student Nov 3 '12 at 10:46
Yes, it is because this seems like a very common homework question, which is absolutely fine, just that it should be marked as such if it is. – Simon Hayward Nov 3 '12 at 11:13
The original author wanted to find a software to do such fitting. I found the question interesting as I had never met such a problem. But now I learned that I can use $\chi^2$-test to measure how good solution is and found that Sage will do the job for me, ask.sagemath.org/question/1164/gauss-distribution-fit . – student Nov 3 '12 at 11:29
You may want to put your comment here where you found the computation as an answer, so that people see it more readily! – kcrisman Jun 26 '14 at 3:12

The best fit is given by finding the sample mean $\overline{x}$ and putting this in place of the population mean $\mu$ in the distribution function. Then you find the sample variance $\hat{s}^2$ and substitute for $\sigma^2$ in the distribution function.

You can then use the $\chi^2$ goodness of fit test to determine whether the fit is a good one or not.

I wouldn't know about doing this in Sage, although there is a tutorial here:-

http://www.sagemath.org/doc/reference/sage/gsl/probability_distribution.html

Some info on goodness of fit with link to further resources is on wikipedia:-

https://en.wikipedia.org/wiki/Goodness_of_fit

Shout if anything is unclear.

-

I think the good point to start is Normality test where you can find few approaches to test the data Graphical methods, Back-of-the-envelope test, Frequentist testsBayesian tests.

I assume that Sage should have package with Shapiro-Wilk Test for Normality.

-