/* Randomization Plans */ /* Copyright 1997, Gerard E. Dallal */ function GEDPlan(GED) { /*make list of number of blocks*/ var nbs = 0 var nperb = new Array var nblock = new Array if (!blank(GED.nperb1.value)) {++nbs; nperb[nbs] = GED.nperb1.value; nblock[nbs] = GED.nblock1.value} if (!blank(GED.nperb2.value)) {++nbs; nperb[nbs] = GED.nperb2.value; nblock[nbs] = GED.nblock2.value} else {nblock[2]=0; nperb[2]=0} if (!blank(GED.nperb3.value)) {++nbs; nperb[nbs] = GED.nperb3.value; nblock[nbs] = GED.nblock3.value} else {nblock[3]=0; nperb[3]=0} if (!blank(GED.nperb4.value)) {++nbs; nperb[nbs] = GED.nperb4.value; nblock[nbs] = GED.nblock4.value} else {nblock[4]=0; nperb[4]=0} for (i=1; i<=4; ++i) {nperb[i]=parseFloat(nperb[i]); nblock[i]=parseFloat(nblock[i])} /* sort list */ for (i=1; i<ntr; ++i) { for (j=i+1; j<=nbs; ++j) { if (nperb[i]<nperb[j]) { dummy = nperb[j]; dummy2 = nblock[j]; nperb[j] = nperb[i]; nblock[j] = nblock[i]; nperb[i] = dummy; nblock[i] = dummy2}}} if (blank(nperb[1]) || !digits(nperb[1])) { alert("Number of subjects per block not specified"); return;} var gogo= GED.gogo.value if (blank(gogo) || !digits(gogo)) { alert("Initial subject value not specified"); return;} /* var nblock = GED.nblock.value if (blank(nblock) || !digits(nblock)) { alert("Number of blocks not specified"); return;} nperb = parseFloat(nperb) if (nperb<2) { alert("Number of subjects per block must be at least 2"); return;} nblock = parseFloat(nblock) if (nblock<1) { alert("There must be at least 1 block"); return;} */ gogo = parseFloat(gogo) if (gogo<1) { alert("Inital subject ID must be no less than 1"); return;} /* set up random number generator*/ ix = 12345; iy = 23456; seed = GED.seed.value if (blank(seed)) { xseed= new Date(); seed = 1 + (xseed.getSeconds()*1000 + xseed.getMinutes()*10 + xseed.getHours()) % 29998 } else { if (!digits(seed)) { alert("Seed must be between 1 and 30,000"); return;} } seed = parseFloat(seed); if (seed<1 || seed>30000) { alert("Seed must be between 1 and 30,000"); return;} seed2 = seed; /* make list of treatments*/ var ntr = 0 var tlist = new Array if (!blank(GED.tr1.value)) {++ntr; tlist[ntr] = GED.tr1.value;} if (!blank(GED.tr2.value)) {++ntr; tlist[ntr] = GED.tr2.value;} if (!blank(GED.tr3.value)) {++ntr; tlist[ntr] = GED.tr3.value;} if (!blank(GED.tr4.value)) {++ntr; tlist[ntr] = GED.tr4.value;} if (!blank(GED.tr5.value)) {++ntr; tlist[ntr] = GED.tr5.value;} if (!blank(GED.tr6.value)) {++ntr; tlist[ntr] = GED.tr6.value;} if (!blank(GED.tr7.value)) {++ntr; tlist[ntr] = GED.tr7.value;} if (!blank(GED.tr8.value)) {++ntr; tlist[ntr] = GED.tr8.value;} if (!blank(GED.tr9.value)) {++ntr; tlist[ntr] = GED.tr9.value;} if (!blank(GED.tr10.value)) {++ntr; tlist[ntr] = GED.tr10.value;} if (!blank(GED.tr11.value)) {++ntr; tlist[ntr] = GED.tr11.value;} if (!blank(GED.tr12.value)) {++ntr; tlist[ntr] = GED.tr12.value;} if (!blank(GED.tr13.value)) {++ntr; tlist[ntr] = GED.tr13.value;} if (!blank(GED.tr14.value)) {++ntr; tlist[ntr] = GED.tr14.value;} if (!blank(GED.tr15.value)) {++ntr; tlist[ntr] = GED.tr15.value;} if (!blank(GED.tr16.value)) {++ntr; tlist[ntr] = GED.tr16.value;} if (!blank(GED.tr17.value)) {++ntr; tlist[ntr] = GED.tr17.value;} if (!blank(GED.tr18.value)) {++ntr; tlist[ntr] = GED.tr18.value;} if (!blank(GED.tr19.value)) {++ntr; tlist[ntr] = GED.tr19.value;} if (!blank(GED.tr20.value)) {++ntr; tlist[ntr] = GED.tr20.value;} /* sort list */ for (i=1; i<ntr; ++i) { for (j=i+1; j<=ntr; ++j) { if (tlist[i]<tlist[j]) { dummy = tlist[j]; tlist[j] = tlist[i]; tlist[i] = dummy}}} /* nperb = number of items per block */ var nbl = new Array for (i=1; i<=nblock[1]; ++i) { nbl[i]=nperb[1] } if (nbs>1) {for (i=nblock[1]+1; i<=nblock[1]+nblock[2]; ++i) { nbl[i]=nperb[2] } } if (nbs>2) {for (i=nblock[1]+nblock[2]+1; i<=nblock[1]+nblock[2]+nblock[3]; ++i) { nbl[i]=nperb[3] } } if (nbs>3) {for (i=nblock[1]+nblock[2]+nblock[3]+1; i<=nblock[1]+nblock[2]+nblock[3]+nblock[4]; ++i) { nbl[i]=nperb[4] } } totblock = nblock[1]+nblock[2]+nblock[3]+nblock[4] ntot = nperb[1]*nblock[1] + nperb[2]*nblock[2] + nperb[3]*nblock[3] + nperb[4]*nblock[4] if ((nperb[1] % ntr != 0) || (nperb[2] % ntr != 0) || (nperb[3] % ntr != 0) || (nperb[4] % ntr != 0)) { alert("Number of subjects per block must be multiple of Number of treatments"); return;} /*permute block sizes*/ if (nbs>1) { for (i=totblock; i>=2; --i) { j = i * random() + 1; j = j - j%1; dummy = nbl[i]; nbl[i] = nbl[j]; nbl[j] = dummy;} } perm = new Array tr = new Array treat = new Array igo=0 for (k=1; k<=totblock; ++k) { /* Assign each block's treatments, unpermuted*/ /* neach = number of each treatment per block */ neach = nbl[k]/ntr; for (i=1; i<=ntr; ++i) { for (j=1; j<=neach; ++j) { tr[(i-1)*neach+j]=tlist[i] } } /* random permutation of 1(1)nbl[k] */ for (i=1; i<=nbl[k]; ++i) {perm[i]=i} for (i=nbl[k]; i>=2; --i) { j = i * random() + 1; j = j - j%1; dummy = perm[i]; perm[i] = perm[j]; perm[j] = dummy;} /* Permute each block's treatments*/ for (i=1; i<=nbl[k]; ++i) {treat[igo+i] = tr[perm[i]]} igo=igo+nbl[k] } PlanWin = window.open("","Randomization_Plan") PlanWin.document.open() /* PlanWin.document.write("<H3 ALIGN=CENTER>A Randomization Plan</H3>") PlanWin.document.write("<CENTER>from") PlanWin.document.write("<H3 ALIGN=CENTER><FONT COLOR='#FF0000'>http://www.randomization.com</FONT></H3>") PlanWin.document.write("<H3 ALIGN=CENTER>A Randomization Plan") PlanWin.document.write("<CENTER>from") PlanWin.document.write("<center><FONT COLOR='#FF0000'>http://www.randomization.com</FONT> </center></h3>") */ PlanWin.document.write("<CENTER><font size=+2><b>A Randomization Plan</b></CENTER>") PlanWin.document.write("<CENTER><font size=+1>from</CENTER>") PlanWin.document.write("<CENTER><FONT size=+2 COLOR='#FF0000'><b>http://www.randomization.com</b></FONT></CENTER>") PlanWin.document.write("<font size=+0><br>") var line = "_________________________________________" PlanWin.document.write("<SAMP>") PlanWin.document.write("<blockquote>") PlanWin.document.write("<OL start="+gogo+" TYPE=1>") for(i=1; i<=ntot; ++i) { x = treat[i]+line x = x.substring(0,39) PlanWin.document.write("<LI>"+x)} PlanWin.document.write("</OL>") PlanWin.document.write("</blockquote>") PlanWin.document.write("</SAMP>") if (nbs==1) { if (nblock[1]==1){ PlanWin.document.write("<BR><BR><CENTER>"+ntot+" subjects randomized into "+nblock[1]+" block<\CENTER>") } else { PlanWin.document.write("<BR><BR><CENTER>"+ntot+" subjects randomized into "+nblock[1]+" blocks<\CENTER>") } } else { PlanWin.document.write("<BR><BR><CENTER>"+ntot+" subjects randomized into blocks of<\CENTER>") for (j=1; j<=totblock; ++j){ if ((j>1) & (1==j%20)){PlanWin.document.write("<br>")} PlanWin.document.write(nbl[j]+" ") } } PlanWin.document.write("<CENTER>To reproduce this plan, use the seed "+seed2+"<\CENTER>") PlanWin.document.write("<CENTER>Randomization plan created on "+ xseed.toLocaleString()+"<\CENTER>") PlanWin.document.close() } function random () { /* Algorithm AS 183 Appl. Statist. (1982) Vol.31, No.2 */ /* as amended by */ /* Remark AS R58 Appl. Statist. (1985) Vol.34, No.2 */ /* X, Y and Z should be set to integer values between */ /* 1 and 30000 before first entry */ ix = (ix * 171) % 30269; iy = (iy * 172) % 30307; seed = (seed * 170) % 30323; r = (ix / 30269 + iy / 30307 + seed / 30323) % 1; if (r >= 1) {r = 0.999999}; return r; } function blank(x) { var b="" var n=x.length for(var i=1;i<=n;i++) {b += " ";} if (x==b) { return true;} else { return false;} return bl; } function digits(x) { if (x=="") {return false;} for(i=0;i<x.length;i++) {if ( x.substring(i,i+1)<"0" || x.substring(i,i+1)>"9") { return false}} return true; } //--> </script> </head> <body text="#000000" bgcolor="#51B6F2" link="#0000EE" vlink="#551A8B" alink="#FF0000"> <center> <h3> Randomization Plans</h3></center> <center><b>Randomizing subjects to a single treatment</b></center> <center><noscript><font color="#FF0000"><b> <br>Ooops! <br>This is a JavaScript program. <br>Your browser is not recognizing JavaScript. <br>The most likely explanation is that JavaScript recognition <br>is turned off. Go to your browser's Help menu and <br>search on </font>Java<font color="#FF0000"> to learn how to enable it.</b> </font></noscript></center> <ul><form><b>Treatment labels:</b> (enter as many as necessary)</ul> <center><input TYPE = "text" NAME = "tr1" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr2" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr3" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr4" VALUE = "" SIZE = 15> <br><input TYPE = "text" NAME = "tr5" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr6" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr7" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr8" VALUE = "" SIZE = 15> <br><input TYPE = "text" NAME = "tr9" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr10" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr11" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr12" VALUE = "" SIZE = 15> <br><input TYPE = "text" NAME = "tr13" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr14" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr15" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr16" VALUE = "" SIZE = 15> <br><input TYPE = "text" NAME = "tr17" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr18" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr19" VALUE = "" SIZE = 15><input TYPE = "text" NAME = "tr20" VALUE = "" SIZE = 15> <p><b>Number of subjects per block/number of blocks </b><input TYPE = "text" NAME = "nperb1" SIZE = 4> <b>/</b> <input TYPE = "text" NAME = "nblock1" SIZE = 4 VALUE = 1> <br><b>Number of subjects per block/number of blocks </b><input TYPE = "text" NAME = "nperb2" SIZE = 4> <b>/</b> <input TYPE = "text" NAME = "nblock2" SIZE = 4 VALUE = 1> <br><b>Number of subjects per block/number of blocks </b><input TYPE = "text" NAME = "nperb3" SIZE = 4> <b>/</b> <input TYPE = "text" NAME = "nblock3" SIZE = 4 VALUE = 1> <br><b>Number of subjects per block/number of blocks </b><input TYPE = "text" NAME = "nperb4" SIZE = 4> <b>/</b> <input TYPE = "text" NAME = "nblock4" SIZE = 4 VALUE = 1> <br><b><a href="assigndoc.htm#num">Initial subject ID number</a>&nbsp;</b><input TYPE = "text" NAME = "gogo" SIZE = 7 VALUE = 1> <p><input TYPE = "button" VALUE = 'Generate Plan' onClick = "GEDPlan(this.form)"><a href="assigndoc.htm"><img SRC="HELP.GIF" BORDER=0 height=32 width=47></a> <p>To reproduce an earlier plan, enter its labels and its seed&nbsp;<input TYPE = "text" NAME = "seed" SIZE = 5>