0
$\begingroup$

This is an extension of an earlier question asked here. I have a data-set coming from a distribution given by:

$$Pr(X=k)=p \left({n\choose k}a^k(1-a)^{n-k}\right)+(1-p) \left({n\choose k}b^k(1-b)^{n-k}\right)$$

which is a mixture of two binomial distributions.

My aim is to estimate the parameter values, namely: n, p, a, b. To this I want to optimize the maximum likelihood function using "JDEoptim" package via R software.

fn<-function(x){
  #x(1)=p; x(2)=n; x(3)=a; x(4)=b;
  -prod(DensityFn(x, dataset[1:length(dataset)]))
}

DensityFn<-function(x, val){
  x[1]*dbinom(val, floor(x[2]), x[3])+(1-x[1])*dbinom(val, floor(x[2]), x[4])
}

lower=c(0, 11, 0, 0);
upper=c(0.5, 20, 1, 1);

print(JDEoptim(lower, upper, fn))

The variable "data-set" contains the values generated by this density function. The output upon running this program gives me:

$par [1]  0.07007818 11.85238114  0.86411002  0.64941201

$value [1] 0

$iter [1] 0

$convergence [1] 0

'iter' is 0 while 'convergence' is 0...indicating convergence has occured, however the parameter values outputted are far off from the actual values. Also, every time I run the program, the parameter estimates differ, but 'iter' and 'convergence' are always 0.

Is my code and logic correct?

$\endgroup$
2
  • 3
    $\begingroup$ At minimum, you should provide a link to your earlier question stats.stackexchange.com/questions/327702/… $\endgroup$ Commented Feb 10, 2018 at 14:30
  • $\begingroup$ Thank you for pointing that out. Is it usually bad practice to ask follow-up questions within a short time-frame to an already answered question? I'm asking because I'm a relatively new user to the stack community $\endgroup$ Commented Feb 10, 2018 at 14:36

1 Answer 1

1
$\begingroup$

Fixed the problem by using log-likelihood instead.

used

-sum(log(DensityFn(x, dataset[1:length(dataset)]))) 

instead of

-prod(DensityFn(x, dataset[1:length(dataset)]))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.