시뮬레이션 순서대로 들립니다.
N=100044×2p≤α2×2αNN
α=0.050.28
α
α0.050.010.001error rate∼0.28∼0.06∼0.008
0.05α0.008
Matlab의 빠르고 더러운 코드는 다음과 같습니다. 이 코드는 매우 죽었고 전혀 최적화되지 않았습니다. 모든 것이 루프에서 실행되며 엄청나게 느립니다. 이것은 아마 많이 가속화 될 수 있습니다.
function seqAnalysis()
alphas = [0.001 0.01 0.05];
for a = 1:length(alphas)
falsePositives(a) = trials_run(1000, 1000, alphas(a));
end
display(num2str([alphas; falsePositives]))
end
function outcome = trials_run(Nrep, N, alpha)
outcomes = zeros(1,Nrep);
for rep = 1:Nrep
if mod(rep,10) == 0
fprintf('.')
end
outcomes(rep) = trial(N, alpha);
end
fprintf('\n')
outcome = sum(outcomes);
end
function result = trial(N, alpha)
outcomes = zeros(2,4);
result = 0;
winner = [];
%// adding subjects one by one
for subject = 1:N
group = randi(size(outcomes,2));
outcome = randi(2);
outcomes(outcome, group) = outcomes(outcome, group) + 1;
%// if groups are significantly different
if chisqtest(outcomes) < alpha
%// compare each treatment against the rest
for group = 1:size(outcomes,2)
contrast = [outcomes(:, group) ...
sum(outcomes(:, setdiff(1:size(outcomes,2), group)),2)];
%// if significantly different
if chisqtest(contrast) < alpha
%// check if better or worse
if contrast(1,1)/contrast(2,1) < contrast(1,2)/contrast(2,2)
%// kick out this group
outcomes = outcomes(:, setdiff(1:size(outcomes,2), group));
else
%// winner!
winner = group;
end
break
end
end
end
if ~isempty(winner)
result = 1;
break
end
end
end
function p = chisqtest(x)
e = sum(x,2)*sum(x)/sum(x(:));
X2 = (x-e).^2./e;
X2 = sum(X2(:));
df = prod(size(x)-[1 1]);
p = 1-chi2cdf(X2,df);
end