[6551] in s-news-athena

home help back first fref pref prev next nref lref last post

New and updated functions installed in statlib

daemon@ATHENA.MIT.EDU (Frank Harrell)
Thu Mar 2 11:28:56 1995

Date: Thu, 2 Mar 1995 10:23:28 -0500 (EST)
From: Frank Harrell <feh@biostat.mc.duke.edu>
Reply-To: feh@biostat.mc.duke.edu
To: s-news@utstat.toronto.edu

Mike Meyer has installed updates to several of my functions as well as
two new function:
----------------------------------------------------------------------
New functions: find.matches, cpower/ciapower (stored under name cpower)

find.matches    Find matches between columns of matrices

This function is useful for drawing matched samples from a reference
sample using exact matching, matching within specified tolerances,
and Euclidean distance matching with specified scale constants.

Example:

       > set.seed(17)       # so can replicate results
       > x <- matrix(runif(500), ncol=2)
       > y <- matrix(runif(2000), ncol=2)
       > w <- find.matches(x, y, maxmatch=5, tol=c(.02,.03))
       > w$matches[1:5,]
            Match #1 Match #2 Match #3 Match #4 Match #5
       [1,]      383        0        0        0        0
       [2,]      710      283      585      143       67
       [3,]      935      343      682       47      659
       [4,]      919      857      491      810      557
       [5,]      558        8      675        0        0
       > w$distance[1:5,]
            Distance #1 Distance #2 Distance #3 Distance #4 Distance #5
       [1,]   1.0160329          NA          NA          NA          NA
       [2,]   0.4180267   0.5695871   0.6080781   0.8480735   1.1498693
       [3,]   0.1263243   0.1358317   0.4338589   0.4425930   0.7466168
       [4,]   0.1120088   0.4246693   0.4630336   0.5731505   0.6278675
       [5,]   0.1407727   0.6417053   1.1753261          NA          NA
       > x[1,]
       [1] 0.9596826 0.6678012
       > y[383,]

       [1] 0.9467001 0.6446666
       > summary(w)
       Frequency table of number of matches found per observation

         0  1  2  3  4  5
        25 59 60 48 34 24

       Median minimum distance by number of matches

               1         2         3         4         5
        0.650781 0.3803045 0.2224013 0.2467452 0.1326343

       Observations selected first more than once (with frequencies)

        5 17 32 185 243 315 383 394 501 535 621 657 708 745 770 817 848 899 
        2  2  2   2   2   2   2   3   2   2   2   2   4   2   2   2   2   2

       # For many applications would do something like this:
       > attach(df1)
       > x <- cbind(age, sex) 
       # Just do as.matrix(df1) if df1 has no factor objects
       > attach(df2)
       > y <- cbind(age, sex)
       > mat <- find.matches(x, y, tol=c(5,0)) # exact match on sex, 5y on age


cpower  - Compute power of two-sample Cox or logrank survival test
ciapower- Compute power of interaction test for exponential survival 
---------------------------------------------------------------------------
Bug corrections: cut2, impute
---------------------------------------------------------------------------
New features:

sas.get: Added uncompress option, sasprog option, where option,
         is.special.miss function, [.special.miss function, 
         print.special.miss,
         sas.codes: prints original SAS codes that were given value
         labels with PROC FORMAT
         Fixed bug in reading very long records when SAS dataset converted
         to ASCII

Note: sas.get still only runs on UNIX.  A couple of MS Windows users have
been experimenting with modifying sas.get to work there.  Will keep you
posted.
 

bystats: Allowed the variable being described to be a matrix
         Added LaTeX support
         Added bystats2 function for printing 2-way tables

Examples:

> a <- rep(1:5,100)
> b <- c(rep(1,200),rep(2,300))
> set.seed(13)
> x <- runif(500)
> table(a)
   1   2   3   4   5 
 100 100 100 100 100
> table(b)
   1   2 
 200 300
> options(digits=2)
> bystats(x>.5, a, b)

 Fraction of x > 0.5 by a, b 

      N Fraction 
1 1  40     0.47
2 1  40     0.42
3 1  40     0.45
4 1  40     0.55
5 1  40     0.47
1 2  60     0.50
2 2  60     0.42
3 2  60     0.57
4 2  60     0.67
5 2  60     0.50
ALL 500     0.51
> bystats(x, a)

 Mean of x by a 

      N Mean 
  1 100 0.49
  2 100 0.46
  3 100 0.53
  4 100 0.57
  5 100 0.49
ALL 500 0.51
> bystats(x, a, fun=quantile)

 quantile of x by a 

      N     0%  25%  50%  75% 100% 
  1 100 0.0050 0.20 0.49 0.72 0.99
  2 100 0.0234 0.21 0.38 0.75 0.98
  3 100 0.0029 0.26 0.53 0.82 1.00
  4 100 0.0103 0.26 0.63 0.82 1.00
  5 100 0.0088 0.21 0.49 0.74 0.99
ALL 500 0.0029 0.22 0.51 0.76 1.00
> bystats(x, a, fun=function(x) c(Mean=mean(x), Median=median(x)))

 c(Mean = mean(x), Median = median(x)) of x by a 

      N Mean Median 
  1 100 0.49   0.49
  2 100 0.46   0.38
  3 100 0.53   0.53
  4 100 0.57   0.63
  5 100 0.49   0.49
ALL 500 0.51   0.51
> x2 <- runif(500)
> bystats(cbind(x,x2), a, fun=function(y) apply(y, 2, quantile, c(.25, .75)))

 quantile of cbind(x, x2) by a 

      N x 25% x 75% x2 25% x2 75% 
  1 100  0.20  0.72   0.23   0.71
  2 100  0.21  0.75   0.31   0.81
  3 100  0.26  0.82   0.24   0.72
  4 100  0.26  0.82   0.25   0.81
  5 100  0.21  0.74   0.29   0.72
ALL 500  0.22  0.76   0.25   0.75
> x[1] <- NA
> a <- cut2(a, c(2,4))    #cut2 in statlib
> bystats2(sqrt(x), a, b, fun=function(x) c(Mean=mean(x), quantile(x)))

 c(Mean = mean(x), quantile(x)) of sqrt(x) by a, b 

+-------+
|N      |
|Missing|
|Mean   |
|  0%   |
| 25%   |
| 50%   |
| 75%   |
|100%   |
+-------+
a    |b
     |1    |2    |ALL  |
-----+-----+-----+-----+
[1,2)| 39  | 60  | 99  |
     |1    |0    |1    |
     |0.64 |0.66 |0.66 |
     |0.071|0.207|0.071|
     |0.44 |0.48 |0.45 |
     |0.66 |0.70 |0.70 |
     |0.84 |0.85 |0.85 |
     |0.99 |1.00 |1.00 |
-----+-----+-----+-----+
[2,4)| 80  |120  |200  |
     |0    |0    |0    |
     |0.67 |0.65 |0.66 |
     |0.057|0.054|0.054|
     |0.50 |0.42 |0.47 |
     |0.69 |0.70 |0.69 |
     |0.87 |0.89 |0.88 |
     |1.00 |1.00 |1.00 |
-----+-----+-----+-----+
[4,5]| 80  |120  |200  |
     |0    |0    |0    |
     |0.68 |0.69 |0.69 |
     |0.169|0.094|0.094|
     |0.47 |0.47 |0.47 |
     |0.73 |0.78 |0.74 |
     |0.83 |0.89 |0.87 |
     |1.00 |1.00 |1.00 |
-----+-----+-----+-----+
ALL  |199  |300  |499  |
     |1    |0    |1    |
     |0.67 |0.67 |0.67 |
     |0.057|0.054|0.054|
     |0.48 |0.45 |0.47 |
     |0.69 |0.73 |0.71 |
     |0.85 |0.89 |0.87 |
     |1.00 |1.00 |1.00 |
-----+-----+-----+-----+


varclus: Added support for formula language, data, subset, na.action
         Added new function naclus, which depicts the similarities
         between variables on which observations are NA

----------------------------------------------------------------------------
Frank E Harrell Jr			feh@biostat.mc.duke.edu
Associate Professor of Biostatistics
Division of Biometry                    Duke University Medical Center
Box 3363 Durham NC 27710 USA
 

home help back first fref pref prev next nref lref last post