home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / bit / listserv / sasl / 5079 < prev    next >
Encoding:
Text File  |  1992-11-17  |  5.5 KB  |  164 lines

  1. Path: sparky!uunet!stanford.edu!bu.edu!olivea!sgigate!sgiblab!swrinde!gatech!destroyer!gumby!yale!yale.edu!news.yale.edu!mars.caps.maine.edu!maine.maine.edu!cunyvm!psuvm!auvm!VM1.YORKU.CA!FRIENDLY
  2. From: FRIENDLY@VM1.YORKU.CA (Michael Friendly)
  3. Newsgroups: bit.listserv.sas-l
  4. Subject: IML bug - MARG function
  5. Message-ID: <SAS-L%92111712044805@VM.UCS.UALBERTA.CA>
  6. Date: 17 Nov 92 18:53:26 GMT
  7. Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. Reply-To: Michael Friendly <FRIENDLY@VM1.YORKU.CA>
  9. Lines: 152
  10. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  11.  
  12. Below is a description of a bug in the SAS/IML function MARG (marginal
  13. sums) that I reported to Tech Support, followed by SAS, SASLOG, and
  14. LISTING files which demonstrate the problem, and show a work-around.
  15.  
  16. I'm copying this to SAS-L, since it demonstrates a useful technique
  17. for reordering the dimensions of multidimensional tables in IML,
  18. which explicitly handles only 2-way arrays.
  19.  
  20. - Michael
  21.  
  22. BUG:  The MARG function in SAS/IML does not accept negative values in
  23.       the <table> argument.
  24.  
  25. Systems tested: 6.06/6.07 (VM/CMS), 6.07 (NeXT)
  26.  
  27. Description:  The SAS/IML documentation describes the conformability
  28.       requirements for the arguments <dim>, and <table> only
  29.       as:
  30.           dim[#] = nrow(table)#ncol(table)
  31.           dim[1:k][#] = ncol(table)   for some k,
  32.       with no restrictions on the values in table.
  33.  
  34.       Although MARG was developed for frequency tables, it is also
  35.       useful for:
  36.        (a) finding marginal sums of *any* multidimensional table,
  37.  
  38.        (b) reordering the dimensions of a multidimensional table.
  39.            This last use is particularly important since SAS/IML
  40.            has no direct way to manipulate multidimensional arrays.
  41.  
  42.   Hence, the test for positive values in <table> should be removed.
  43.  
  44. Workaround:
  45.   For a table with negative values, subtract the minimum value in
  46.   the table before calling MARG, add it back to the result after.
  47. +=============================================== Beginning of MARG SAS
  48. title 'Demonstrate MARG bug';
  49. proc iml;
  50.    reset fw=6;
  51.    table = { 1 2 3 4,
  52.              5 6 7 8};
  53.    dim = {2 2 2};
  54.  
  55.    *-- use marg to reorder the dimensions (turn table inside-out);
  56.    order = {3,2,1};
  57.    run marg(loc,newtab, dim,table,order);
  58.    print 'Reordered table (positive values)', newtab;
  59.  
  60.    *-- marg chokes on values < 0 - this generates an error;
  61.    dev = table - 5;
  62.    run marg(loc,newtab, dim,dev  ,order);
  63.    print newtab;
  64.  
  65.    *-- workaround: subtract min value, then add back in;
  66.    mdev = min(dev);
  67.    run marg(loc,newtab, dim,dev-mdev,order);
  68.    print newtab;
  69.    newtab = newtab + mdev;
  70.    print 'Reordered (w/ negative values)', newtab;
  71. quit;
  72. -===================================================== End of MARG SAS
  73. +============================================ Beginning of MARG SASLOG
  74. 11                                The SAS System 13:15 Tuesday, November 17, 199
  75.  
  76.  NOTE: Copyright(c) 1989 by SAS Institute Inc., Cary, NC USA.
  77.  NOTE: SAS (r) Proprietary Software Release 6.07  TS301
  78.        Licensed to YORK UNIVERSITY, Site 0007019005.
  79.  
  80.  NOTE: Running on IBM Model 4381 Serial Number 012441.
  81.  
  82.  
  83.  1          proc iml;
  84.  IML Ready
  85.  2             reset fw=6;
  86.  3             table = { 1 2 3 4,
  87.  4                       5 6 7 8};
  88.  5             dim = {2 2 2};
  89.  6
  90.  7             *-- use marg to reorder the dimensions (turn table inside-out);
  91.  8             order = {3,2,1};
  92.  9             run marg(loc,newtab, dim,table,order);
  93.  10            print 'Reordered table (positive values)', newtab;
  94.  11
  95.  12            *-- marg chokes on values < 0;
  96.  13            dev = table - 5;
  97.  14            run marg(loc,newtab, dim,dev  ,order);
  98.  ERROR: (execution) Invalid argument to function.
  99. +ERROR: (execution) Invalid argument to function.
  100. +ERROR: (execution) Invalid argument to function.
  101.  
  102.   operation : MARG     at line    14 column   4
  103.   operands  : DIM, DEV, ORDER
  104.  
  105.  DIM           1 row       3 cols    (numeric)
  106.  
  107.        2      2      2
  108.  
  109.  DEV           2 rows      4 cols    (numeric)
  110.  
  111.       -4     -3     -2     -1
  112.        0      1      2      3
  113.  
  114.  ORDER         3 rows      1 col     (numeric)
  115.  
  116.        3
  117.        2
  118.        1
  119.  
  120.   statement : RUN             at line    14 column   4
  121.  15            print newtab;
  122.  16
  123.  17            *-- workaround: subtract min value, then add back in;
  124.  18            mdev = min(dev);
  125.  19            run marg(loc,newtab, dim,dev-mdev,order);
  126.  20            print newtab;
  127.  21            newtab = newtab + mdev;
  128.  22            print 'Reordered (w/ negative values)', newtab;
  129.  23         quit;
  130.  Exiting IML.
  131.  NOTE: The PROCEDURE IML printed page 1.
  132.  
  133.  ERROR: Errors printed on page 1.
  134. +ERROR: Errors printed on page 1.
  135. +ERROR: Errors printed on page 1.
  136.  
  137. 12                                The SAS System 13:15 Tuesday, November 17, 199
  138.  
  139.  NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
  140. -================================================== End of MARG SASLOG
  141. +=========================================== Beginning of MARG LISTING
  142. 1                                 The SAS System
  143.                                                  13:15 Tuesday, November 17, 199
  144.  
  145.                         Reordered table (positive values)
  146.  
  147.              NEWTAB
  148.                   1      5      3      7      2      6      4      8
  149.  
  150.  
  151.              NEWTAB
  152.                   1      5      3      7      2      6      4      8
  153.  
  154.  
  155.              NEWTAB
  156.                   0      4      2      6      1      5      3      7
  157.  
  158.                           Reordered (w/ negative values)
  159.  
  160.              NEWTAB
  161.                  -4      0     -2      2     -3      1     -1      3
  162.  
  163. -================================================= End of MARG LISTING
  164.