[R] inverse of matrix made by low.tri function

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Oct 3 18:02:35 CEST 2007

You missed one very important line:

> library(Matrix)

This is not R, it is package Matrix, and the error is in that package, as 
traceback() shows:

> traceback()
6: sprintf(gettext(fmt, domain = domain), ...)
5: gettextf("not-yet-implemented method for %s(<%s>, <%s>).\n ->>  Ask the 
package authors to implement the missing feature.",
        fun, cl1, cl2)
4: stop(gettextf("not-yet-implemented method for %s(<%s>, <%s>).\n ->> 
Ask the package authors to implement the missing feature.",
        fun, cl1, cl2), call. = FALSE)
3: .bail.out.2("solve", class(a), class(b))
2: solve(XtXu)
1: solve(XtXu)

I also suggest you find out about crossprod().

You don't need package Matrix to do this, and squaring a matrix (XtX) to 
form XtX inverse is not good practice.  (Hint: what are the calculations 
used to find the variance-covariance matrix in a regression?  You are 
effectively doing a Cholesky decomposition of XtX, and how does that 
relate to decompositions of X, e.g. QR and SVD?)

On Wed, 3 Oct 2007, kevinchang wrote:

> Hi all,
> I am using R trying to get a inverse matrix of (X^T)X , but I keep getting
> the error
> message like: no b argument and no default value for sprintf(gettext(fmt,
> domain = domain), ...) .
> --------------------------------------------------------------------------------------------
> # my code
> X<-Matrix(rep(1,500),100,5)
> X[lower.tri(X)]<-1-10^-7
> XtX<- t(X)%*% X
> XtXu<-lu(XtX)
> InverseXtX<-solve(XtXu)
> ---------------------------------------------------------------------------------------------
> The cause suggested for this error is that the lower.tri function returns a
> matrix of logicals. If so, is trying to fix this by using sprintf function a
> good idea ? Or is there is any alternative way to get the inverse matrix?
> Please help. Thanks

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list