Search code examples
rstatisticscdfgamma-distribution

R - Gamma Cumulative Distribution Function


I want to calculate the Gamma CDF for an array of data that I have. I have calculated the alpha and beta parameters, however I am not sure of how to calculate the CDF in R,(Is there something like Matlab's gamcdf?).

I have seen some people use fitdistr, or pgamma, but I do not understand how to put the alpha and beta values or I do not need them at all?

Thanks.


Solution

  • A gamma distribution is defined by the two parameters, and given those two parameters, you can calculate the cdf for an array of values using pgamma.

    # Let's make a vector
    x = seq(0, 3, .01)
    # Now define the parameters of your gamma distribution
    shape = 1
    rate = 2
    # Now calculate points on the cdf
    cdf = pgamma(x, shape, rate)
    # Shown plotted here
    plot(x,cdf)
    

    Gamma CDF

    Note that the Gamma has different ways it can be parameterized. Check ?pgamma for specifics to ensure your 2 parameters match.