# How to test whether a sample of data fits the family of Gamma distribution?

I have a sample of data which was generated from a continuous random variable X. And from the histogram I draw using R, I guess that maybe the distribution of X obeys a certain Gamma distribution. But I do not know the exact parameters of this Gamma distribution.

My question is how to test whether the distribution of X belongs to a family of Gamma distribution? There exists some goodness of fit tests such as Kolmogorov-Smirnov test, Anderson-Darling test, and so on, but one of the restriction when using these tests is that the parameters of the theoretical distribution should be known in advance. Would anyone please tell me how to solve this problem?

I think the question asks for a precise statistical test, not for an histogram comparison. When using the Kolmogorov-Smirnov test with estimated parameters, the distribution of the test statistics under the null depends on the tested distribution, as opposed to the case with no estimated parameter. For instance, using (in R)

``````x <- rnorm(100)
ks.test(x, "pnorm", mean=mean(x), sd=sd(x))
``````

``````        One-sample Kolmogorov-Smirnov test

data:  x
D = 0.0701, p-value = 0.7096
alternative hypothesis: two-sided
``````

while we get

``````> ks.test(x, "pnorm")

One-sample Kolmogorov-Smirnov test

data:  x
D = 0.1294, p-value = 0.07022
alternative hypothesis: two-sided
``````

for the same sample x. The significance level or the p-value thus have to be determined by Monte Carlo simulation under the null, producing the distribution of the Kolmogorov-Smirnov statistics from samples simulated under the estimated distribution (with a slight approximation in the result given that the observed sample comes from another distribution, even under the null).