Download A SAS Macro for Generating Patient/Subject Random Allocation Schedules

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
Transcript
A SAS MACRO FOR GENERATING PATIENT/SUBJECT RANDOM ALLOCATION SCHEDULES
James A. Bolognese, Merck Sharp & Oohme Research Laboratories
ABSTRACT
A SAS macro to generate random allocation schedules of sequential patient/subject numbers for
blocked or unblocked studies in clinical/preclinical trials with any number of crossed factors
is presented. The rank transformation is used
with SAS' UNIFORM function to produce a nicely
formatted allocation schedule. The theoretic
justification of the
II
Example 1. Suppose we need a random allocation
schedule for a total of 12 experimental units
which are to receive 1 of 3 treatments. We want
blocks of size 6 and the allocation numbers (ANs)
to start with I. Table 1 shows the results of
executing the algorithm with n =12~ t =3, b =6
and s = 1 as described.
randomness" of the rank
Table I:
transformation is given and verified by a Monte
Carlo example. In addition, examples of the use
of the macro are presented.
Illustration of Random AllocationA1gorithm with n -12, t st 3 t b =6$ and s =1.
, , •
,
, ,
,
, ,
10 11 12
5
6 1 8
.87 .43 .73 .57 .03 .41 .63 .81 .11 .SS .58 .0'
1 1
Block(j) 1 1
1
2
2 2
3
2 4
5
6
1
6
3
5 4
'(X i )
3
3
Group(k) I
3
3
1
1
,
x.
I NTROOUCTION
In carrying out research studies in which many
experimental units (patients, subjects, etc.) are
given various treatment~, a random allocation
schedule assigning experimental units to treatments is needed. The experimental units entering
a study are sequentially assigned identification
numbers which have been randomly associated with
each of the treatments. A study of n experimental units and t treatments (such that n is a multiple of t) requires nIt of the numbers 1, 2, ... ,
n randomly assigned to treatment group 1, nit
assigned to treatment group 2, etc. Studies are
often blocked by certain factors which require
each subgroup of size b (such that n isamultip1e
of band b is a multiple of t) to be equally divided among the t treatments.
,
AN
S
3
5
4
2 10 11
8 12
In order to assure that this algorithm yields a
truly random allocation schedule, we must show
that the probability of any particular schedule
given n, t, b, and s is themultipHcative inverse
of the number of possible schedules. Without
1055 of generality we can take s =1 since the
schedule for any s is the same as the schedule
for s = 1 with s -I added to each AN. Also, we
can take b=nsince the algorithm applies to the
rank-order-transformation identically within each
block. Therefore, all we need show is that given
a random sample of size n from the uniform distribution on (a.l), the probability of any given
rank-order occurring is the same as that of any
other rank-order occurring. i.e.
,rtr.
It can easfly be proved by induction that
~3
"')0
(X2
}o
dx,
dX2 •••
ALGORITHM
= (xnJ
The random allocation SChedule described above
can be obtained by first generating a random
sample of size n from the uniform distribution
on the Interval (0,1). Call these observations
Xl' X2, .•. tXn where the subscript indicates the
order in which they were drawn. For each of the
nib groups of size b, rank the b crbservations obtaining R(XI + l)' R(Xi + 2),· .. ' R(Xi + b) where
i =(j-I)· b and j=1,2·, ..• ,,~. Assign the allocation numbers (s -1) + R(xir+j·b to group k
I1here i =1,2, ... ,n, j =(1 +the integer part of
~ and k = (1 + the integer part of
- 1 -
l7t-
,
THEORETICAL JUSTIFICATION
Summarizing the problem, we need to generate a
random allocation schedule for n experimental
units in t groups blocked in groups of b, where
n is a multiple of t,
n is a multiple of b. and
b is a multiple of t.
Furthermore, we_~ish to start the allocation numbers with integer s and increase them sequentially to 5 + n - 1.
~,
,
n!
n
la
o·
tI)
Taking a =1, equation (I), is equivalent to
P(X, < x, < ... < xn): liT' The probability of
any rank-order is ~ by appropriatel,)' changing
the order Qf the xi"S in equation 0).
EMPIRICAL JUSTIFICATION
Since a random sample from a uniform distribution
yields a random rank~order of the sample, the
randomness of allocation schedules generated by
the algorithm described above depends on that of
the uniform samp1 e obtained (from SAS function
UNIFORM). In order to empirically justify that
the algorithm yields random allocation schedules,
a Monte Carlo experiment was run.
1) • b).
Thus, the allocation schedule is complete with
the first b units equally and randomly divided
among the t treatments, the second b units are
likewise divided, .the third, etc. Example 1
illustrates the algorithm.
A random sample of size 4 from the uniform distribution on (0,1) has a total of 24 possible
528
rank-orders: 1234,1243,1324,1342, ... ,4312,4321.
these are equally likely. To verify this empirically, 500 goodness of fit chi squares with 23
The call for ALLOC must be moved to follow the
title statement (see DISPLAY 1). When titles are
used, the user should use "OPTIONS NOCENTER;"
prior to calling ALLOC because ALLOC does not center Its output.
degrees of freedom were each ca lculated from counts
of the rank-orders resulting from 24 random samples of size 4 from SAS UNIFORM function. These
500 chi squares represented a random sample from
Note that this macro provides only balanced allocation SChedules, therefore. the following restrictions apply:
the chi square distribution· with 23 degrees of
freedom and were tested for goodness of fit, Ho:
23, and Ho: a Z = 46 (reca 11 that the mean and
variance of the chi square distribution are the
d.f. and twice the d.f., respectively). This was
done for 10 sets of 500 such chi squares. Some
tail categories of the goodness of fitch; squares
were trimmed because they severely inflated the
chi square. In each of the 10 runs, the fit was
very good except in the extreme upper tail categories in some cases (categories were 1, 2, 3,
.•• , max chi square observed). All means were
not significantly different (p > .05) from 23,
and only 1 of 10 variances was significantly
different (p < .05) from 46. The monte carlo
results are shown in Table 2,
" =
Table 2:
Ron ....L
23.5
~
L
10
"'An
in upper tail
3
S
9
The macro is listed in lines 100-8500 of DISPLAY
1 and contains documentation of the programming
conventions. Lines 8600-9000 of DISPLAY 1 give
samples of user added instructions for examples
of schedules. DISPLAY 2 shows the random allocation schedules that result from execution of
the SAS program in DISPLAY 1.
ACKNOWLEDGEMENTS
I am grateful to TOM COOK for pointing out the
reason for an error 1 had made in my initial
monte carlo verification of the algorithm. I
also thank MAR KERSTEN for her typing this manuscript and the preliminary draft.
Monte Carlo Results
.13 55.5
23.3 >.2:5 43.1
23.0 >.25 45.S
23,0 >.25 50.9
23.2 >.25 44.2
23.1 >.25 46.4
22.S >.25 47.2
n.l >.25 48,1
23.6
.06 45.S
22.7 >.25 44.5
4
5
6
7
1) n must be a multiple of t,
2) n must be a multiple of b, and
3) b must be a multiple of t.
~
.001
>.25
>,25
.09
>.25
>.25
>.25
>,25
>.25
>.25
p: Goodness
of Fit
.61
.31
.13
.29
.36
.24
.21
Tail C!tegories
Excluded*
.44
0
0
.24
.15
5
0
2
REFERENCE
0
Barr, A. J., et. a1. (1979). SAS User's Guide,
1979 Ed., SAS Inst. Inc., Raleigh, N.C.
2
1
1
This empirical evidence gives us confidence that
the use of the SAS UNIFORM function and the algorithm ~resented herein will yield valid random
allocation schedules in practice.
USER'S INSTRUCTIONS
The SAS macro ALLOC is used to generate random
allocation schedules as described above. Following the macro in a SAS program, the user need
only add one line of SAS instructions for each
schedule desired. The line to be added is
(lATA AltOCIN; S,.
s.
N "'n; T '" t; 8S ,. b; NAPl,.l; OUTPUT; Allot
where
s = the smallest allocation number desired (the
starting number),
n = the total number of allocation numbers required,.
t = the number-of treatments (groups),
b = the block size-(number of allocation numbers
per block)-;- and
1 = the number of allocation numbers to be printed
per Tine of output.
For subsequent allocation schedules, this line
can be repeated once for each additional schedule
desired. If titles are needed, they Can be inserted immediately following the added line.
529
DISPLAY 2
DrSpLA Y 1
MACRO Allot
~ATA
AlLOtI»; SET AlLOCIN'
•* THIS MACRO PRODUCES BALANCED RANDOM ALLOCATION SCHEDULES.
INPUT IS A DATASET ALLOCIN ~ITH ONE OBSERVATION AND 4 VARIABLES
IN THIS OROER! S=SrARTIHG ALLOCATION NUMBER (AN)
H=NVNCER OF AN'S NEeDEO
T=NUMBER OF TREATMENT GROUPS
e5"'BLOCK SIlE
.•
;
NAPL=NUH6ER Of AN'S PRINTEn peR LINE OF OUTPUT
tHE REMAINING COMMENTS DOCUMENT THE PROGRAM
* CHEeK
FOR IMBALANCEO INPUT, seT ERROR FLAG. AHD WARN USER
.;
IF tlAPLJ:1) THEN HAPl=tVT; IF t100tN,Tl HE 0 THEN 00; FLAG"'!>
PUT 'ERROR! N NOT A MULTIPLE Of T. TRY AGAIN'; END;
IF flOO(N,BS) HE 0 THEN 00; FLAG=l;
PUT 'ERROR: N NOT A MULTIPLE Of 65. TRY AGAIN'; ENO;
IF HOO(8S.T) HE 0 THEH DO; FLAG:l;
PUT 'ERROR: 55 NOT A MULTIPLE OF T. TRY AGAIN'; EHO;
PROC MATRIX; FETCH Z DATA=ALLOCIN;
•* IF
ERROR FLAG SET, SKIP CALCULATIONS. GO TO NEXT STEP
• SET PARAMETERS
*
.;
N=Ztl.2); T=Z(1.31; eS=Z(1.4); HB=N#/BS; MAPL%Z(l.S);
A.%Jtl,N,O);
S=Z~l,l);
•* GENERATE
00 I
o
*
.;
=1
AI1~I)=UNIFORM(O);
00003200
0()003300
00003400
000035-00
000:03-600
00003701
END;
RANK WITHIN EACH BLOCK AND MAKE AN'S
ooonaoo
DO I ,. 1 TO MS; INDEX::::«{ -1)1I6S*1);(111BSI1;
A!l,INDEX)=(tI-l)#BS)+RANKtA(l.INDEX)); END;
•* ASSIGN
.;
STARTING NUNBER ANtI ORDER THE AN'S
c:; }::::)'?OO
FOR OUTPUT
A=S-l+SHAPEIA,TI;
DO I = 1 TO NCOLIA); RA=RANK{A<*.!)l; ~At*.I);
DO K = 1 TO NROW{AI. A(RAIK.1J.I)=B(K,1J; END; END;
•* RESHAPE INTO VECTOR
.;
A~SHAPEtA'>l).
FOR OUTPUT AND
CALC MAX DIGITS PER AN
NAPl~~iNROW(A}.l.NAFL);
NPT~J(~ROW(A}>l~(N#IT)'
H=INTCO+00000001+LOG10IMAX(A))); MP=J(NROWiA),l,Hl;
•* FORM OUTPUT HATRIX WITH CONTROLS AND
.;
.
•
OUTPUT
f~R
PRINTING
A=NPTtINAPLjIAIIHP; OUTPUT A OUT=AllOCOUT;
-* IF ERROR FLAG SET. OUTPUT ERROR FLAG TO PRINTING SECTION
EXIT: IF Z(1,6)=1 THEN DO; E=JI1.4.1); OUTPUT E OUT=ALLOCOUT; END;
DATA _NUlL_' SET AlLOCOUT;
•* IF
.;
ERROR FLAG SET. DON'T PRINT
oooo~eoo
IF COLl=l THEN STOP; fILE PRINT;
•
f
l
I
I
I
I
OOl}04000
000-04100
00004200
000'04300
00004400
00130'4500
00004600
00004700
00004800
000.049DO
00005000
00005100
00005200
000"05300
0000'5400
00005500
00005600
00005100
000'05800
OOC05900
00006000
00006100
00-006300
00006400
* PRINT HEADING FOR EACH TREATMENT GROUP
00006500
00006600
IF MOO{{COLl+_N_-l).COll'=O THEN 00;
00(;06700
G=(COL1+_N_~1}/COL1; PUT // ~l 'GROUP' ~7 G ~lQ lC~'-'; END.
00006800
o
00006'100
* CALC NUHBER OF SPACES TO SKIP FOR UNIFORM PRINTING Of AN'S
00007000
.;
00007100
M=COL4-INT(O.OGOOOOl+LOG10(COL3)l;
00007200
00007300
* CHECK FOR FIRST AN IN EACH TREATMENT GROUP AND SET COUNTER
0'0007400'
.;
00007500
IF HOOt1COll+_N_,.COL1'=O THEN N=-1;
00007600
00007700
* PRINT AN EITH PUT STMT DEPEN~ING ON NUMBER Of AN'S PER LINE OF OUTPUT 000'07800
.;
00007900
N+l; IF N HE COL2 THEN PUT +H caL3 ~;
00008000
ELSE DO; PUT +M COll ; N=O; END; RETAIN Hi
00008100
00"0082:00
* DELETE DATASETS TO CLEAR WORK SPACE
00008300
.;
00008400
PROC DELETE OATA=ALLOCIH-ALtOCOUT;
?
0000850'0
OPTIO~S NOCENTER'
00006600
DATA ALLoelN; 5=1; »=12. T=3; 85=0; NAPL=2, OUTPUT;
00008700
TITLEl ALLOCATION SCHEOULE; TITlE2 FOR EXAMPLE 1; .LlOC
00'008800
D4TA ALlOCIN; selOl; N=lS0j T=S; BS~lO; HAPl=lO; OUTPUT;
00006900'
TITLEl ANOTHER EXAMPLE; TITlE2 S=101 N~15U T=5 B5=10 HAPl=1U; ALLOC
00009000
.•
~
00001900
00002:000'
00002100
00002200
00002300
00002400
00M2S00
00002600
000'02700
00002800
00002900
0(0031)00
OOOO:UOO
RANOOK SAHPlE FROM UNIFORH (O,l}
TO N;
ALLOCATION SCHEDULE
FOR EXAMPLE 1
GROUP 1
3
•
•
530
•
10 11
GROUP 2
4 •
----------
8"
GROUP 3
1 2
OOOOlSOO
IF Z(l.o)=l !HEN GO TO EXIT;
.;
00000100
00000£00
00000300
(1)000400
00000500
00000600
00000700
00000800
00000900
00001000
00001100
00001Z00
00001300
00001400
00001500
00001600
00001700
7
ANOTHER EXAMPLE
S=101 N=150 T=5
•
6S~lO
HAPl=10
GROUP 1 ---------104 107 III 116 124 128 133 135 145 150
156 ISS 165 167 171 Ian 181 183 192 200
206 208 211 220 223 227 235 236 242 249
GROUP 2
-~~--~--~-
". ,.,
106 110 HS 120 '21 123
141 146
157 160 162 16-6 174 176 '82 198 194 197
202 210 217219 225 228 Z3' m 241 2:44
----------
GROUP 3
101 105 113 119 129 130 137 13-9 144 148
153 159
16917$ 179 185 la7 In 1911
203 2n7 21S 218 22.1 226- 233 240 243 245
".
GROUP 4
103 109 112 114 12:5 126 132 138 142 149
lSI 152 16-4 170 175 177 l~ 186 196 19<)
205 209 212 214 222 224 234 238 £47 250
GROUP 5
102 106 115 117 122 127 131 134 143 147
154 155 161 163 172 173 188 189 193 195
201 20:4 213 216 229 230 237 239 246 248