在 R 中使用 Simplex 时获得 "NAs are not allowed in subscripted assignments"

Getting "NAs are not allowed in subscripted assignments" while using Simplex in R

我是运行以下命令:

>simplex(a = a, A2 = A2, b2 = b2, A3 = A3, b3 = b3)

我收到错误:

Error in pivot(tableau, prow, pcol) : 
  NAs are not allowed in subscripted assignments

这是我的 R 脚本:

library("boot")     # For simplex

set.seed(100)

i <- 6
X <- rnorm(i, mean = 4, sd = 1)
e <- rnorm(i, mean = 0, sd = 1)
Y <- 5*X + e

sum <- 0
Y_a <- matrix(0,1,floor(i/2))                 
for(miss in 1:floor(i/2)){
    sum <- sum + Y[miss*2]
    Y_a[miss] <- Y[miss*2]
}

Y_p <- 5*rnorm(floor(i/2), mean = 4, sd = 1) + rnorm(floor(i/2), mean = 0, sd = 1)          
a <- matrix(0,1,2*floor(i/2))
for(miss in 1:floor(i/2)){
    a[miss] <- 1
}
A3 <- t(apply(a,1, rev))
A2 <- matrix(0,2*floor(i/2),2*floor(i/2))

for(miss in 1:floor(i/2)){
    index <- 2*miss
    index_ <- index - 1
    A2[index_,miss] <- 1
    A2[index_,miss+floor(i/2)] <- 1
    A2[index,miss] <- 1
    A2[index,miss+floor(i/2)] <- -1
}
b2 <- matrix(0,2*floor(i/2),1)
b2[(1:(2*floor(i/2)))%%2==1] <- Y_p
b2[(1:(2*floor(i/2)))%%2==0] <- -Y_p
simplex(a = a, A2 = A2, b2 = b2, A3 = A3, b3 = sum)

当变量 "i" 大于 5 时出现上述错误,否则出现错误:

Error in simplex1(c(a, rep(0, m1 + 2 * m2 + m3)), cbind(rbind(A1, A2,  : 
  number of items to replace is not a multiple of replacement length
In addition: Warning message:
In simplex1(c(a, rep(0, m1 + 2 * m2 + m3)), cbind(rbind(A1, A2,  :
  number of items to replace is not a multiple of replacement length

我无法理解这些错误是LP问题无法解决还是函数调用方式有误

提前致谢。

关于参数 b2?simplex 的文档指出

A vector of length m2 giving the right hand side of the >= constraints. This argument is required if A2 is given and ignored otherwise. All values in b2 must be non-negative. Note that the constraints x >= 0 are included automatically and so should not be repeated here.

尝试确保 b2 始终为非负值。