我想要调用Rsolnp包求极大似然估计,程序如下:
Xi <- seq(-1,by=0.001,0.999)
f1 <- (1/(sqrt(2*pi)*sqrt(0.01)))*exp(-(Xi+0.5)^2/0.02)
f2 <- 1/(sqrt(2*pi)*sqrt(0.05))*exp(-(Xi-0.5)^2/0.1)
t <-(0.3+0.25*Xi+f1+f2)^(-1)
#plot(Xi,t^(-1),col="blue",type="l")
library(actuar)
Yi <- rburr(2000,1,t,1)
z <- cbind(Xi,Yi)
o <- order(Yi,Xi)
sort_z <- z[o, ]
v <- sort_z[,2]
k <-40
n<-length(Yi)
u <- v[n-k]
z.samp = sort_z[(2000-k+1):2000,]
X <- z.samp[,1]
Y <- z.samp[,2]
h <- 0.1
library(Rsolnp)
library(parallel)
library(truncnorm)
ss <- rep(0,n)
for(j in 1:n)
 {
 x=Xi[j]
# the objective function to minimize
 f <- function(b)                                                                                                                                                                                                                                                                                                        
 {                                                                                                            
  (-1/k)*sum( ( log(b[1]+b[2]*(X-x)) + (1+(b[3]+b[4]*(X-x))^(-1)) * log(1 + Y*( (b[3]+b[4]*(X-x))/(b[1]+b[2]*(X-x))))    )*exp((-1/2)*((X-x)/h)^2) )
 }
# the inequality function                                      
inequa11 = function(b) {                          
 z1=b[1]+b[2]*(X-x)
 z2=b[3]+b[4]*(X-x)
 return(c(z1,z2))
 }
# the lower limit for inequalities
 ineqLB = c(0,0)
 ineqUB = c(10,5)
# initial value
 b0 = c(1,0,1,0) 
# solving the problem                                                                                                                                                                                                                                                            
ss[j] = solnp(b0, fun = f, ineqfun = inequa11, ineqLB = ineqLB,control=list(outer.iter=400)) 问:这里加什么语句可以把b[3]的解返回给ss[j],我知道调用multiroot( )时,后面用$root[3]可以返回b[3]给ss[j]
 }
运行会有 Error:solnp-->error: inequality function returns vector of different length to  inequality lower bounds
新手上路,求大神指点,焦急等待中,不甚感激