我有2个输入变量:
我正在估计每个元素的错误发现率(FDR),p表示如果当前p值(来自p)将是阈值,来自随机排列的p值将经过多少.
我写与ARRAYFUN的功能,但它需要大量的时间用于大N(2 分钟为Ñ = 20K),媲美的for循环.
function pfdr = fdr_from_random_permutations(p, pr)
%# ... skipping arguments checks
pfdr = arrayfun( @(x) mean(sum(pr<=x))./sum(p<=x), p);
Run Code Online (Sandbox Code Playgroud)
任何想法如何让它更快?
关于统计问题的评论也欢迎.
测试数据可以生成为p = rand(N,1); pr = rand(N,M);.
我在互联网上找到了这个Matlab代码.它实际上是整个代码的一部分,可以在这里找到.有人可以逐行解释发生了什么.我真的很绝望......
% ------------- % This is code to make the edge detecting filter % ----%
function filter=gaussfilt(N)
% calculate alpha so the filter fills all N points
alpha=N;
first=-(1-N/2)*exp(-(1-N/2)^2/alpha);
count=0;
while first<.1*(-(1530/4000*N-N/2)*exp(-(1530/4000*N-N/2)^2/alpha))
count=count+1;
alpha=N*500*count;
first=-(1-N/2)*exp(-(1-N/2)^2/alpha);
end
for n=1:N
filter(n)=-(n-N/2)*exp(-(n-N/2)^2/alpha); % d/dt of a gaussian
end
filter=filter/sum(abs(filter)); % normalization
return
Run Code Online (Sandbox Code Playgroud)