September 2012
Volume 53, Issue 10
Free
Letters to the Editor  |   September 2012
Generating a Random Sequence of Left and Right Eyes for Ophthalmic Research
Author Notes
  • Wolverhampton and Midland Counties Eye Infirmary, New Cross Hospital, Wolverhampton, United Kingdom. 
Investigative Ophthalmology & Visual Science September 2012, Vol.53, 6301-6302. doi:10.1167/iovs.12-10737
  • Views
  • PDF
  • Share
  • Tools
    • Alerts
      ×
      This feature is available to authenticated users only.
      Sign In or Create an Account ×
    • Get Citation

      Simon Dulku; Generating a Random Sequence of Left and Right Eyes for Ophthalmic Research. Invest. Ophthalmol. Vis. Sci. 2012;53(10):6301-6302. doi: 10.1167/iovs.12-10737.

      Download citation file:


      © ARVO (1962-2015); The Authors (2016-present)

      ×
  • Supplements
Outcomes between left and right eyes are correlated, 1 and this poses problems for the statistical inference of data from ophthalmic studies. Although regression methods can correct for this, 1 a simpler alternative (at some loss of statistical power compared to regression methods) is to choose randomly one eye or another when analyzing data. 
When so doing, it may be desirable to have equal numbers of left and right eyes in each group, or to have a random sequence that may result in unequal numbers between groups. 
The purpose of this Letter is to describe how such sequences can be generated using standard statistical software. 
Methods
Two functions were created using the open source statistical programming language, R. 2 The first function outputs a random sequence of left and right eyes with equal numbers of left and right eyes, while the second simply outputs a random sequence of eyes. 
Although software packages cannot produce true random numbers, the pseudo-random number generator in R uses the Mersenne-Twister algorithm, 3 which is sufficiently robust for the purposes described here. 
Function 1: Equal Eyes
This function produces an equal number of left and right eyes (coded as left = 0, right = 1) in a random sequence. 
The function can be entered into R using the following short piece of code: 
equaleyes <- function(x){  
prob.vector <- c(rep(1,ceiling(x/2)),rep(0,floor(x/2)))  
eye.seq <- sample(prob.vector,x,replace = FALSE)  
eye.seq  
}  
The code works as follows: x is the number of eyes required. A sequence of 1s followed by a sequence of 0s is placed in prob.vector (for probability vector). The number of 1s is exactly half of the total number of eyes required, rounded up if necessary using “ceiling.” The number of 0s also is exactly half of the total number of eyes, rounded down if necessary using “floor.” This means that for an even number of eyes, there will be an equal number of 1s and 0s, while for an odd number of eyes, there will be an extra “1” in the sequence. 
Next, numbers are picked at random from prob.vector and placed in eye.seq (for eye sequence). This is repeated until all of the numbers have been placed in eye.seq. As each number is taken, they are not replaced in the list (replace = FALSE); thus each eye can be picked only once, and equal numbers of left and right eyes appear in the final list, but in a randomized order. 
Once the function has been entered, typing equaleyes(x), where x is the number of eyes in the sequence, will generate a random sequence of left and right eyes with equal numbers in each group. As mentioned, where x is an odd number, the total number of right eyes will exceed the total number of left eyes by 1. 
Function 2: Random Eyes
This function produces a random sequence of left and right eyes. 
randomeyes <- function(x){  
prob.vector <- c(1,0)  
eye.seq <- sample(prob.vector,x,replace = TRUE)  
eye.seq  
}  
This function is simpler as prob.vector simply contains two numbers, 1 and 0. Numbers are picked at random and put into eye.seq. This is repeated as many times as required, but this time, when an eye is picked from prob.vector, it is replaced so that it can be picked again (replace = TRUE). This ensures that a completely random sequence of eyes is produced (which is likely to contain unequal numbers of left and right eyes). 
Once entered, typing randomeyes(x), where x is the number of eyes in the sequence, will generate a random sequence of left and right eyes. 
Results
To generate a random sequence of 10 eyes with equal left and right eyes, type equaleyes(10). This will give output similar to: 
[1] 0 1 1 1 1 0 1 0 0 0  
The sequence is read from left to right as 0 = left eye and 1 = right eye (the [1] simply indicates the first item in the list and is not part of the data). Any positive whole number can be chosen to determine the total number of eyes. 
For comparison, randomeyes(20) gives output similar to: 
[1] 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0  
When reproducible results are required, one should use set.seed(x), where x is any integer, before using the function. Using the same value of set.seed(x) each time will generate the same sequence of 1s and 0s. 
Discussion
These functions can be used for the purposes of randomly selecting left and right eyes, with either equal numbers of left and right eyes in each sequence, or a completely random sequence. 
The functions also could be used to perform block randomization in a clinical trial, although there are a number of additional points to consider if doing so. 4 To perform block randomization one simply would use equaleyes(x), where x is the size of the block of patients, and 0 = treatment 1/control and 1 = treatment 2. 
These functions have been implemented in a freely available, open source, statistical package 2 and provide a standard method for randomizing eyes. Although they have been implemented in R, the step-by-step description of how the functions work could be adapted for use in any suitable statistical or spreadsheet package. 
It is hoped that this, along with regression methods, will facilitate the analysis of data in a manner that avoids the problem of correlation between eyes. 
References
Glynn RJ Rosner B. Regression methods when the eye is the unit of analysis. Ophthalmic Epidemiol . 2012;19:159–165. [CrossRef] [PubMed]
R Development Core Team. R: A Language and Environment for Statistical Computing . Vienna, Austria: R Foundation for Statistical Computing, ISBN: 3-900051-07-0. Available at: http://www.R-project.org. Accessed May 20, 2012.
Matsumoto M Nishimura T. Mersenne twister: a 623-dimensionally equidistributed uniform pseudo-random number generator. ACM Trans. Model. Comput. Simul . 1998;8:3–30. [CrossRef]
Efird J. Blocked randomization with randomly selected block sizes. Int J Environ Res Public Health . 2011;8:15–20. [CrossRef] [PubMed]
×
×

This PDF is available to Subscribers Only

Sign in or purchase a subscription to access this content. ×

You must be signed into an individual account to use this feature.

×