Re: [R] Matlab inv() and R solve() differences
Joseph P Gray wrote: I submit the following matrix to both MATLAB and R x= 0.133 0.254 -0.214 0.116 0.254 0.623 -0.674 0.139 -0.214 -0.674 0.910 0.011 0.116 0.139 0.011 0.180 MATLAB's inv(x) provides the following 137.21 -50.68 -4.70 -46.42 -120.71 27.28 -8.94 62.19 -58.15 6.93 -7.89 36.94 8.35 11.17 10.42 -14.82 R's solve(x) provides: 261.94 116.22 150.92 -267.78 116.22 344.30 286.68 -358.30 150.92 286.68 252.96 -334.09 -267.78 =358.30 -334.09 475.22 inv(x)*x = I(4) and solve(x)%*%x = I(4) Is there a way to obtain the MATLAB result in R? Multiply x[3,4] by 10: xx - x xx[3,4]-0.11 solve(xx) [,1] [,2] [,3] [,4] [1,] 137.20892 -50.67500 -4.705127 -46.41581 [2,] -120.71445 27.27570 -8.937571 62.19270 [3,] -58.15073 6.93474 -7.886343 36.93919 [4,]8.34851 11.17053 10.415928 -14.81602 -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@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.
Re: [R] Matlab inv() and R solve() differences
Hello, is there a upper limit to kappa value where I can consider a matrix well-conditioned? Cleber Kingsford Jones wrote: I suppose the solution is unstable because x is ill-conditioned: x [,1] [,2] [,3] [,4] [1,] 0.133 0.254 -0.214 0.116 [2,] 0.254 0.623 -0.674 0.139 [3,] -0.214 -0.674 0.910 0.011 [4,] 0.116 0.139 0.011 0.180 cor(x) [,1] [,2] [,3] [,4] [1,] 1.000 0.9963557 -0.9883690 0.8548065 [2,] 0.9963557 1.000 -0.9976663 0.8084090 [3,] -0.9883690 -0.9976663 1.000 -0.7663847 [4,] 0.8548065 0.8084090 -0.7663847 1.000 kappa(x) [1] 2813.326 hth, Kingsford Jones On Thu, Jan 29, 2009 at 7:00 PM, Joseph P Gray jpg...@uwm.edu wrote: I submit the following matrix to both MATLAB and R x= 0.133 0.254 -0.214 0.116 0.254 0.623 -0.674 0.139 -0.214 -0.674 0.910 0.011 0.116 0.139 0.011 0.180 MATLAB's inv(x) provides the following 137.21 -50.68 -4.70 -46.42 -120.71 27.28 -8.94 62.19 -58.15 6.93 -7.89 36.94 8.35 11.17 10.42 -14.82 R's solve(x) provides: 261.94 116.22 150.92 -267.78 116.22 344.30 286.68 -358.30 150.92 286.68 252.96 -334.09 -267.78 =358.30 -334.09 475.22 inv(x)*x = I(4) and solve(x)%*%x = I(4) Is there a way to obtain the MATLAB result in R? Thanks for any help. Pat Gray __ __ R-help@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.
Re: [R] Matlab inv() and R solve() differences
Joseph P Gray wrote: I submit the following matrix to both MATLAB and R x= 0.133 0.254 -0.214 0.116 0.254 0.623 -0.674 0.139 -0.214 -0.674 0.910 0.011 0.116 0.139 0.011 0.180 MATLAB's inv(x) provides the following 137.21 -50.68 -4.70 -46.42 -120.71 27.28 -8.94 62.19 -58.15 6.93 -7.89 36.94 8.35 11.17 10.42 -14.82 R's solve(x) provides: 261.94 116.22 150.92 -267.78 116.22 344.30 286.68 -358.30 150.92 286.68 252.96 -334.09 -267.78 =358.30 -334.09 475.22 The matrix x is clearly symmetric. Therefore I expect a symmetric inverse of x. The result of Matlab's inv(x) is clearly not symmetric. R's result is symmetric. I find what is shown as Matlab's result difficult to believe. Berend -- View this message in context: http://www.nabble.com/Matlab-inv%28%29-and-R-solve%28%29-differences-tp21740213p21745164.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Matlab inv() and R solve() differences
Berend Hasselman wrote: Joseph P Gray wrote: I submit the following matrix to both MATLAB and R x= 0.133 0.254 -0.214 0.116 0.254 0.623 -0.674 0.139 -0.214 -0.674 0.910 0.011 0.116 0.139 0.011 0.180 MATLAB's inv(x) provides the following 137.21 -50.68 -4.70 -46.42 -120.71 27.28 -8.94 62.19 -58.15 6.93 -7.89 36.94 8.35 11.17 10.42 -14.82 R's solve(x) provides: 261.94 116.22 150.92 -267.78 116.22 344.30 286.68 -358.30 150.92 286.68 252.96 -334.09 -267.78 =358.30 -334.09 475.22 The matrix x is clearly symmetric. Therefore I expect a symmetric inverse of x. The result of Matlab's inv(x) is clearly not symmetric. R's result is symmetric. I find what is shown as Matlab's result difficult to believe. Yes. See my earlier post. (Well. I believe it, but not with the same input!) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@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.
Re: [R] Matlab inv() and R solve() differences
Hi Cleber, there is no hard-and-fast magic number here. Ill-conditioning also depends on what you are trying to do (inference? prediction?). The condition number is only one of a number of conditioning/collinearity diagnostics commonly used. Take a look at: Golub, G. H., Van Loan, C. F. (1996). Matrix Computations (3rd ed.). Baltimore: Johns Hopkins University Press. Belsley, D. A. (1991a). Conditioning Diagnostics: Collinearity and Weak Data in Regression. New York, NY: Wiley. Hill, R. C., Adkins, L. C. (2001). Collinearity. In B. H. Baltagi (Ed.), A Companion to Theoretical Econometrics (p. 256-278). Oxford: Blackwell HTH, Stephan Cleber Nogueira Borges schrieb: Hello, is there a upper limit to kappa value where I can consider a matrix well-conditioned? Cleber Kingsford Jones wrote: I suppose the solution is unstable because x is ill-conditioned: x [,1] [,2] [,3] [,4] [1,] 0.133 0.254 -0.214 0.116 [2,] 0.254 0.623 -0.674 0.139 [3,] -0.214 -0.674 0.910 0.011 [4,] 0.116 0.139 0.011 0.180 cor(x) [,1] [,2] [,3] [,4] [1,] 1.000 0.9963557 -0.9883690 0.8548065 [2,] 0.9963557 1.000 -0.9976663 0.8084090 [3,] -0.9883690 -0.9976663 1.000 -0.7663847 [4,] 0.8548065 0.8084090 -0.7663847 1.000 kappa(x) [1] 2813.326 hth, Kingsford Jones On Thu, Jan 29, 2009 at 7:00 PM, Joseph P Gray jpg...@uwm.edu wrote: I submit the following matrix to both MATLAB and R x= 0.133 0.254 -0.214 0.116 0.254 0.623 -0.674 0.139 -0.214 -0.674 0.910 0.011 0.116 0.139 0.011 0.180 MATLAB's inv(x) provides the following 137.21 -50.68 -4.70 -46.42 -120.71 27.28 -8.94 62.19 -58.15 6.93 -7.89 36.94 8.35 11.17 10.42 -14.82 R's solve(x) provides: 261.94 116.22 150.92 -267.78 116.22 344.30 286.68 -358.30 150.92 286.68 252.96 -334.09 -267.78 =358.30 -334.09 475.22 inv(x)*x = I(4) and solve(x)%*%x = I(4) Is there a way to obtain the MATLAB result in R? Thanks for any help. Pat Gray __ __ R-help@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. __ R-help@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.
Re: [R] Matlab inv() and R solve() differences
I suppose the solution is unstable because x is ill-conditioned: x [,1] [,2] [,3] [,4] [1,] 0.133 0.254 -0.214 0.116 [2,] 0.254 0.623 -0.674 0.139 [3,] -0.214 -0.674 0.910 0.011 [4,] 0.116 0.139 0.011 0.180 cor(x) [,1] [,2] [,3] [,4] [1,] 1.000 0.9963557 -0.9883690 0.8548065 [2,] 0.9963557 1.000 -0.9976663 0.8084090 [3,] -0.9883690 -0.9976663 1.000 -0.7663847 [4,] 0.8548065 0.8084090 -0.7663847 1.000 kappa(x) [1] 2813.326 hth, Kingsford Jones On Thu, Jan 29, 2009 at 7:00 PM, Joseph P Gray jpg...@uwm.edu wrote: I submit the following matrix to both MATLAB and R x= 0.133 0.254 -0.214 0.116 0.254 0.623 -0.674 0.139 -0.214 -0.674 0.910 0.011 0.116 0.139 0.011 0.180 MATLAB's inv(x) provides the following 137.21 -50.68 -4.70 -46.42 -120.71 27.28 -8.94 62.19 -58.15 6.93 -7.89 36.94 8.35 11.17 10.42 -14.82 R's solve(x) provides: 261.94 116.22 150.92 -267.78 116.22 344.30 286.68 -358.30 150.92 286.68 252.96 -334.09 -267.78 =358.30 -334.09 475.22 inv(x)*x = I(4) and solve(x)%*%x = I(4) Is there a way to obtain the MATLAB result in R? Thanks for any help. Pat Gray __ R-help@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. __ R-help@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.
Re: [R] Matlab inv() and R solve() differences
G'day all, On Thu, 29 Jan 2009 19:24:40 -0700 Kingsford Jones kingsfordjo...@gmail.com wrote: I suppose the solution is unstable because x is ill-conditioned: While, as you show, x is ill-conditioned, I do not believe that this is serious enough to explain the differences that Pat sees between MATLAB and R. In fact, on one of our lab machines MATLAB Version 7.5.0.342 (R2007b), August 15, 2007, yields the following result: x=[0.133 0.254 -0.214 0.116; 0.254 0.623 -0.674 0.139; -0.214 -0.674 0.910 0.011 ; 0.116 0.139 0.011 0.180] x = 0.13300.2540 -0.21400.1160 0.25400.6230 -0.67400.1390 -0.2140 -0.67400.91000.0110 0.11600.13900.01100.1800 inv(x) ans = 261.9426 116.2219 150.9174 -267.7793 116.2219 344.3029 286.6735 -358.2959 150.9174 286.6735 252.9553 -334.0920 -267.7793 -358.2959 -334.0920 475.2252 which is consistent with the output of R's solve(). But the matrix x is ill-conditioned enough for small changes in the precision of the entries leading to big differences in the calculated inverse matrix. My guess is that Pat was not completely truthful in the description of what he did. Presumably, x was not submitted to MATLAB in the given form but calculated (to a higher precision) in MATLAB before being fed to MATLAB's inv() command. Then x was transferred with a lower precision (less significant digits) to R and submitted there to R's solve() function. Thus coming back to Pat's original question: On Thu, Jan 29, 2009 at 7:00 PM, Joseph P Gray jpg...@uwm.edu wrote: [...] Is there a way to obtain the MATLAB result in R? Presumably yes. Feed x in the same precision to R's solve() function as you feed it to MATLAB's inv() function. HTH. Cheers, Berwin === Full address = Berwin A TurlachTel.: +65 6516 4416 (secr) Dept of Statistics and Applied Probability+65 6516 6650 (self) Faculty of Science FAX : +65 6872 3919 National University of Singapore 6 Science Drive 2, Blk S16, Level 7 e-mail: sta...@nus.edu.sg Singapore 117546http://www.stat.nus.edu.sg/~statba __ R-help@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.