options(warn=-1)

Gamma Distribution The Gamma Distribution is commonly used distribution for a continous random variable that only take values on non negative values 0 <= x < inf

it has a probability density function g(x;a,b) ==> k(x^(r-1))((exp(1))^(-vx)) for 0<= x < inf*

the shape of the curve is determined by (x^(r-1))((exp(1))^(-v*x)) and k is the constant to make this equation probabaility density function

k (constant) is generalization of factorial function v^r/Fact(r)

so lets create probability density function for gamma distribution

gamma<-function(x,r,v){
  k = (v**r)/(factorial(r))
  gammf<- k*(x^(r-1))*((exp(1))^(-v*x))
  print(paste("k is : " ,k))
  return(gammf)
}

lets create a variable that ranges between 0 and inf

x <- seq(0, 5, length = 21)

define a and b values

r_v <- c(1,2,3,4,5)

plot probability densities with loop

dist<-NULL
for (r in r_v){
  for (v in r_v){
    dist<- gamma(x,r,v)
    plot(x,dist,type="b",col="blue",main = paste("Gamma (",r,",",v,")"),ylab="density")
  }
}
## [1] "k is :  1"

## [1] "k is :  2"

## [1] "k is :  3"

## [1] "k is :  4"

## [1] "k is :  5"

## [1] "k is :  0.5"

## [1] "k is :  2"

## [1] "k is :  4.5"

## [1] "k is :  8"

## [1] "k is :  12.5"

## [1] "k is :  0.166666666666667"

## [1] "k is :  1.33333333333333"

## [1] "k is :  4.5"

## [1] "k is :  10.6666666666667"

## [1] "k is :  20.8333333333333"

## [1] "k is :  0.0416666666666667"

## [1] "k is :  0.666666666666667"

## [1] "k is :  3.375"

## [1] "k is :  10.6666666666667"

## [1] "k is :  26.0416666666667"

## [1] "k is :  0.00833333333333333"

## [1] "k is :  0.266666666666667"

## [1] "k is :  2.025"

## [1] "k is :  8.53333333333333"

## [1] "k is :  26.0416666666667"

we can see same shapes with different parameters of r,v but the area under curves are differs from each other

Thanks: Hincal Topcuoglu