Error in Error in chol.default(sigma.u): the leading minor of order 4 is not positive definite

i have problem in implementing the function :

gfevd = function(model, n.ahead=10,normalize=TRUE,standardize=FALSE) {
  if (class(model) != "varest") {
    return("The model class is not varest!")
  }
  A <- Phi(model, (n.ahead-1))
  epsilon <- residuals(model)
  Sigma <- abs(t(epsilon)%*%epsilon / (model$obs))
  gi <- array(0, dim(A))
  sigmas <- sqrt(diag(Sigma))
  for (j in 1:dim(A)[2]) {
    gi[,,j] <- t(A[,,j]%*%Sigma%*%solve(diag(sqrt(diag(Sigma)))))
  }
  
  if (standardize==TRUE){
    girf=array(NA, c(dim(gi)[1],dim(gi)[2], (dim(gi)[3])))
    for (i in 1:dim(gi)[3]){
      girf[,,i]=((gi[,,i])%*%solve(diag(diag(gi[,,1]))))
    }
    gi = girf
  }
  num <- apply(gi^2,1:2,sum)
  den <- c(apply(num,1,sum))
  fevd <- t(num)/den
  if (normalize==TRUE) {
    fevd=(fevd/apply(fevd, 1, sum))
  } else {
    fevd=(fevd)
  }
  return = list(fevd=fevd, girf=gi)
}
h = 10
plag = 2
var.ret = VAR(dataret,p=plag,lag.max = 10,ic="AIC") #my data is k by k matrix, not all are #positive numbers 
var.ret
var.vol = VAR(datavol,p=plag,lag.max = 10,ic="AIC")
var.vol
### TABLE 3
fevd.ret = fevd(var.ret,n.ahead=h)
fevd.vol = fevd(var.vol,n.ahead=h)
FEVD.VOL = FEVD.RET = matrix(NA,k,k)
colnames(FEVD.VOL) = rownames(FEVD.VOL) = colnames(FEVD.RET) = rownames(FEVD.RET) = colnames(dataret)
for (i in 1:k) {
  FEVD.RET[i,] = fevd.ret[[i]][h,]
  FEVD.VOL[i,] = fevd.vol[[i]][h,]
}
vs.ret = VS(FEVD.RET)
TABLE3 = vs.ret$ALL

The error comes out in fevd.ret = fevd(var.ret,n.ahead=h) saying "Error in Error in chol.default(sigma.u): the leading minor of order 4 is not positive definite"
can some one help please ?
Sardor

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.