⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pbl.m

📁 Permuted Block Randomization 医药临床实验中的随机数的产生; Block可以为定值:2 或者是随机2或4(推荐使用)
💻 M
字号:
%Permutated-Block Randomization%

function x=pbl(r,sample_size)

%sample_size: Number of patients need to be randomized%

%r: if r=1, then we have randomized block sizes:2 or 4;if r=0, we have
%fixed block size equals 2%
M1=[1 1 0 0];
M2=[1 0 1 0 ];
M3=[1 0 0 1];
M4=[0 0 1 1];
M5=[0 1 0 1];
M6=[0 1 1 0];
N1=[0 1];
N2=[1 0];
j=1
if r==0;%r=0,we will use fixed block size equals 2%
    for i=1:sample_size/2;
        v=binornd(1,0.5);
        if v==0;
            x(j)=N1(1,1),x(j+1)=N1(1,2);
        else
            x(j)=N2(1,1),x(j+1)=N2(1,2);
        end
        j=j+2
    end

else
    
    for i=1:sample_size/2;
        w=binornd(1,0.5);
        if w==1;
            v=binornd(1,0.5);
            if v==0;
                x(j)=N1(1,1),x(j+1)=N1(1,2);
            else
                x(j)=N2(1,1),x(j+1)=N2(1,2);
            end
            j=j+2;
        else
            u=unifrnd(0,1);
            if u>=0&&u<1/6;
                 x(j)=M1(1,1),x(j+1)=M1(1,2),x(j+2)=M1(1,3),x(j+3)=M1(1,4);
            elseif u>=1/6&&u<2/6;
                    x(j)=M2(1,1),x(j+1)=M2(1,2),x(j+2)=M2(1,3),x(j+3)=M2(1,4);
                elseif u>=2/6&&u<3/6;
                    x(j)=M3(1,1),x(j+1)=M3(1,2),x(j+2)=M3(1,3),x(j+3)=M3(1,4);
            elseif u>=3/6&&u<4/6;
            x(j)=M4(1,1),x(j+1)=M4(1,2),x(j+2)=M4(1,3),x(j+3)=M4(1,4);
            elseif u>=4/6&&u<5/6;
                x(j)=M5(1,1),x(j+1)=M5(1,2),x(j+2)=M5(1,3),x(j+3)=M5(1,4);
            elseif u>=5/6&&u<=1;
                x(j)=M6(1,1),x(j+1)=M6(1,2),x(j+2)=M6(1,3),x(j+3)=M6(1,4);
            end
            j=j+4;
        end
    end
end
x=x'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -