Bobesh - 18 days ago 5

R Question

I have series of plots looking like this:

python code:

`a = np.array([4,4,4,4,5,5,5,6,6,6,6,6,6,6,7,7,7,8,8,8,9])`

b = np.array([i/len(a) for i in range(1, len(a)+1)])

pl.plot(a,b, 'ro')

r code:

`a <- c(4,4,4,4,5,5,5,6,6,6,6,6,6,6,7,7,7,8,8,8,9)`

b <- seq(0,1,length = length(a))

plot(a, b, col = "red")

For some purpose I need to fit this points with best cumulative distribution function (CDF) of gamma distribution. Is there any way how to do this numerically in python or R? I am using winpython so i can import R code pretty straightfoward.

PS: I found this post but I dont understant it.

Answer

Using package `fitdistrplus`

:

```
a <- c(4,4,4,4,5,5,5,6,6,6,6,6,6,6,7,7,7,8,8,8,9)
library(fitdistrplus)
fit <- fitdist(a, "gamma", lower = c(0,0))
plot(fit)
```