Related Links:
Random Numbers Generation Program Page
Introduction
Examples
References
Random numbers are widely used to model random events, but truly random
numbers are difficult to obtained, requiring random events observed in nature,
such as the time interval between radio statics or lightning strikes.
For most purposes in medical research, that level of randomness is unnecessary,
and computer generated pseudorandom numbers are used.
Types of random numbers
The program in Random Numbers Generation Program Page
generates 4 types of random numbers in common use.
 Random real numbers are real numbers, evenly distributed, with values between 0 and 1.
 Random normally distributed numbers are real numbers with a normal distribution, it's mean and Standard Deviation
nominated by the user
 Random integers are whole numbers, within a range defined by the user.
 Random integers in blocks are blocks of integer numbers. The range within each block is defined by the user, but the
order of the numbers are randomized.
How random numbers are generated
Pseudorandom numbers are generated by computer programs. The program ensures
that the numbers generated do not form any pattern, that the value of each number
is not dependent or influenced by the numbers already generated, and that
the sequence of numbers is not repeated during use. StatTools uses the Ran3 algorithm
described in the Numerical Recipes (see reference). This algorithm has a long nonrecurring cycle, and when provided with
the same seed will generate the same sequence of random numbers.
Use of random numbers
Random real numbers, and random normally distributed numbers are often used to model
numerical systems that depends on random occurrences. Examples of these
are weather and climate models, economic models, movement of share prices,
and so on. Most examples of data presented by StatTools are generated by random numbers.
Random integers and integers in blocks are used more frequently in medical research,
and these will be discussed in greater details in the examples section.
Balanced random numbers
Standard random number sequences requires that the value of each number generated
is independent of all the numbers previously generated. In random integers
within a specified range, this means that all the numbers within the range
have an equally chance of appearing on each occasion. This model represents
true randomness, and resembles picking a numbered marble out of a barrel, and
replacing it before taking another pick.
Although the standard model provides true randomness, an even distribution of all
possible numbers only occurs in a very large sequence, and in the usual volume
of subjects in an average medical research project, where 50100 subjects
are used, the sample size between the groups may be different, and becomes a
source of bias.
There are also some research models, such as complex analysis of variance, where
the mathematics is based on an assumption of equal sample size in all groups and
subgroups, so discrepancies in group size may become problematic.
An alternative is to provide random numbers that have balanced allocations, so that
all numbers within the range are equally represented in the final sequence.
This type of random number is usually generated by using an array of numbers,
containing one number each within the range, and use the random number generator to
create a random order within that array. This model resembles picking a numbered
marble out of a barrel, but not replacing it before picking another.
The advantage of the balanced model is the assurance that sample size in groups
and subgroups are the same (balanced), and this reduces possible bias and error caused
by group size discrepancies. However, by the very nature of being balanced,
that each group will in the end be the same size means that, once a number is allocated,
it will be less likely to be allocated again until the other possible numbers are allocated
to the same frequency. True randomness is therefore lost.
In the practical situation, with a reasonably large sample size, the minor
loss of randomness, particularly if this loss is blinded to researchers and subjects,
will cause very little bias, and may be preferred, particularly in situations where
balanced group and subgroup size are essential to complex statistical analysis.
1 :Random Sampling
2. Random Allocation
3. Balanced Allocations
4. Cross over Studies
5. Paired Comparisons
We wish to study treatment for headaches, and wishes to select a sample of
subjects from those attending a headache clinic. To avoid bias, we wish to
have subjects from different days of the week. We know that, on average
we have 20 patients a day, and we wish to select 1 in 5 from each day.
For each day, we generate 20 random integer numbers with a range of 0 to 4,
such as the following
3 1 2 1 2 3 2 0 2 4 2 1 4 4 1 4 0 2 1 1
Before seeing these numbers we can predetermined which number we will use as
an index to select the cases. If we, say, decided to use the number 2, then
the third, fifth, seventh, ninth, and sixteenth patient will be selected.
If we, say, predetermined using 0, then only the eighth and seventeenth cases
will be selected on that day.
Using different sequences and predetermined indices for selection on different
days, an average of one in 5 cases will be randomly selected for the study.
This type of random selection is frequently used in population surveys or in market
research. For example, names in a phone book grouped according to suburbs, and
a random sample of 1 in 100 in each suburb may be selected in a telephone survey.
We wish to study which of the two headache powders (A and B) is better, and decided
to conduct a randomised controlled trial using 3 groups, A and B for the two
powders, and P for a placebo. We decided to use 60 cases, and want to know how
we allocate the cases to the groups as they are recruited.
We set the range as 0 to 2 (3 groups), and generated the following sequence.
111012101211220201100210220101201200122200122022012000201120
If we predetermined that we will assign to P for 0, A for 1, and B for 2, then the sequence of allocation is as follows.
AAAPABAPABAABBPBPAAPPBAPBBPAPABPABPPABBBPPABBPBBPABPPPBPAABP
The first 3 subjects will be in group A, the fourth P, the fifth A,
the sixth B, and so on.
Please note that, as each number is allocated independent to previous allocations,
there are equal chances for any of the 3 numbers to be allocated to each
slot. Consequently, the numbers allocated to each group may not be the same
(they will increasingly be the same only as sample size increases). In this sequence,
there are 21 Ps, 19 As, and 20 Bs.
We wish to conduct the same randomised controlled trial, but wish to have equal sample size in all 3 groups. We set
the created a single block of 60 numbers, ranging 1 to 60 in random order, and obtain the following sequence.
39 21 25 15 33 48 24 08 37 54 26 22 55 52 16 57 03 29 23 13 07 53 34 19 47 50 04 40 02 36
51 06 35 46 12 14 27 44 60 59 05 01 32 49 45 09 42 41 11 20 56 17 18 28 43 10 31 38 58 30
In this sequence, we have 1 each of numbers from 1 to 60. We now take the
modulo 3 of these numbers (divided by 3 and take the remainder), and obtained
the following sequence.
0 0 1 0 0 0 0 2 1 0 2 1 1 1 1 0 0 2 2 1 1 2 1 1 2 2 1 1 2 0
0 0 2 1 0 2 0 2 0 2 2 1 2 1 0 0 0 2 2 2 2 2 0 1 1 1 1 2 1 0
When this is translated into allocation (0=P, 1=A, 2=B), the following sequence is obtained.
P P A P P P P B A P B A A A A P P B B A A B A A B B A A B P
P P B A P B P B P B B A B A P P P B B B B B P A A A A B A P
This is also a random sequence of allocation, but there are 20 for each group.
This is a powerful research model, based on providing to each subject all of
the treatments on different occasions, and use the differences
in response within each subject as the outcome measurement.
To avoid bias, the order of the treatment is randomised. As each treatment
may have a possible hang over effect which may influence the response to the
next treatment, a balanced model of equal numbers in each order of allocation
is necessary.
If we were to study our headache powders using this model, we will have the 3
treatments P, A, and B given in different orders to each subject.
We noticed that, with 3 treatments, there are 6 possible orders;
PAB,PBA,ABP,APB,BAP,BPA, and the same number of each order must be used,
so our sample size must be a multiple of 6.
We decided to use 30 subjects, 5 for each order, but which order a subject
is assigned to will be randomised.
We generated a single block of 30 numbers, ranging from 0 to 29, in random order, and obtain the following sequence.
19 9 12 6 16 24 11 3 18 27 13 10 26 25 5 28 0 14 8 4 2 23 20 15 22 29 1 17 7 21
To change this into 6 sets of orders we use the modulo of each number with 6 (divided by 6
and take the remainder), and obtained the following sequence.
1 3 0 0 4 0 5 3 0 3 1 4 2 1 5 4 0 2 2 4 2 5 2 3 4 5 1 5 1 3
Please note that there are 5 sets for each of 6 orders (0 to 5). We then replace each number
with a sequence, 0 with PAB, 1 with PBA, and so on. We obtained the following.
PBA APB PAB PAB BAP PAB BPA APB PAB APB PBA BAP ABP PBA BPA
BAP PAB ABP ABP BAP ABP BPA ABP APB BAP BPA PBA BPA PBA APB
The first subject recruited will be given placebo (P), powder B, and powder A
in that order; the second subject given in order A, P, and B; the third P, A, and B;
and so on. At the end of the study, there will be 5 subjects with each
order, and a balanced and randomised cross over allocation is achieved.
This is sometime used when research subjects are paired, each within the pair received a different treatment,
and the differences between subjects within each pair are the outcome measurements.
Pairs may be siblings, class mates, matched pairs, consecutive subjects recruited to the study, and so on.
Commonly pairs contain two subjects, but larger numbers are also used. To avoid systematic bias, the allocations
of treatments within each pair are randomised.
Such a model is similar to the crossover model, except that the allocations
are not necessarily balanced across the treatments, given that each treatment is given to
a different (although paired in characteristics) subject, so no residual effect is expected.
In another model of our study of headache powders, we will use subjects that are matched
in age, sex, medical diagnosis, and social background. We will use 3 matched subjects in each paired cluster,
to receive P, A, or B, and use the differences in response between the 3 as outcome measurements. In order
not to introduce bias, we randomised the treatments in order of recruitment of the matched 3 subjects.
We intend to study 20 matched sets.
We creating 20 block of 3 numbers, ranging 0 to 2, and obtain the following sequence.
1 0 2, 0 1 2, 1 2 0, 2 1 0, 1 0 2, 0 1 2, 2 1 0, 2 0 1, 2 0 1, 0 2 1,
0 1 2, 1 0 2, 2 0 1, 2 1 0, 2 0 1, 1 2 0, 2 0 1, 2 0 1, 0 1 2, 2 1 0
When translated (0=P, 1=A, and 2=B), the allocations are as follows
APB, PAB, ABP, BAP, APB, PAB, BAP, BPA, BPA, PBA, PAB, APB, BPA, BAP, BPA, ABP, BPA, BPA, PAB, BAP
In other words, in the first set of 3 matched subjects, the allocation in order
of recruitment will be A, P, and B. In the second set, P, A, and B. In the
third set A, B, and P, and so on.
Please note the similarity between paired allocation and crossover allocation,
but in the paired model the allocations are randomised but not necessarily balanced.
The first member of the matched threesome received placebo (P) 5 times, drug A 5 times,
and drug B 10 times. The second members received P 9 times, A 8 times, and B 3 times.
The third member received P 6 times, and A and B 7 times. In the crossover
model the numbers are the same on the 3 occasions.
Press WH, Flannery BP,Teukolsky SA, Vetterling WT (1994).
Numerical recipes in Pascal Ed. 1, IBSN 0521375169. p.221
