R - fitting a mixture distribution with fitdistrpl

2019-09-05 23:54发布

问题:

I have defined a mixture of a LogNormal and a Generalised Pareto (actuar) as follows:

dlnormgenpar<-function(x,
               w_lnorm,
               meanlog=0,
               sdlog=1,
               par_shape1=1,
               par_shape2=1,
               par_scale=1) {
  w_par=1-w_lnorm
  dln=dlnorm(x,meanlog = meanlog,sdlog = sdlog)
  dpar=dgenpareto(x,shape1=par_shape1,shape2=par_shape2,scale=par_scale)
  return(w_lnorm*dln+w_par*dpar)
}

I am trying to fit it to some data using fistdistrplus:

dist<-fitdist(data,"lnormgenpar")

However I receive the error:

Unknown starting values for distribution lnormgenpar.

If I expand the fitting function in the usual fitdistrplus way the error remains:

dist<-fitdist(data,"lnormgenpar",dparams=list(
  w_lnorm=0.5,
  meanlog=0,
  sdlog=1,
  par_shape1=1,
  par_shape2=1,
  par_scale=1
  ))

How should I pass my parameters in to the fitting function?

Thanks

Simon