Class QRDecomposition

java.lang.Object
ubic.basecode.math.linalg.QRDecomposition

public class QRDecomposition extends Object
QR with pivoting. See http://www.netlib.org/lapack/lug/node42.html and http://www.netlib.org/lapack/lug/node27.html, and Golub and VanLoan, section 5.5.6+. Designed to mimic the way R does this by default.
Author:
paul
  • Constructor Details

    • QRDecomposition

      public QRDecomposition(DoubleMatrix2D A)
      Parameters:
      A - the matrix to decompose, pivoting will be used.
    • QRDecomposition

      public QRDecomposition(DoubleMatrix2D A, boolean pivoting)
      Construct the QR decomposition of A. With pivoting = true, this reproduces quite closely the behaviour of R qr().
      Parameters:
      A - the matrix to decompose
      pivoting - set to false to obtain standard QR behaviour.
  • Method Details

    • chol2inv

      public DoubleMatrix2D chol2inv()
      Used for computing standard errors of parameter estimates for least squares; copies functionality of R chol2inv.
      Returns:
    • effects

      public DoubleMatrix1D effects(DoubleMatrix1D y)
      Compute effects matrix Q'y (as in Rb = Q'y).

      "Tthe effects are the uncorrelated single-degree-of-freedom values obtained by projecting the data onto the successive orthogonal subspaces generated by the QR decomposition during the fitting process. The first r (the rank of the model) are associated with coefficients and the remainder span the space of residuals (but are not associated with particular residuals)."

      Parameters:
      y - vector Missing values are ignored, otherwise assumed to be of the right size
      Returns:
      vector of effects - these are the projections of y into Q column space
    • effects

      public DoubleMatrix2D effects(DoubleMatrix2D y)
      Compute effects matrix Q'y (as in Rb = Q'y)
      Parameters:
      y - matrix of data, assumed to be of right size, missing values are not supported
      Returns:
      matrix of effects - these are the projections of y's columns into Q column subspace associated with the parameters, so values are "effects" each basis vector on the data
    • getPivotOrder

      public IntArrayList getPivotOrder()
      Returns:
    • getQ

      public DoubleMatrix2D getQ()
      Generates and returns the (economy-sized - first p columns only) orthogonal factor Q.
      Returns:
      first p columns of Q
    • getQraux

      public DoubleMatrix1D getQraux()
      Returns:
    • getR

      public DoubleMatrix2D getR()
      Returns the upper triangular factor, R.
      Returns:
      R
    • getRank

      public int getRank()
      Returns:
      rank
    • getTolerance

      public double getTolerance()
    • hasFullRank

      public boolean hasFullRank()
      Returns whether the matrix A has full rank.
      Returns:
      true if R, and hence A, has full rank.
    • isPivoting

      public boolean isPivoting()
      Returns:
      true if pivoting was used (just whether it was set; not whether any actual pivoting happened)
    • solve

      public DoubleMatrix2D solve(DoubleMatrix2D y)
      Least squares solution of A*X = y; returns X using the stored QR decomposition of A.
      Parameters:
      y - A matrix with as many rows as A and any number of columns. Least squares is fit for each column of y.
      Returns:
      X that minimizes the two norm of Q*R*X - B.
      Throws:
      IllegalArgumentException - if y.rows() != A.rows().
      IllegalArgumentException - if !this.hasFullRank() (A is rank deficient). However, rank-deficient cases are handled by pivoting, so if you are using pivoting you should not see this happening.
    • toString

      public String toString()
      Returns a String with (propertyName, propertyValue) pairs. Useful for debugging or to quickly get the rough picture.
      Overrides:
      toString in class Object
    • diagnose

      protected String diagnose()
    • getQR

      protected DoubleMatrix2D getQR()
      For testing.
      Returns: