2016-11-22 4 views
0

Ich habe Reihe von Diagrammen wie folgt aussehen:Fit Punkte mit Gamma CDF in Python oder R

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") 

imge

Für einen bestimmten Zweck muss ich diese Punkte mit der besten kumulativen Verteilungsfunktion (CDF) der Gammaverteilung kombinieren. Gibt es eine Möglichkeit, dies in Python oder R numerisch zu tun? Ich benutze Winpython, damit ich R-Code ziemlich direkt importieren kann.

PS: Ich fand this Post, aber ich verstehe es nicht.

+0

'fitdistr (a, "Gamma")' aus dem 'MASS'-Paket in' R' scheint zu funktionieren, nicht wahr? –

+0

Ja, thx viel !! – Bobesh

Antwort

0
library(MASS) 
gammafit <- fitdistr(a, "gamma") 
# shape  rate 
# 17.552961 2.902459 
# (5.366214) (0.900112) 

So offenbar, der Gamma-Parameter 17.55 (für die Form) und 2,90 (für den Preis) Ihre Daten am besten passen.

plot(a, b, col = "red") 
lines(a, pgamma(a, gammafit$estimate[1], gammafit$estimate[2])) 

like this

0

Mit Paket 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)