BookmarkSubscribeRSS Feed
renc
Calcite | Level 5

I did an EM-algorithm for latent variable model with missing biomarkers and coviates in SAS IML. There is an overflow error in the DET of a 159X159 matrix. I have to use Log-likelihood function(LF) to control the iteration times and it includes the determinant.

What are the possible approaches to solve this problem?

Thanks for any help in advance!


4 REPLIES 4
Rick_SAS
SAS Super FREQ

The determinant is a polynomial in the entries, and is therefore known to be unstable for large matrices.

Are you using the determinant to find out if a matrix is singular? If so, there are better (more stable) ways to determine singularity.

Or does the determinant appear in the LL formula and you need to compute it explicitly? If so, compute the log-determinant (which should be stable) and exponentiate, assuming the log-det is less than CONSTANT('LOGBIG').

Is the matrix positive definite (a correlation or covariance matrix)?  If so, you can compute the log-det as follows:

Let G = root(A) be the Cholesky root of the matrix A.

Then log(det(A)) = log(det(G`*G)) = log(det(G`)*det(G)) = 2*log(det(G))

Since G is triangular, det(G) = prod(diag(G)) and therefore log(det(G))=sum(diag(G)).

So your formula for log(det(A)) is 2*sum(log(diag(root(A)))).  In SAS/IML you would use the VECDIAG function to get the diagonal elements of a matrix.

Message was edited by: Rick Wicklin

renc
Calcite | Level 5

Thank you, Rick. The idea is very good and helpful. The formula might be log(det(A))= 2*log(det(root(A))). If det(root(A)) is still overflow, we may need to use all eigenvalues of A to calculate the log(det(A)).

Rick_SAS
SAS Super FREQ

You're free to try it, but computing det(root(A)) is only a minor improvement over det(A). The whole point is to get rid of det(LargeMatrix).

Rick_SAS
SAS Super FREQ

Rats, I omitted a 'log' in the final formula, which is probably what confused you. I will edit my original post to correct it.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1185 views
  • 1 like
  • 2 in conversation