我正在尝试使用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'