0

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:

screenshot showing p, i.p, i.p.s matrix

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?

The multiple of i.p and its inverse, i.p.s

Silu Wang
  • 9
  • 1
  • The result is an identity matrix. All the values off the diag is almost 0. – Ven Yao Dec 16 '15 at 01:59
  • it is almost the identity.... floating point errors – user20650 Dec 16 '15 at 01:59
  • 3
    see http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal. Try `all.equal(i.p %*% i.p.s, diag(7))` – user20650 Dec 16 '15 at 02:00
  • 1
    Do not post your data as an image, please learn how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap Dec 16 '15 at 07:05
  • @Jaap the question did give a reproducible example ... the images just show the results of the code that they supplied – user20650 Dec 16 '15 at 11:11
  • 1
    @user20650 oops, sorry! on the other hand: if you can give a reproducible example, it isn't too hard i guess to include just the text output instead of a picture (which is better imo and also less cumbersome) – Jaap Dec 16 '15 at 11:32
  • ha, no prob, and yup i do agree.... just thought id mention it as sometimes it can attract downvotes for the poor op - which i think is a bit unnecessary for a new user, esp in this case, – user20650 Dec 16 '15 at 11:52

0 Answers0