In the R code (R studio),
How to generate the gamma distribution by function?
we take an example for show how we generate tha gamma Distribution by function in R-Studio
R-Studio Syntax is as
# Example R Code
alpha=3
beta=12.4
avrg=alpha*beta
std.dv=sqrt(alpha*beta^2)
x=50
# Draw the Gamma Distribution
range=seq(0,avrg+5*std.dv,0.01)
y=dgamma(range,alpha,rate=1/beta)
plot(range,y,type="l",ylim=c(0,max(y)+0.01))
# Add area to the left of x
cord.a=c(0,seq(min(range),x,0.01),x)
cord.b=c(0,dgamma(seq(min(range),x,0.01),alpha,rate=1/beta),0)
polygon(cord.a,cord.b,col="blue")
# Add area to the right of x
cord.c=c(x,seq(x,max(range),0.01),b)
cord.d=c(0,dgamma(seq(x,max(range),0.01),alpha,rate=1/beta),0)
polygon(cord.c,cord.d,col=grey(0.90))
# P(X<x) Area to the left of x
pgamma(x,alpha,rate=1/beta)
# P(X>x) Area to the right of x
1-pgamma(x,alpha,rate=1/beta)
# 50th percentile median
qgamma(0.5,alpha,rate=1/beta)
And Result is as
Get Answers For Free
Most questions answered within 1 hours.