BookmarkSubscribeRSS Feed
ShufeGuoding
Obsidian | Level 7

Is there any function or algorithm to verity a matrix  is nonsingular in IML? I need if in a "if  then"statement.

2 REPLIES 2
IanWakeling
Barite | Level 11

The function DET returns the determinant of a matrix,  so:

if det(x)^=0 then ......

but you may want to exclude small determinants if whatever you want to do is likely to give stability problems with near-singular x, so something like:

if abs(det(x))>s

where s is some suitable small value.

Rick_SAS
SAS Super FREQ

The problem you describe is equivalent to computing the "rank of a matrix."  A nonsingular matrix is a square matrix that has full rank. Because of finite-precision arithmetic, the rank problem is difficult.  As Ian points out, there are problems with trying to compare a floating-point computation (determinant, eigenvalue, singular value,...) with zero.  Stable rank-detecting algorithms use some variation of Gaussian elimination to determine whether there are linear dependencies in the rows or columns of a matrix.   In SAS/IML, the standard way to detect rank is to compute the generalized inverse (which always exists) and then multiply it by the original matrix.  If you get the identity matrix, then the original matrix was full rank (nonsingular). Otherwise the original matrix is less than full rank.  So to detect singularity, I suggest the following:

A = { /* your matrix to test */ };

matrixRank = round(trace(ginv(A)*A));

if matrixRank < nrow(A) then print "Singular";

else print "Nonsingular";

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1588 views
  • 1 like
  • 3 in conversation