constrOptim() in R with non-conformable arguments

时间:2016-03-04 18:19:20

标签: r optimization multidimensional-array

Has somebody experience with constrOptim? I want to estimate a multivariate Garch model but I get Error in ui %*% theta : non-conformable arguments. Doing it by hand results in no problem. Do I need to change the arry of ui or theta?

A=matrix(rep(0.0001,100),10,10)

B=matrix(rep(0.0001,100),10,10)

theta=matrix(c(A,B),20,10, byrow = T)

ui=rbind(cbind(diag(1,10,10),matrix(rep(0),10,10)), cbind(matrix(rep(0),10,10),di ag(1,10,10)),cbind(diag((-1),10,10),diag((-1),10,10)),cbind(diag((1),10,10),diag((1),10,10)))
ci=c(rep(0,20),rep((-1),20))
#optimization procedure
est=constrOptim(theta, LogLik,grad=NULL, ui, ci,method = "BFGS",hessian=TRUE)

The LogLik is

LogLik=function(params)
{
#calling function to get input
x=matrix(unlist(params), ncol = 20, byrow = FALSE)
input=Vech_Garch(x)
SigmaLL=Sigma
errorLL=ee
d=dim(r_t)[2]

for(i in 1:(dim(r_t)[1]))
{
LL=-(d/2)*log(2*pi)-(d/2)*log(det(SigmaLL[(j[i]:k[i]),]))-(1/2)*t(errorLL[(j[i]:k[i]),])*solve(SigmaLL[(j[i]:k[i]),])*errorLL[(j[i]:k[i]),]
}
}

0 个答案:

没有答案