Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Goodness of fit tests in SciPy

I'm new to Python and coming from the R world. I'm trying to fit distributions to sample data using SciPy and having good success. I can make distribution.fit(data) return sane results. What I've been unable to do is create the goodness of fit statistics which I'm used to with the fitdistrplus package in R. Is there a common method for comparing "best fit" from a number of different distributions with SciPy?

I'm looking for something like the Kolmogorov-Smirnov test or Cramer-von Mises or Anderson-darling tests

like image 452
JD Long Avatar asked Jun 29 '12 20:06

JD Long


People also ask

How do you check goodness of fit in Scipy?

If you want to know the "goodness of fit", use the R squared stat. R squared tells you how much of the observed variance in the outcome is explained by the input. Here is an example in python. This returns 0.801 , so 80.1% percent of the variance in y seems to be explained by x.

What is a goodness to fit test?

What is the Chi-square goodness of fit test? The Chi-square goodness of fit test is a statistical hypothesis test used to determine whether a variable is likely to come from a specified distribution or not. It is often used to evaluate whether sample data is representative of the full population.

How do you calculate chi-square goodness of fit in Python?

Note that the p-value corresponds to a Chi-Square value with n-1 degrees of freedom (dof), where n is the number of different categories. In this case, dof = 5-1 = 4. You can use the Chi-Square to P Value Calculator to confirm that the p-value that corresponds to X2 = 4.36 with dof = 4 is 0.35947.

What is chi-square test of goodness of fit?

The chi-square goodness of fit test is a hypothesis test. It allows you to draw conclusions about the distribution of a population based on a sample. Using the chi-square goodness of fit test, you can test whether the goodness of fit is “good enough” to conclude that the population follows the distribution.


2 Answers

See the scipy.stats library: http://docs.scipy.org/doc/scipy/reference/stats.html

It contains K-S and Anderson-Darling, although apparently not Cramer-von Mises.

like image 150
BrenBarn Avatar answered Sep 27 '22 21:09

BrenBarn


There's also statmodels goodness of fit tests.

like image 25
John D. Cook Avatar answered Sep 27 '22 20:09

John D. Cook