I want to take the inverse of a matrix i.p
with the solve
function. This i.p
matrix is the result of an identity matrix subtracting p
.
Here's the code to get i.p
:
p<-rbind(c(0,0,0,0,0,0,3), c(0,0,7,9,0,0,0), c(3,6,0,75,0,0,0), c(0,0,20,0,1,35,34), c(0,0,1,0,0,0,0), c(0,0,10,1,0,0,27), c(0,3,31,2,0,0,0))
dev<-c(sum(0,0,0,0,0,0,3), sum(0,0,7,9,0,0,0), sum(3,6,0,75,0,0,0), sum(0,0,20,0,1,35,34), sum(0,0,1,0,0,0,0), sum(0,0,10,1,0,0,27), sum(0,3,31,2,0,0,0))
p<-p/dev
p[7,]<-c(0,3,31,2,0,0,0)/sum(0,3,31,2,0,0,0, 30)
i<-diag(1, 7, 7) #make a 7X7 identity matrix
i.p<-i-p #identity matrix substract probability matrix I-P
i.p.s<-solve(i.p, i) #inverse of I-P
Here's the p
, i.p
, and i.p.s
matrices:
This inverse i.p.s
multiplies the matrix i.p
should be an identity matrix.
i.p %*% i.p.s
However this multiple calculated with the code above was clearly not an identity matrix. Why is that?