[R] solve() doesn`t work

Achim Zeileis zeileis at ci.tuwien.ac.at
Wed Jun 19 17:07:18 CEST 2002


Frithjof Weinert wrote:
> 
> Hi,
> 
> I tried to inverse a matrix but it doesn`t work. I hope somebody can help
> me. This is what I did.
> 
> > kurse <- read.table("kurse.txt", header=T, dec=",")
> > x <- cbind(1,kurse[,-c(1)])
> > y <- kurse$index
> > t(x) %*% x
> Error in t(x) %*% x : requires numeric matrix/vector arguments
> > x <- as.matrix(x)
> > xtxi <- solve(t(x) %*% x)
> Error in solve.default(t(x) %*% x) : singular matrix `a' in solve

>From help(solve)

     tol: the tolerance for detecting linear dependencies in the
          columns of `a'.

By default tol = 1e-7, which is in my experience a little bit low. Just
try:

R> xtxi <- solve(crossprod(x), tol = 1e-10)

That should work
Z

> My data looks like this:
> 
>     index   bmw    mru   rwe    vow    kar    sie   bas
> 1  159.70 74.18 338.21 89.03 110.30 141.23 178.53 67.97
> 2  160.76 73.46 343.66 89.38 110.30 142.66 180.45 68.30
> 3  162.45 74.18 349.12 91.54 108.54 146.22 183.12 68.85
> 4  162.18 72.74 349.12 92.20 106.43 144.80 181.75 68.52
> 5  161.64 72.98 340.93 91.43 101.87 144.08 181.41 68.30
> 6  160.81 72.74 338.21 91.43 103.62 141.23 181.07 68.08
> 7  161.34 72.51 338.21 91.69 104.11 144.44 182.44 67.97
> 8  161.61 72.74 351.84 91.84 103.27 142.66 182.78 67.97
> 9  162.05 72.84 354.57 92.20 102.43 142.66 184.29 67.81
> 10 161.77 71.79 365.48 91.95 102.57 142.66 184.50 67.42
> 11 160.97 71.60 381.85 91.23 100.25 141.23 183.81 67.48
> 12 160.40 71.55 370.94 90.67  98.99 143.37 182.30 67.26
> 13 160.36 71.69 370.94 90.92  98.63 144.08 181.62 67.31
> 14 160.20 71.79 370.94 90.92  98.56 143.37 181.27 67.15
> 15 159.78 70.83 362.75 91.02  97.65 143.02 180.86 67.15
> 16 159.89 70.83 365.48 91.02  98.14 143.37 180.93 66.76
> 17 159.15 69.87 365.48 90.15  96.81 141.95 178.73 66.38
> 18 157.29 67.00 362.75 89.49  95.33 139.81 176.54 65.66
> 19 157.18 69.39 365.48 89.90  95.26 138.38 176.33 65.33
> 20 157.58 69.39 381.85 89.90  95.96 136.81 176.47 65.39
> 21 157.66 70.35 365.48 89.74  96.25 136.60 175.92 65.55
> 22 158.15 70.35 365.48 89.90  96.67 136.24 176.47 65.77
> 23 157.45 68.92 365.48 89.69  96.39 135.53 175.10 65.39
> 24 158.12 69.63 365.48 90.15  97.65 136.24 175.24 65.44
> 25 159.08 69.39 366.03 90.82  99.06 136.81 175.65 65.77
> 26 158.25 70.11 366.57 89.74  97.65 136.24 172.70 65.39
> 27 157.35 69.54 366.57 89.49  96.95 135.60 171.40 65.00
> 28 157.43 69.39 366.57 89.49  96.95 136.24 171.88 65.06
> 29 158.62 70.59 365.48 89.74  98.35 135.53 172.56 65.83
> 30 158.59 71.79 367.66 89.49  98.70 134.24 171.67 65.55
> 31 158.01 72.27 379.12 90.41  98.35 131.96 170.44 65.22
> 32 157.57 71.31 373.66 90.15  98.35 130.89 168.04 65.06
> 
> Thank you very much.
> 
> cu
> Frithjof
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list