Matrix QPmat:Amat和dvec不兼容

Matrix QPmat:Amat和dvec不兼容,matrix,constraints,quadratic-programming,Matrix,Constraints,Quadratic Programming,我是二次规划新手,在popbio包中运行函数QPmat时遇到问题,该包使用阶段类计数矩阵来计算阶段类转移概率 我正在运行的代码: ####Create a matrix of time series stage class counts Total<- matrix(c(17,74,86,41,17,11,75,84,46,25,7,60,90,46,24,10,61,82,44,25),nrow=5, ncol=4) Total ## list nonzero elements co

我是二次规划新手,在popbio包中运行函数QPmat时遇到问题,该包使用阶段类计数矩阵来计算阶段类转移概率

我正在运行的代码:

####Create a matrix of time series stage class counts
Total<- 
matrix(c(17,74,86,41,17,11,75,84,46,25,7,60,90,46,24,10,61,82,44,25),nrow=5, 
ncol=4)
Total
## list nonzero elements counting by column, indices
nonzero <- c(1,2,7,8,13,14,19,20,25)
## create a constraint matrix, C
C <- rbind(diag(-1,5), c(1,1,0,0,0), c(0,0,1,0,0), c(0,0,0,0,1))
C
## calculate b vector
b <- apply(C, 1, max)
b
QPmat(Total,C,b,nonzero)
#####创建时间序列阶段类计数矩阵

总计我的约束矩阵完全错误。我查看了Caswell 2001中的实际示例,并了解了约束的作用

对于上述代码中的约束矩阵C,替换为:

C<-rbind(diag(-1,9), c(1,1,0,0,0,0,0,0,0), c(0,0,1,1,0,0,0,0,0), 
c(0,0,0,0,1,1,0,0,0),c(0,0,0,0,0,0,1,1,0),c(0,0,0,0,0,0,0,0,1))
C