Re: [R] Need help to locate my mistake

From: Louise Hoffman <louise.hoffman_at_gmail.com>
Date: Mon, 03 Mar 2008 00:49:54 +0100

> Unfortunately, x^(-1) is not the inverse of x:
>
> x<-matrix(c(2,4,4,5),nrow=2)
> x
> # [,1] [,2]
> # [1,] 2 4
> # [2,] 4 5
>
> x^(-1)
> # [,1] [,2]
> # [1,] 0.50 0.25
> # [2,] 0.25 0.20
>
> i.e. it is the matrix which you get by applying the operation
> (...)^(-1) to each element of x.
>
> In R, the inverse of a non-singular matrix is (somewhat obscurely)
> denoted by solve(x):
>
> solve(x)
> # [,1] [,2]
> # [1,] -0.8333333 0.6666667
> # [2,] 0.6666667 -0.3333333
>
> solve(x)%*%x
> # [,1] [,2]
> # [1,] 1 1.110223e-16
> # [2,] 0 1.000000e+00
> (Note the slight rounding error); whereas
>
> (x^(-1))%*%x
> # [,1] [,2]
> # [1,] 2.0 3.25
> # [2,] 1.3 2.00

Thanks for the very detailed explanation! I will never make that mistake again =)



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 02 Mar 2008 - 23:52:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Mar 2008 - 01:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive