[R] solve() doesn`t work
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Wed Jun 19 17:25:52 CEST 2002
On Wed, 19 Jun 2002, Achim Zeileis wrote:
> Frithjof Weinert wrote:
> >
> > 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.
However, solve on X'X is a poor way to invert a cross-product, introducing
enough problems that I would not want to reduce the tolerance.
Taking the SVD of X and constructing (X'X)^{-1} from it is perhaps the
best way, but see also chol2inv (and, hint, the Choleski decomposition of
X'X can be found directly from X).
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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