library(Ryacas0)
library(Matrix)
Consider this model: xi=ax0+ei,i=1,…,4 and x0=e0. All terms e0,…,e3 are independent and N(0,1) distributed. Let e=(e0,…,e3) and x=(x0,…x3). Isolating error terms gives that e=L1x where L1 has the form
<- diag(4)
L1chr 2:4, 1] <- "-a"
L1chr[<- as.Sym(L1chr)
L1 L1
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] -a 1 0 0
## [3,] -a 0 1 0
## [4,] -a 0 0 1
If error terms have variance 1 then Var(e)=LVar(x)L′ so the covariance matrix is V1=Var(x)=L−(L−)′ while the concentration matrix (the inverse covariances matrix) is K=L′L.
<- Simplify(Inverse(L1))
L1inv <- Simplify(Transpose(L1) * L1)
K1 <- Simplify(L1inv * Transpose(L1inv)) V1
cat(
"\\begin{align}
K_1 &= ", TeXForm(K1), " \\\\
V_1 &= ", TeXForm(V1), "
\\end{align}", sep = "")
K1=(3a2+1−a−a−a−a100−a010−a001)V1=(1aaaaa2+1a2a2aa2a2+1a2aa2a2a2+1)
Slightly more elaborate:
<- diag(4)
L2chr 2:4, 1] <- c("-a1", "-a2", "-a3")
L2chr[<- as.Sym(L2chr)
L2 L2
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] -a1 1 0 0
## [3,] -a2 0 1 0
## [4,] -a3 0 0 1
<- diag(4)
Vechr cbind(1:4, 1:4)] <- c("w1", "w2", "w2", "w2")
Vechr[<- as.Sym(Vechr)
Ve Ve
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] w1 0 0 0
## [2,] 0 w2 0 0
## [3,] 0 0 w2 0
## [4,] 0 0 0 w2
<- Simplify(Inverse(L2))
L2inv <- Simplify(Transpose(L2) * Inverse(Ve) * L2)
K2 <- Simplify(L2inv * Ve * Transpose(L2inv)) V2
cat(
"\\begin{align}
K_2 &= ", TeXForm(K2), " \\\\
V_2 &= ", TeXForm(V2), "
\\end{align}", sep = "")
K2=(w1a21w22+w1w22a22+w1w22a23+w32w1w32−a1w2−a2w2−a3w2−a1w21w200−a2w201w20−a3w2001w2)V2=(w1w1a1w1a2w1a3a1w1w1a21+w2a1w1a2a1w1a3a2w1a2w1a1w1a22+w2a2w1a3a3w1a3w1a1a3w1a2w1a23+w2)