[R] multiple paired t-tests without loops

Greg Snow Greg.Snow at imail.org
Mon Apr 26 22:53:51 CEST 2010


The usual way to speed up permutation testing is to sample from the set of possible permutations rather than looking at all possible ones.

If you show some code then we may be able to find some inefficiencies for you, but there is not general solution, poorly written uses of apply will be slower than well written for loops.  In some cases rewriting critical pieces in C or fortran will help quite a bit, but we need to see what you are already doing to know if that will help or not.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Matthew Finkbeiner
> Sent: Saturday, April 24, 2010 4:58 AM
> To: r-help at r-project.org
> Subject: [R] multiple paired t-tests without loops
> 
> I am new to R and I suspect my problem is easily solved, but I haven't
> been able to figure it out without using loops.  I am trying to
> implement Blair & Karniski's (1993) permutation test.  I've included a
> sample data frame below.  This data frame represents the conditional
> means (C1, C2) for 3 subjects in 2 consecutive samples of a continuous
> data set (e.g. ERP waveform).  Each sample includes all possible
> permuations of the subject means (2^N), which is 8 in this case.
> 
> The problem: I need to run a paired t-test on each SampleXPermutation
> set and save the maximum t-value obtained for each sample.  The real
> data set has 16 subjects (216 permutations) and 500 samples, which
> leads
> to more than 32 million t-tests.  I have a loop version of the program
> working, but it would take a few weeks to complete the job and I was
> hoping that someone could tell me how to do it faster?
> 
> thank you kindly,
> 
> Matthew Finkbeiner
> 
> --------------------------------
> 
> "Sample"    "C1"    "C2"    "PermN"
> 1    5    8    perm1
> 1    4    3    perm1
> 1    6    4    perm1
> 2    2    6    perm1
> 2    3    1    perm1
> 2    7    4    perm1
> 1    8    5    perm2
> 1    3    4    perm2
> 1    6    4    perm2
> 2    6    2    perm2
> 2    1    3    perm2
> 2    7    4    perm2
> 1    5    8    perm3
> 1    3    4    perm3
> 1    6    4    perm3
> 2    2    6    perm3
> 2    1    3    perm3
> 2    7    4    perm3
> 1    8    5    perm4
> 1    4    3    perm4
> 1    4    6    perm4
> 2    6    2    perm4
> 2    3    1    perm4
> 2    4    7    perm4
> 1    5    8    perm5
> 1    4    3    perm5
> 1    4    6    perm5
> 2    2    6    perm5
> 2    3    1    perm5
> 2    4    7    perm5
> 1    8    5    perm6
> 1    3    4    perm6
> 1    4    6    perm6
> 2    6    2    perm6
> 2    1    3    perm6
> 2    4    7    perm6
> 1    5    8    perm7
> 1    3    4    perm7
> 1    4    6    perm7
> 2    2    6    perm7
> 2    1    3    perm7
> 2    4    7    perm7
> 1    8    5    perm8
> 1    4    3    perm8
> 1    6    4    perm8
> 2    6    2    perm8
> 2    3    1    perm8
> 2    7    4    perm8
> 
> 
> 
> 
> 
> 
> --
> Dr. Matthew Finkbeiner
> Senior Lecturer & ARC Australian Research Fellow
> Macquarie Centre for Cognitive Science (MACCS)
> Macquarie University, Sydney, NSW 2109
> 
> Phone: +61 2 9850-6718
> Fax:   +61 2 9850-6059
> Homepage: http://www.maccs.mq.edu.au/~mfinkbei
> Lab Homepage: http://www.maccs.mq.edu.au/laboratories/action/
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list