0
$\begingroup$

I just ran the code in R, which estimates some parameters using Anderson-Darling estimation method. The code is given in the appendix of the Habib-Khalil paper.

x=c(0.020,0.00300,0.00400,0.05500,0.0600,0.00700)
theta0=c(0.00001,0.0003)
para=c(0.0010000,0.0020000,0.0030000)
cdf0=function(para,x){
x=para[1]
y=para[2]
t=para[3]
(1-exp(-y*((t+1)/(t+1+t*x))*exp(-t*x)-1)^a)}

A = function(para, x,cdf0)
{ n=length(x)
x=sort(x)
D = rep(0,l=n)
for(i in 1:(length(x))){
const = (2*i-1)
 D[i] = const*(log(cdf0(x[i],para))+log(1-cdf0(x[i],para)))}
-n-(1/n)*sum(D)}

AD = function (cdf0,theta0,lim_inf,lim_sup)
{
max =try(optim(par = theta0, f = A,
                x = x, cdf0 = cdf0,control=list(maxit=60)),silent=F)
return(max[1])
} 

AD(cdf0,theta0,10,1000)

The error I encounter after running the code is Error in optim(par = theta0, f = A, x = x, cdf0 = cdf0, control = list(maxit = 60)) : function cannot be evaluated at initial parameters. The error persists after repeated changing the x,para,thet0 vectors. Actually the verbatim code in the appendix of the given paper also gave me the same error. Any hints where I am wrong? Thanks beforehand.

$\endgroup$
3
  • $\begingroup$ Is there any way you can improve the formatting on that code? It's pretty difficult to read. $\endgroup$
    – Richard
    May 12 at 13:31
  • $\begingroup$ @Richard Edited slightly. Does it help? $\endgroup$
    – vidyarthi
    May 12 at 13:53
  • $\begingroup$ + I'm afraid not. The content of your function is, for instance, still not indented. Most IDEs will have an auto format function that can fix this for you. $\endgroup$
    – Richard
    May 13 at 12:39

0

Your Answer

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

Browse other questions tagged or ask your own question.