# [R] Optimization failed in fitting mixture 3-parameter Weibull distri bution using fitdistr()

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jul 28 17:21:40 CEST 2003

```I don't think that is the right density: haven't you forgotten I(x > a)?
So you need a constraint on a in the optimization, or at least to return
density 0 if a >= min(x_i) (but I suspect the mle may well occur at the
boundary).

Without that constraint you don't have a valid optimization problem.

On Mon, 28 Jul 2003, Yang, Richard wrote:

> Dear All;
>
> 	I tried to use fitdistr() in the MASS library to fit a mixture
> distribution of the 3-parameter Weibull, but the optimization failed.
> Looking at the source code, it seems to indicate the error occurs at
>                 if (res\$convergence > 0)
>         stop("optimization failed").
>
>             The procedures I tested are as following:
>
> >w3den <- function(x, a,b,c) {c/b*((x -a)/b)^(c-1)*exp(-((x-a)/b)^c)}    #
> define 3-parameter Weibull density
> >w3den <- function(x, a,b,c) {c/b*((x -a)/b)^(c-1)*exp(-((x-a)/b)^c)}
> >set.seed(123)
> > x3 <- rweibull(100, shape = 4, scale = 100)                             #
> Distribution 1
> > fitdistr(x3, w3den, start= list(a = 8.8, b = 90.77, c = 3.678))      #
> Fitting 3-parameter
>
>        a            b            c
>    8.9487415   90.6667712    3.6722124
>  (15.1462445) (16.0657103) ( 0.7582376)
> Warning messages:
> 1: NaNs produced in: log(x)
> 2: NaNs produced in: log(x)
> >      x4 <- rweibull(50, shape = 3, scale = 90)                           #
> Distribution 2
> > fitdistr(x4, w3den, start=list(a = 5.0, b = 90, c = 3))
>        a            b            c
>   -67.572244   159.020786     5.835588
>  (105.975870) (107.842846) (  4.288019)
> Warning messages:
> 1: NaNs produced in: log(x)
> 2: NaNs produced in: log(x)
>
> > mweib <- function(x, p, a,b,c,a1, b1, c1) {p*(c/b*((x -
> a)/b)^(c-1)*exp(-((x-a)/b)^c))+
> +             +(1-p)*(c1/b1*((x -a1)/b1)^(c1-1)*exp(-((x-a1)/b1)^c1))}
> # define mixture distribution
> > x5 <- c(x3, x4)
> > fitdistr(x5, mweib, start=list(p = 0.7, a = 8.9, b=90.77, c = 3.68, a1 =
> -67.57, b1 = 159.02, c1 = 5.83))
> Error in fitdistr(x5, mweib, start = list(p = 0.7, a = 8.9, b = 90.77,  :
>         optimization failed
> In addition: There were 14 warnings (use warnings() to see them).
>
> 	I tested the same procedures with a mixture 2-parameter Weibull
> distribution without problems. With a limited experience with the
> fitdistr(), it seems to me, similar to all nonlinear or optimization
> procedures,  the starting values are critical for convergence. Any
> suggestions for solving the optimization problem?
>
> 	TIA
>
> Richard Yang
>
>
> Northern Forestry Centre   /	Centre de foresterie du Nord
> 5320-122 Street     	   /	5320, rue 122
>
> T6H 3S5
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

```