[Gretl-users] missing value functions for matrices

Allin Cottrell cottrell at wfu.edu
Fri Nov 18 09:47:03 EST 2011


On Fri, 18 Nov 2011, Annaert Jan wrote:

> Is there a reason why functions like missing, misszero and 
> zeromiss are not available for matrices?

Yes, the concept of a "missing value" (gretl's "NA") does not 
apply to matrices. Matrices may contain infinities and NaNs 
(not-a-number) under some conditions, but they can't contain 
NAs. That's because we use straight IEEE arithmetic in matrix 
computations, and while IEEE knows how to handle infinities 
and NaNs it has no notion of NAs.

> The ok function does seem to work with matrices (in contrast 
> to the function reference).

Good point. When a matrix is fed to ok() it works as a 
detector of non-finite values. I'll put that information into 
the function reference.

Note that if you really need it you can construct a function 
to turn non-finite elements of matrix into zeros:

<hansl>
function void matrix_misszero (matrix *m)
   loop j=1..cols(m) -q
     loop i=1..rows(m) -q
       if !ok(m[i,j])
         m[i,j] = 0
       endif
     endloop
   endloop
end function

matrix m = 3*I(2)
m[2,2] = 0/0
print m
matrix_misszero(&m)
print m
</hansl>

Allin Cottrell


More information about the Gretl-users mailing list