Christophe Dutang
2020-Oct-24 06:08 UTC
[R] Fitting Mixed Distributions in the fitdistrplus package
Dear Charles, Please, when you have questions about fitdistrplus, contact directly the authors of the package and not R-help. When fitting non ? standard ? distributions with fitdistrplus, you should define by yourself the density and the cumulative distribution functions, or load a package which define them. See FAQ for a general example : https://cran.r-project.org/web/packages/fitdistrplus/vignettes/FAQ.html#how-do-i-find-non-standard-distributions ? Regarding your mixed distribution, the code below works correctly. By the way, the Feller-Pareto distribution (see actual) is among the best distributions for the Danish dataset. You may also consider composite distributions, see https://CRAN.R-project.org/view=Distributions Kind regards, Christophe dmixgam <- function(x, prob, shape1, scale1, shape2, scale2) prob*dgamma(x, shape1, scale=scale1)+ (1-prob)*dpareto(x, shape2, scale=scale2) pmixgam <- function(q, prob, shape1, scale1, shape2, scale2) prob*pgamma(q, shape1, scale=scale1)+ (1-prob)*ppareto(q, shape2, scale=scale2) library(actuar) library(fitdistrplus) data("danishuni") x<- danishuni$Loss fgam<- fitdist(x,"gamma",lower=0) fpar<- fitdist(x,"pareto",start = list(shape=2,scale=2),lower=0) fmixgam<- fitdist(x,"mixgam",start list(prob=1/2,shape1=1,scale1=1,shape2=1,scale2=1),lower=0) cdfcomp(list(fgam, fpar, fmixgam), xlogscale = TRUE) gofstat(list(fgam, fpar, fmixgam))> > ---------- Forwarded message --------- > From: Charles Thuo <tcmuigai at gmail.com> > Date: Wed, Oct 21, 2020 at 12:03 AM > Subject: [R] Fitting Mixed Distributions in the fitdistrplus package > To: <r-help at r-project.org> > > > Dear Sirs, > > The below listed code fits a gamma and a pareto distribution to a data set > danishuni. However the distributions are not appropriate to fit both tails > of the data set hence a mixed distribution is required which has ben > defined as "mixgampar" > as shown below. > > library(fitdistrplus) > x<- danishuni$Loss > fgam<- fitdist(x,"gamma",lower=0) > fpar<- fitdist(x,"pareto",start = list(shape=2,scale=2),lower=0) > fmixgampar<- fitdist(x,"mixgampar",start > list(prob=1/2,nu=1,lambda=1,alpha=1,theta=1),lower=0) > Error in fitdist(x, "mixgampar", start = list(prob = 1/2, nu = 1, lambda > 1, : > > The dmixgampar function must be defined > > Kindly assist to define the dmixgampar > > Charkes > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.