initial gradient

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

initial gradient

anmolrana
hi,
i have run this program but in result, i have found a problem. please help me how to solve this problem. i have seen very lengthy method to solve "NA initial gradient value", but i do not understand.

library(maxLik)
set.seed( 1234)
x<-c(0.2,0.4,0.1,0.6,0.2,0.4)
# Define your distribution pdf
# such as
fs<-function(x,alpha,beta,c,s){
(((1+(x/s)**c)**(-1))*exp(-alpha*(x**beta)))*(((1+(x/s)**c)**(-1))*(c/s)*(x/s)**(c-1)
+alpha*beta*(x**(beta-1)))
}
# Now take likelihood
# Note that the names of above mentioned parameters must introduced differently
logLikFun1 <- function( param ) {
a<-param[1]
b<- param[2]
d<- param[3]
e<- param[4]
sum(log(fs(x,alpha=a,beta=b,c=d,s=e)))
}
# gradient method
logLikGrad <- function( param ) {
a<-param[1]
b<- param[2]
d<- param[3]
e<- param[4]
 N <- length( x )
logLikGradValues <- numeric(4)
logLikGradValues[1]<-sum((-x**(b))+((b*(x**(b-1)))/((a*b*(x**(b-1)))+((d*(x**(d-1)))/((e**(d))+(x**(d)))))))
logLikGradValues[2]<-sum((-a*(x**(b))*log(x))+((a*(x**(b)))+(((a*b*(x**(b-1)))*log(x))/ ((a*b*(x**(b-1)))+((d*(x**(d-1)))/((e**(d))+(x**(d))))))))
logLikGradValues[3]<-sum(-(((d/e)*((x/e)**(d)))/ (1+((x/e)**(d))))-(((d*((x/e)**(d-1)))* (((e**(d))+(x**(d)))**(-2)))/((a*b*(x**(b-1)))+((d*(x**(d-1)))/((e**(d))+(x**(d)))))))
logLikGradValues[4]<-sum((-((1+((x/e)**(d)))**(-2))*log(x/e)*((x/e)**(d))/((1+((x/e)**(d)))**(-1))) +((((e**d)+(x**d))**(-1))*((x**(d-1))+ ((d*(x**(d-1)))*log(x))+(d*(x**(d-1)))-(((1+((x/e)**(d)))**(-2))*((e**(d))*log(e)+((x**(d))*log(x))))))/ ((a*b*(x**(b-1)))+((d*(x**(d-1)))/((e**d)+(x**d)))))
}
mleGrad <- maxLik( logLik = logLikFun1, grad = logLikGrad,
start = c(a=0.5,b=0.5,d=1.5,e=1.5))
summary( mleGrad )
coef(mleGrad)
stdEr(mleGrad)

i have recieved answer

Error in maxNRCompute(fn = function (theta, fnOrig, gradOrig = NULL, hessOrig = NULL,  :
  NA in the initial gradient
> summary( mleGrad )
Error in summary(mleGrad) : object 'mleGrad' not found
> coef(mleGrad)
Error in coef(mleGrad) : object 'mleGrad' not found
> stdEr(mleGrad)
Error in stdEr(mleGrad) : object 'mleGrad' not found