Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:05:11+00:00 2026-05-29T08:05:11+00:00

I have 2 input variables: a vector of p-values ( p ) with N

  • 0

I have 2 input variables:

  • a vector of p-values (p) with N elements (unsorted)
  • and N x M matrix with p-values obtained by random permutations (pr) with M iterations. N is quite large, 10K to 100K or more. M let’s say 100.

I’m estimating the False Discovery Rate (FDR) for each element of p representing how many p-values from random permutations will pass if the current p-value (from p) will be the threshold.

I wrote the function with ARRAYFUN, but it takes lot of time for large N (2 min for N=20K), comparable to for-loop.

function pfdr = fdr_from_random_permutations(p, pr)
%# ... skipping arguments checks
pfdr = arrayfun( @(x) mean(sum(pr<=x))./sum(p<=x), p);

Any ideas how to make it faster?

Comments about statistical issues here are also welcome.

The test data can be generated as p = rand(N,1); pr = rand(N,M);.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:05:12+00:00Added an answer on May 29, 2026 at 8:05 am

    Well, the trick was indeed sorting the vectors. I give credit to @EgonGeerardyn for that. Also, there is no need to use mean. You can just divide everything afterwards by M. When p is sorted, finding the amount of values that are less than current x, is just a running index. pr is a more interesting case – I used a running index called place to discover how many elements are less than x.

    Edit(2): Here is the fastest version I come up with:

     function Speedup2()
        N = 10000/4 ;
        M = 100/4 ;
        p = rand(N,1); pr = rand(N,M);
    
        tic
        pfdr = arrayfun( @(x) mean(sum(pr<=x))./sum(p<=x), p);
        toc
    
        tic
        out = zeros(numel(p),1);
        [p,sortIndex] = sort(p);
        pr = sort(pr(:));
        pr(end+1) = Inf;
        place = 1;
        N =  numel(pr);
        for i=1:numel(p)
            x = p(i);
            while pr(place)<=x
                place = place+1;
            end
            exp1a = place-1;
            exp2 = i;
            out(i) = exp1a/exp2;
        end
        out(sortIndex) = out/ M;
        toc
        disp(max(abs(pfdr-out)));
    
    end
    

    And the benchmark results for N = 10000/4 ; M = 100/4 :

    Elapsed time is 0.898689 seconds.
    Elapsed time is 0.007697 seconds.
    2.220446049250313e-016

    and for N = 10000 ; M = 100 ;

    Elapsed time is 39.730695 seconds.
    Elapsed time is 0.088870 seconds.
    2.220446049250313e-016

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set my default-input-method variable to english-dvorak: (custom-set-variables '(default-input-method english-dvorak)) When I launch
I have input and output variables assigned to a function definition to grab entries
I have a converter which has a couple of input variables (an object and
I have written a function that takes the names and values of the input
I have a hidden input variable called str. I am assigning abc value to
I have input fields, which I process with AJAX and send it on another
Currently I have Input: e.g., '123456789'.'+'.'987654321' Desired Pattern: Output: e.g., '123456789987654321' How can I
I have an arraylist set up. I have input instuctions set up too, so
How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
We have some input data that sometimes appears with &nbsp characters on the end.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.