def fit_nbinom(samples): from rpy import r r.library('MASS') f = r.fitdistr(samples,'negative binomial') s,m = f['estimate']['size'],f['estimate']['mu'] qp = r.qnbinom(r.ppoints(samples),size=s,mu=m) return qp,s,m
def fit_poisson(samples): from rpy import r r.library('MASS') f = r.fitdistr(samples,'poisson') l = f['estimate']['lambda'] #predicted mean qp = r.qpois(r.ppoints(samples),l) return qp,l
def fit_weibull(samples): from rpy import r #samples = [double(n) for n in samples if n > 0]#because rpy does not like longs! r.library('MASS') f = r.fitdistr(samples,'weibull') sc,sh = f['estimate']['scale'],f['estimate']['shape'] qp = r.qweibull(r.ppoints(samples),scale=sc,shape=sh) return qp,sc,sh
def fit_gamma(samples): from rpy import r samples = [double(n) for n in samples if n > 0]#because rpy does not like longs! r.library('MASS') f = r.fitdistr(samples,'gamma') shap,rat = f['estimate']['shape'],f['estimate']['rate'] qp = r.qgamma(r.ppoints(samples),shape=shap,rate=rat) return qp,shape,rat
def fit_exponential(samples): from rpy import r samples = [double(n) for n in samples]#because rpy does not like longs! r.library('MASS') f = r.fitdistr(samples,'exponential') rat = f['estimate']['rate'] qp = r.qexp(r.ppoints(samples),rate=rat) return qp, rat