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) %*% xError 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 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Frithjof Weinert <mail at weinert.biz> writes:> 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 solveIt means that your matrix is near-singular.> eigen(t(x)%*%x)$values [1] 6.718414e+06 4.166548e+03 3.170856e+02 3.815431e+01 3.324083e+01 [6] 1.370728e+01 1.365406e+00 1.212465e-03 $vectors ... Notice the factor of 5e9 between the largest and the smallest eigenvalue. In fact, you can work around it like this (but the precision will suffer):> solve(t(x)%*%x,tol=1e-10)[,1] [,2] [,3] [,4] [,5] 824.4508915 3.314864820 -0.4763403196 -4.0699637637 0.1052127229 bmw 3.3148648 0.082230914 -0.0025540139 -0.0106190685 -0.0080733381 mru -0.4763403 -0.002554014 0.0006542950 -0.0002472137 0.0008589666 rwe -4.0699638 -0.010619068 -0.0002472137 0.1052825026 0.0162370133 vow 0.1052127 -0.008073338 0.0008589666 0.0162370133 0.0157643276 kar 0.6565594 0.017020959 0.0002213754 0.0144204919 0.0063406071 sie 2.1469705 0.012543437 -0.0013758730 -0.0114628060 0.0019913048 bas -15.0682942 -0.166379673 0.0085819595 -0.0932488883 -0.0619568748 [,6] [,7] [,8] 0.6565593592 2.146970504 -15.06829414 bmw 0.0170209590 0.012543437 -0.16637967 mru 0.0002213754 -0.001375873 0.00858196 rwe 0.0144204919 -0.011462806 -0.09324889 vow 0.0063406071 0.001991305 -0.06195687 kar 0.0264386956 -0.008382337 -0.09138646 sie -0.0083823370 0.019680899 -0.06057200 bas -0.0913864614 -0.060571996 0.93040568 Notice that the problem is partly self-inflicted. You seem to be trying to fit a linear model and lm(), which is designed for the purpose, has no trouble with these data:> summary(lm(index~.,data=dd))$cov.unscaled(Intercept) bmw mru rwe vow (Intercept) 824.4508901 3.314864816 -0.4763403187 -4.0699637528 0.1052127251 bmw 3.3148648 0.082230914 -0.0025540139 -0.0106190685 -0.0080733381 mru -0.4763403 -0.002554014 0.0006542950 -0.0002472137 0.0008589666 rwe -4.0699638 -0.010619068 -0.0002472137 0.1052825026 0.0162370133 vow 0.1052127 -0.008073338 0.0008589666 0.0162370133 0.0157643276 kar 0.6565594 0.017020959 0.0002213754 0.0144204919 0.0063406071 sie 2.1469705 0.012543437 -0.0013758730 -0.0114628060 0.0019913049 bas -15.0682941 -0.166379673 0.0085819595 -0.0932488885 -0.0619568748 kar sie bas (Intercept) 0.6565593623 2.146970499 -15.06829413 bmw 0.0170209590 0.012543437 -0.16637967 mru 0.0002213754 -0.001375873 0.00858196 rwe 0.0144204919 -0.011462806 -0.09324889 vow 0.0063406071 0.001991305 -0.06195687 kar 0.0264386956 -0.008382337 -0.09138646 sie -0.0083823370 0.019680899 -0.06057200 bas -0.0913864614 -0.060571996 0.93040568 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._