📄 psp.m
字号:
%The Pocock-Simon Procedure %
%SOURCE OF FORMULAS:p12-13,Chapter 6,STA 526%
%This codes will randomize patients according to the the levels of
%stratification factors associated to them%
% Tag=1:Treatment%
% Tag=0:Placebo%
function R=psp(factor1,factor2,x,c);
%factor1: Number of levels of factor 1%
%factor2: Number of levles of factor 2%
%x:Data set contains the information of patients%
%c:constant specified in the formula,0.5<c<=2%
theta=(c+1)/3;
%Step 1:Creating an Index Table%
k=0;
for i=1:factor1;
for j=1:factor2;
Q(i,j)=k+j;
end
k=i*j;
end
%Step 2:Randomize the patients to either treatment or
y(2,factor1*factor2)=0
y(1,Q(x(1,1),x(1,2)))=-1+2*binornd(1,0.5); %if y(i,j)=1, then it is considered randomized to treatment, 0 placebo%
R(1,1)=x(1,1);
R(1,2)=x(1,2);
R(1,3)=(y(1,Q(x(1,1),x(1,2)))+1)/2
for i=2:size(x,1);
M=sum(y)
for j=1:factor2;
term(j)=M((x(i,1)-1)*factor2+j)
end
D1=sum(term);
for j=1:factor2;
term(j)=M(x(i,2)+(j-1)*factor2)
end
D2=sum(term);
D=D1+D2;
if D<0;
y(i,Q(x(i,1),x(i,2)))=-1+2*binornd(1,theta);
R(i,1)=x(i,1);
R(i,2)=x(i,2);
R(i,3)=(y(i,Q(x(i,1),x(i,2)))+1)/2;
elseif D>0
y(i,Q(x(i,1),x(i,2)))=-1+2*binornd(1,1-theta);
R(i,1)=x(i,1);
R(i,2)=x(i,2);
R(i,3)=(y(i,Q(x(i,1),x(i,2)))+1)/2
else
y(i,Q(x(i,1),x(i,2)))=-1+2*binornd(1,0.5);
R(i,1)=x(i,1);
R(i,2)=x(i,2);
R(i,3)=(y(i,Q(x(i,1),x(i,2)))+1)/2;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -