全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
4795 0
2016-09-15
各位前辈好!

我最近在做价格传导,利用作者原有的数据和写好的语法跑了一遍模型(TVECM),但是一直提示如下错误,请问是怎么回事?需要如何解决呢?R语言新手菜鸟,希望各位大神指点一二,感激不尽!
> library(nlme)
>
> # load data
>
> A <- read.table(file="eu-pigs.dat")
> colnames(A) <- c("BE", "DK", "BRD", "E", "FR", "I", "NL")
> Y <- rbind(A$BRD,A$E)
>
> # specify number of lags to be included in the TVECM
>
> lags <- 3
>
> # calculate the error correction term as the price difference
>
> z <- Y[1,]-Y[2,]
>
> # organize data
>
> N <- length(z)
> Delta.Y <- Y[,-1]-Y[,-N]
>
> mat <- matrix(NaN,2*(lags+2)+1,N+lags+1)
> mat[1:2,1:N] <- Y
> mat[3:4,2:N] <- Delta.Y
> mat[5,2:(N+1)] <- z
> for (l in 1:lags){
+ mat[(2*l+4):(2*l+5),(2+l):(N+l)] <- Delta.Y
+ }
> mat <- mat[,which(!is.nan(colSums(mat)))]
>
> Y <- mat[1:2,]
> Delta.Y <- mat[3:4,]
> y <- c(Delta.Y[1, ],Delta.Y[2, ])
> z <- mat[5,]
> x <- t(mat[5:(2*(lags+2)+1),])
> x <- cbind(1,x)
>
> p <- ncol(x)
> N <- nrow(x)
>
> # specify grid
>
> grid <- sort(unique(z))
> grid1 <- grid[which(grid<0)]
> grid2 <- grid[which(grid>0)]
>
> G1 <- length(grid1)
> G2 <- length(grid2)
>
> # evaluate profile likelihood/posterior density on grid
>
> LF1 <- LF2 <- LF3 <- LF4 <- matrix(NaN,G1,G2)
>
> for (n in 1:G1)
+ {
+ for (m in 1:G2)
+ {
+ psi.1 <- grid1[n]
+ psi.2 <- grid2[m]
+ X <- kronecker(diag(1,2,2),x)
+ X1 <- kronecker(diag(1,2,2),(z <= psi.1)*x)
+ X2 <- kronecker(diag(1,2,2),(z > psi.1 & z <= psi.2)*x)
+ X3 <- kronecker(diag(1,2,2),(z > psi.2)*x)
+ Xpsi <- cbind(X1,X2,X3)
+
+ # compute profile likelihood
+
+ if (sum(z <= psi.1)>=p & sum(z > psi.1 & z <= psi.2)>=p & sum(z > psi.2)>=p)
+ {
+ ## same variance for the two components of the series (in effect, least squares)
+
+ LM <- lm(y ~ Xpsi-1)
+ LF1[n,m] <- logLik(LM)
+
+ ## different variances for the two components of the series
+
+ SSE <- matrix(LM$res,nrow=2,byrow=TRUE)
+ SSE1 <- sum((SSE[1,])^2)
+ SSE2 <- sum((SSE[2,])^2)
+ LF2[n,m] <- -log(SSE1*SSE2)
+ }
+
+ # compute regularized Bayesian posterior
+
+ ## same variance for the two components of the series
+
+ group.vector <- factor(rep(1,(2*N)))
+ ZBlock <- list(list(group.vector=pdIdent(~ X1-1)),list(group.vector=pdIdent(~ X2-1)))
+ ZBlock <- unlist(ZBlock,recursive=FALSE)
+ try({LME <-  lme(y ~ X - 1, random=ZBlock)
+ LF3[n,m] <- LME$logLik})
+
+ ## different variances for the two components of the series
+
+ group <- rep(1:2,each=N)
+ try({LMEnew <- update(LME, weights=varIdent(form =  ~ 1|group))
+ LF4[n,m] <- LMEnew$logLik})
+ }}
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in lme.formula(y ~ X - 1, random = ZBlock) :
  nlminb problem, convergence error code = 1
  message = singular convergence (7)
Error in solve.default(-val) :
  system is computationally singular: reciprocal condition number = 5.86726e-24
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0
Error in solve.default(-val) :
  Lapack routine dgesv: system is exactly singular: U[2,2] = 0



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群