用手概率错误“无法用double类型的向量强制类型关闭

时间:2019-04-24 20:54:55

标签: r function

我正在尝试使用R手动编码一个Probit,但出现错误   无法将类型'closure'强制转换为类型'double'的向量

{

    probitll<-function( X, Y){ 
     Y<-as.matrix(Y)
     X<-as.matrix(X)
     K<-ncol(X)
     b<-as.matrix(par[1:K])
     R<-pnorm(X%*%b)
     sum(Y*log(R)+(1-Y)*log(1-R))
    }
    {grad<-function( X, Y){
      + X<-as.matrix(X)
      + Y<-as.matrix(Y)
      + K<-ncol(X)
      + b<-as.matrix(par(1:K))
      + R<-pnorm(X%*%b)
      + apply(R*X, 2, sum)
    }

    resultprobit<-optim(beta, probitll, gr=grad,  Y=Y, X=X, method="BFGS", control=list(fnscale=-1), hessian=TRUE)

Error in optim(probitll, gr = grad, Y = Y, X = X, method = "BFGS", control = list(fnscale = -1),  : 
  cannot coerce type 'closure' to vector of type 'double'

0 个答案:

没有答案