📄 bcr.m
字号:
%Biased Coin Randomization%
%Source of Formulas:p9-10,Chapter 6STA 526%
%Three Different candidate versions of Formulas:1)Efron's; 2)Soares&Wu's;
%3)Chen's%
function x=bcr(version,sample_size,v,c);
%version:0:Efron's;1:S&W's;2:Chen's%
%sample_size%
%v: The new specified probability specified in Efron's and Chen's version
%0.5=<v<=1;%
%c:A prespecified constant c;used in S&W's and Chen's version%
if version==0; %Efron's version%
x(1)=binornd(1,0.5);
for i=2:sample_size;
d=(2*sum(x))-(i-1);
if d==0;
x(i)=binornd(1,0.5);
elseif d<0;
x(i)=binornd(1,v);
else
x(i)=binornd(1,1-v);
end
end
elseif version==1;%Soares and Wu's version%
x(1)=binornd(1,0.5);
for i=2:sample_size;
d=(2*sum(x))-(i-1);
if abs(d)<c;
x(i)=binornd(1,0.5);
elseif d==c;
x(i)=binornd(1,0);
elseif d==-c
x(i)=binornd(1,1);
end
end
else %chen's version%
x(1)=binornd(1,0.5);
for i=2:sample_size;
d=(2*sum(x))-(i-1);
if d==0;
x(i)=binornd(1,0.5);
elseif d==c;
x(i)=binornd(1,0);
elseif d==-c
x(i)=binornd(1,1);
elseif d>0&&d<c;
x(i)=binornd(1,v);
elseif d>-c&&d<0;
x(i)=binornd(1,1-v);
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -