我试图运行一个面向输出的DEA模型,并得到以下错误:
1.
Warning message:
In rbind(const.mat, const.dir.num, const.rhs) :
number of columns of result is not a multiple of vector length (arg 2)
Error in rbind(weights, results$solution[1]) :
cannot coerce type 'closure' to vector of type 'list'
我分享我的完整代码如下:
library(readxl)
library(lpSolve)
library (rJava)
library(WriteXLS)
library(xlsxjars)
#defining dataset
df=data.frame(read_excel(path = "Data1.xlsx", sheet= "1"))
inputs=data.frame(df[1:2])
outputs=data.frame(df[3:4])
m=2
s=ncol(df)-m
N= nrow(df)
f.con=matrix(ncol=N+1,nrow=m+s)
for (j in 1:N)
f.rhs = c(unlist(unname(df[j,(1):(m),1])),rep(0,s), 1)
f.dir = c(rep("<=",m),rep(">=",s), "=")
f.obj = c(1, rep(0,N))
for(i in 1:m){}
f.con[i,1:(N+1)]=c(0,df[,i])
for(i in 1:m){f.con[i,1:(N+1)]=c(0,df[,i])}
for(r in (m+1):(s+m)) {f.con[r,1:(N+1)]=c(as.numeric(-df[j,r]),as.numeric(df[,r]))}
#solving the model
results =lp ("max", as.numeric(f.obj), f.con, f.dir, f.rhs, scale=0, compute.sens=F)
> Warning message:
> In rbind(const.mat, const.dir.num, const.rhs) :
number of columns of result is not a multiple of vector length (arg 2)
if (j==1) {weights = results$solution[1]
lambdas = results$solution[seq(2,(N+1))]
xbench =lambdas%*% as.matrix(inputs)
ybench =lambdas%*% as.matrix(outputs)
} else{
weights = rbind(weights, results$solution[1])
lambdas = rbind(lambdas, results$solution[seq(2,(N+1))])
xbench = lambdas %*% as.matrix(inputs)
ybench = lambdas %*% as.matrix(outputs) }
> Error in rbind(weights, results$solution[1]) :
cannot coerce type 'closure' to vector of type 'list'
1条答案
按热度按时间ncecgwcz1#
首先,
lp
的compute.sens
参数不接受TRUE
/FALSE
,它默认为“no”,所以我相信您可以安全地删除该参数,请参见下面的?lp
:预解数值:预解-默认为0(否);任何非零值表示“是”。当前已忽略。
第二,最后一条错误消息来自if/else逻辑块的第五行。
weights
和lambdas
没有在您的环境或if/else块的else
部分中定义,所以R认为你在尝试rbind
函数stats::weights
(一个闭包)。您可以在将来通过单独运行每一行来查找错误发生的位置,从而排除类似这样的if/else块。如何修复错误取决于您的总体编程目标以及您希望如何定义
weights
。您可以将定义weights
和lambdas
的部分复制粘贴到您的else
部分,但这取决于您的目标。您最近评论的代码输出: