Skip to content

Fitting Mixed Distributions in the fitdistrplus package

1 message · Christophe Dutang

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