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