Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Storing infinite confidence intervals in Stata matrices


From   "Salvati, Jean" <[email protected]>
To   <[email protected]>
Subject   st: RE: Storing infinite confidence intervals in Stata matrices
Date   Fri, 10 Feb 2006 11:58:34 -0500

> . matr def matti[2,2]=c(maxdouble)
> 
> . matr list matti
> 
> symmetric matti[2,2]
>            c1         c2
> r1          1
> r2          3  8.99e+307
> 
> Note that, when I try to change one entry of the matrix 
> matti, Stata appears to note that the matrix is square and to 
> do some kind of unsolicited approximate-symmetry test, find 
> the matrix to be approximately symmetric, and then replace it 
> with something exactly symmetric in order to save space.

This seems to be a display issue:

. matrix test = (1,2\3,4)

. matrix list test

test[2,2]
    c1  c2
r1   1   2
r2   3   4

. matrix test[2, 2] = c(maxdouble)

. matrix list test

symmetric test[2,2]
           c1         c2
r1          1
r2          3  8.99e+307


. di test[1,2]
2

Jean Salvati 


> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of 
> Newson, Roger B
> Sent: Friday, February 10, 2006 11:51 AM
> To: statalist
> Subject: st: Storing infinite confidence intervals in Stata matrices
> 
> Fellow Statalisters (especially StataCorp):
> 
> I have a query about Stata matrices (as distinct from Mata 
> matrices). In some of my programs, I store confidence 
> intervals in Stata matrices with
> 1 row per confidence interval and columns containing the 
> point estimates, the lower limits and the upper limits. 
> Sometimes, confidence limits should be plus or minus infinity 
> (eg the Clopper-Pearson CI for the log odds, the Mehta CI for 
> the log odds ratio, the Hodges-Lehmann median difference). In 
> a previous discussion with Nick Cox and Bill Gould in the 
> Stata 6 era, I was advised to use very high-magnitude numbers 
> (+1e+300 or -1e+300) to represent infinite confidence limits.
> Under Stata 9, we presumably might prefer to use plus or 
> minus c(maxdouble), which is approximately 8.99e+307 in my 
> Stata. These can be inserted into Stata matrices, as in the 
> following example (in the 2006/01/20 version of Stata 9.1 
> under Windows XP):
> 
> . matr list matti
> 
> matti[3,3]
>     c1  c2  c3
> r1   1   2   3
> r2   4   5   6
> r3   7   8   9
> 
> . matr def matti[3,3]=c(maxdouble)
> 
> . matr list matti
> 
> matti[3,3]
>            c1         c2         c3
> r1          1          2          3
> r2          4          5          6
> r3          7          8  8.99e+307
> 
> However, last night, I discovered an unexpected feature of 
> Stata matrices, using the following example:
> 
> . matr def matti=(1,2\3,4)
> 
> . matr list matti
> 
> matti[2,2]
>     c1  c2
> r1   1   2
> r2   3   4
> 
> . matr def matti[2,2]=c(maxdouble)
> 
> . matr list matti
> 
> symmetric matti[2,2]
>            c1         c2
> r1          1
> r2          3  8.99e+307
> 
> Note that, when I try to change one entry of the matrix 
> matti, Stata appears to note that the matrix is square and to 
> do some kind of unsolicited approximate-symmetry test, find 
> the matrix to be approximately symmetric, and then replace it 
> with something exactly symmetric in order to save space. The 
> same thing happens when I use the old Stata 6 magic number 
> instead of the new Stata 9 magic number:
> 
> . matr def matti=(1,2\3,4)
> 
> . matr list matti
> 
> matti[2,2]
>     c1  c2
> r1   1   2
> r2   3   4
> 
> . matr def matti[2,2]=1e+300
> 
> . matr list matti
> 
> symmetric matti[2,2]
>            c1         c2
> r1          1
> r2          3  1.00e+300
> 
> This feature has got me worried. Unsurprisingly, it does not 
> seem to be found in Mata matrices, but reappears once the 
> Mata matrix is converted into a Stata matrix. The following 
> example illustrates this feature:
> 
> 
> . mata: mitzi=(1,2\3,4)
> 
> . mata:mitzi
>        1   2
>     +---------+
>   1 |  1   2  |
>   2 |  3   4  |
>     +---------+
> 
> . mata: maggi=st_numscalar("c(maxdouble)")
> 
> . mata:maggi
>   8.9885e+307
> 
> . mata:mitzi[2,2]=maggi
> 
> . mata:mitzi
>                  1             2
>     +-----------------------------+
>   1 |            1             2  |
>   2 |            3   8.9885e+307  |
>     +-----------------------------+
> 
> . mata:st_matrix("muttli",mitzi)
> 
> . matr list muttli
> 
> symmetric muttli[2,2]
>            c1         c2
> r1          1
> r2          3  8.99e+307
> 
> An obvious fix to this feature is to represent infinite 
> confidence limits using Stata missing values, which seem to 
> be allowed in Stata matrices in Stata 9. We might use .a to 
> represent minus infinity and .z to represent plus infinity. 
> The following example demonstrates Stata missing values in 
> Stata matrices:
> 
> . matr def matti=(2,1,3\5,4,6\8,7,9)
> 
> . matr list matti
> 
> matti[3,3]
>     c1  c2  c3
> r1   2   1   3
> r2   5   4   6
> r3   8   7   9
> 
> . matr def matti[2,2]=.a
> 
> . matr def matti[3,3]=.z
> 
> . matr list matti
> 
> matti[3,3]
>     c1  c2  c3
> r1   2   1   3
> r2   5  .a   6
> r3   8   7  .z
> 
> This might be the best solution to the immediate problem. 
> However, these unsolicited symmetry checks seem to raise a 
> more general issue, namely whether we should use Stata 
> matrices in programs to store arbitrary arrays of 
> double-precision numbers, unless we know that these arrays of 
> numbers can never be square. For instance, I might want a 
> Stata program to pass an array of numbers as an option, or an 
> argument, to another Stata program. In these circumstances, 
> is it safer to use Mata matrices rather than Stata matrices? 
> And would it be a good idea to rewrite the Stata programs as 
> Mata programs? (I note that Mata programs can call Stata 
> programs, as well as vice versa - see [M-5] stata().)
> 
> Best wishes (and thanks in advance)
> 
> Roger
> 
> 
> Roger Newson
> Lecturer in Medical Statistics
> POSTAL ADDRESS:
> Respiratory Epidemiology and Public Health Group National 
> Heart and Lung Institute at Imperial College London St Mary's 
> Campus Norfolk Place London W2 1PG STREET ADDRESS:
> Respiratory Epidemiology and Public Health Group National 
> Heart and Lung Institute at Imperial College London
> 47 Praed Street
> Paddington
> London W1 1NR
> TELEPHONE: (+44) 020 7594 0939
> FAX: (+44) 020 7594 0942
> EMAIL: [email protected]
> WEBSITE: http://www.kcl-phs.org.uk/rogernewson/
> Opinions expressed are those of the author, not of the institution.
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index