[R] eliminate t() and %*% using crossprod() and solve(A,b)

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Wed 05 Oct 2005 - 20:19:43 EST


I have a square matrix Ainv of size N-by-N where N ~ 1000 I have a rectangular matrix H of size N by n where n ~ 4. I have a vector d of length N.

I need X = solve(t(H) %*% Ainv %*% H) %*% t(H) %*% Ainv %*% d


H %*% X.

It is possible to rewrite X in the recommended crossprod way:

X <- solve(quad.form(Ainv, H), crossprod(crossprod(Ainv, H), d))

where quad.form() is a little function that evaluates a quadratic form:

  quad.form <- function (M, x){

         jj <- crossprod(M, x)
         return(drop(crossprod(jj, jj)))

QUESTION: how to calculate

H %*% X

in the recommended crossprod way? (I don't want to take a transpose because t() is expensive, and I know that %*% is slow).

Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Oct 05 20:34:04 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:36 EST