Registered Member
|
A bit of background to my request. I am writing interfaces to Eigen from R (http://www.R-project.org), a system for statistical computing, using Rcpp (CRAN.R-project.org/web/packages/Rcpp/), a C++ template library for the R internal storage types.
As a first example for such interfaces we usually create a method for least squares fits, including some of the statistical summaries. My current version of the code is
(By the way, those **** in the signature are not really in the code - apparently the software censors submissions and decided to blank out the identifier type, which is an abbreviation of the phrase "symbolic expression" formed from the first letter of the first word and the first three letters of the second word.) For full-rank cases this works as desired (and, by the way, I am quite impressed with the quality and flexibility of the Eigen library). I am not entirely sure that I have the reordering of the standard errors correct but that is a minor point which I will get to in the testing. In the rank-deficient case, an assertion fails in the calculation of Rinv, reporting
I can provide the matrix A and the vector b that generates this example if that would help in creating a test case. Am I doing the calculation of the standard errors, which are the diagonal elements of s^2 * Rinv * trans(Rinv), effectively? The matrix Rinv should be the inverse of the non-singular part of R (i.e. the first r rows and columns). If this is a reasonable way of calculating these values, how can I avoid the assertion failure? To generate Rinv I apply a solve method to an identity matrix. I looked around to see if there is an explicit triangular inverse (like Lapack's dtrtri) but didn't see one. Thanks for creating Eigen and thanks for any advice. |
Registered Member
|
Sorry, I misstated the definition of the standard errors. They are the square roots of the diagonal elements of s^2 * Rinv * trans(Rinv).
|
Moderator
|
hi, the assertion is triggered by this line:
VectorXd se = mqr.colsPermutation() * Rinv.rowwise().norm() * s; because mqr.colsPermutation() is a p x p permutation matrix while Rinv.rowwise().norm() is a rx1 column vector. The pb only occurs when A is not full rank (r<p), but then the residual and standard error are zero anyway, so no need to compute them! |
Registered Member
|
Thank you. Dumb of me not to realize that.
Not quite. One can still calculate the standard errors of the coefficients corresponding to the first r columns of A * mqr.colsPermutation(). Coefficients and standard errors for the remaining columns are not defined. |
Registered Member
|
Of course, first I will need to look closely at the solve method to ensure that coefficients are solved correctly. |
Registered Member
|
Hi GGael
Is there any inbuilt function that one can use to compute the inverse of a triangular matrix? There is the ubiquitous dtrtri from LAPACK which I can use but I would prefer to use something from Eigen if available. Thanks |
Moderator
|
First of all make sure you really need to explicitly compute the inverse, it is often preferable to call solve multiple times. If so, then there is no shortcut, but you can still do something like:
|
Registered Member
|
Indeed, an inverse is the last resort that I would like to use. However, given that inversion can be performed recursively for a large matrix, does it make sense to use some form of recursion to compute the inverse?
|
Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar