15
$\begingroup$

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?

$\endgroup$
3
  • 1
    $\begingroup$ Perhaps I am missing something, but if you already know of a test for testing the fit of the distribution and all you need to know are the values of the theoretical distribution, then you could simply use the maximum likelihood estimators of the parameters of the gamma distribution on your data to get estimates of the parameters. You could then use those estimates to define the theoretical distribution in your test. $\endgroup$
    – David
    Jan 6, 2012 at 0:22
  • $\begingroup$ David, thank you for your answer. The answer is also what i have been thinking about, but i am not sure whether there is some theories which can support this idea, could you answer it for me? $\endgroup$
    – user8363
    Jan 6, 2012 at 10:48
  • $\begingroup$ If you use R, you may be interested in taking a look at the fitdistrplus package, which has facilities for doing this sort of thing. $\endgroup$ Nov 18, 2012 at 14:28

2 Answers 2

10
$\begingroup$

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))

leads to

        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).

$\endgroup$
6
  • 1
    $\begingroup$ (+1) I don’t get well why it is correct to simulate samples under the estimated distribution. I would have think that we needed a prior for the parameters, and sample from all the possible distributions... can you explain a little bit more? $\endgroup$
    – Elvis
    Jan 6, 2012 at 9:38
  • 2
    $\begingroup$ Xi'an, your answer is exactly what i worried about. You mean that "When using the Kolmogorov-Smirnov test with estimated parameters, the distribution of the test statistics under the null depends on the tested distribution". However, we don't know the distribution of X, more precisely, we don't know the parameter of the distribution of X under the null hypothesis, hence the distribution of test statistic,therefore,we use monte carlo. Would you have some other ways of solving it by not using monte carlo to get the P value? Thank you $\endgroup$
    – user8363
    Jan 6, 2012 at 11:05
  • 1
    $\begingroup$ To take into account the fact that "the observed sample comes from another distribution even under the null", wouldn’t it be appropriate to bootstrap the sample, re-estimating the parameters at each replicate? $\endgroup$
    – Elvis
    Jan 6, 2012 at 13:19
  • 1
    $\begingroup$ @Elvis (1): this is classical statistics, not a Bayesian resolution of the goodness of fit problem. For distributions with location-scale parameters, the choice of the parameters used to simulate the simulated samples does not matter. $\endgroup$
    – Xi'an
    Jan 6, 2012 at 14:58
  • 1
    $\begingroup$ @Elvis (2): Again something I just discussed with my students! Bootstrap would help in assessing the behaviour of the Kolmogorov-Smirnov distance under the true distribution of the data, not under the null! The Fisher-Neyman-Pearson principle is that what matters is the behaviour of the Kolmogorov-Smirnov distance under the null, so that it is rejected if the observed distance is too extreme wrt this distribution under the null. $\endgroup$
    – Xi'an
    Jan 6, 2012 at 15:03
6
$\begingroup$

Compute MLEs of the parameters assuming a gamma distribution for your data and compare the theoretical density with the histogram of your data. If the two are very different the gamma dstribution is a poor approximation of your data. For a formal test you could compute, for example, the Kolmogorov-Smirnoff test statistic comparing the best fitting gamma distribution with the empirical distribution and test for significance.

$\endgroup$
8
  • 4
    $\begingroup$ +1, this is a solid answer. However, I would suggest examining a qq-plot against the theoretical gamma rather than a histogram--it will be easier to assess for deviations. $\endgroup$ Jan 6, 2012 at 3:30
  • 1
    $\begingroup$ The problem is that KS test assumes the theoretical distribution to be given beforehand, not estimated from the data. Xi'an (partially) answered to that point... $\endgroup$
    – Elvis
    Jan 6, 2012 at 9:35
  • $\begingroup$ you mean that we firstly use this sample of data to obtain an MLS estimater and use the value of MLS estimater in Gamma distribution, and then compare the data with Gamma distribution(with estimated parameter) by using KS test? $\endgroup$
    – user8363
    Jan 6, 2012 at 10:45
  • $\begingroup$ Elvis, would you please tell me how to solve the problem that when the parameter of the theoretical distribution is unknow and need to be estimated. In this cas, how can one use KS test to get a relatively accurate judgement of the hypothesis, thank you! $\endgroup$
    – user8363
    Jan 6, 2012 at 10:57
  • 1
    $\begingroup$ @Elvis: I do not think the exact derivation is possible in the case of the gamma distribution. The cdf itself is not available in closed form. Further, the fact that the shape parameter is neither scale nor location means that there is a different distribution for each value of the shape parameter... $\endgroup$
    – Xi'an
    Jan 6, 2012 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.