# Does my data come from a gamma or beta distribution? [closed]

I have data and I want to ascertain whether it is beta or gamma distribution.

Once I know what the distribution is, how do I find out what the parameters are?

• Can you say anything about your data, such as where they come from, or if they're bound by 0 & 1? May 11, 2012 at 16:49
• Why do you think it's either gamma or beta distributed? May 11, 2012 at 18:18
• Have you looked at qqplots of your data against those densities?
– Seth
May 11, 2012 at 18:29
• The Beta distribution is restricted to $(0,1)$ so it should be rather obvious when looking at your data, assuming those are the only two possibilities.... May 12, 2012 at 19:37

You can use the free statistical program R, available at http://www.r-project.org/, to analyze your data. You state that you want to determine how your data are distributed. You guess that your data either conform to a beta or a gamma distribution. You provide no information about your data and do not speculate that it could conform to one of the many other probability distribution types, so I'll just briefly discuss the two distributions that you mention in my answer. I suppose the most logical thing to do first would be to simply plot your data on a histogram or density plot to facilitate visual inspection.

Example 1: Beta Distribution

The beta distribution is a family of continuous probability distributions defined on the interval (0, 1).

You provide no example data in your question, so we will have to make some up for this example. First, let's make some randomly generated dummy data that conform to a beta distribution. We can use the rbeta() command to do this. Type help(rbeta) into R to learn how to use this function.

## Generate 10,000 data points and save them as an object called "temp".
temp <- rbeta(10000, shape1 = 1, shape2 = 1, ncp = 0)


Now, let's double check that our data are bound by zero and one. We can use the summary() command to do this.

## Find maximum and minimum value of the data.
summary(temp)


Now, let's plot the data on a histogram for visual inspection.

## Plot the data on a histogram.
hist(temp)


You could alternatively make a density plot of the data, which for practical purposes is the same thing.

## Make density plot.
plot(density(temp))


I suppose you can take the mean and variance of your data and use them to calculate the parameters of a beta distribution. (Before jumping to this step, you should probably do more descriptive analyses, including looking at the qqplots as suggested by Seth, above). The below function, copied directly from Max's example on this page, should provide estimates of the parameters.

## Calculate mean and variance of the data.
mu <- mean(temp)
var <- var(temp)

## Define function to estimate parameters of a beta distribution.
estBetaParams <- function(mu, var) {
alpha <- ((1 - mu) / var - 1 / mu) * mu ^ 2
beta <- alpha * (1 / mu - 1)
return(params = list(alpha = alpha, beta = beta))
}

## Apply function to your data.
estBetaParams(mu, var)


Example 2: Gamma Distribution

The gamma distribution is a two-parameter family of continuous probability distributions.

First, let's make some randomly generated dummy data that conform to a gamma distribution. We can use the rgamma() command to do this.

## Generate 10,000 data points and save them as an object called "temp".
temp <- rgamma(10000, shape = 1, rate = 10, scale = 1/rate)

## Plot the data on a histogram for visual inspection.
hist(temp)


To estimate the gamma distribution parameters, you can use the MASS library, explained at this website. After installing and loading the MASS library into R, type help(fitdistr) for more information.

• beta is defined on the interval $(0,1)$ or $[0,1]$ ? Aug 12, 2013 at 14:21