Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

non-finite finite-difference value, many data become inf and NA after exponential

I'm going to find the parameters for a rank-logit model. But the error always shows that there are non-finite finite-difference value. If I change the "b0<-rep(0,5)" to "b0<-rep(-1,5)", the number after non-finite finite-difference value changes from 2 to 1. If you need the dataset, I will send it to you by email.

cjll <- function(b){

U <- X%*%b
lSU <- csm%*%exp(U)
   lSU <- (lSU!=0)*lSU+(lSU==0)
LL <- sum(Ccsm%*%U-log(lSU))

return(LL)
}

b0 <- rep(0,5)
res <- optim(b0,cjll,method="BFGS",hessian=TRUE,control=list(fnscale=-1))
#Error in optim(b0, cjll, method = "BFGS", hessian = TRUE, control = list(fnscale = -1)) :
#  non-finite finite-difference value [2]

b <- res$par
#Error: object 'res' not found
like image 494
Jiawen Jiang Avatar asked Jan 28 '15 05:01

Jiawen Jiang


1 Answers

BFGS requires the gradient of the function being minimized. If you don't pass one it will try to use finite-differences to estimate it. Looking at your likelihood function, it could be that the fact that you "split" it by elements equal to 0 and not equal to 0 creates a discontinuity that prevents the numerical gradient from being properly formed. Try using method = "Nelder-Mead" and setting Hessian to FALSE and see if that works. If it does, you can then use the numDeriv package to estimate the gradient and Hessian at the point of convergence if you need them.

like image 191
Avraham Avatar answered Nov 16 '22 03:11

Avraham