· 1 # gonogo.r 5/16/2018 (from gonogo0.r from xtogether.r) 2 . 3 . #index 1 through 35, xcomm.r...

96
# gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 1 2 #INDEX 1 through 35, XComm.R (35 functions) 3 4 gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,term1=T,BL=NULL,Y=NULL) 5 { 6 lY=length(Y); lBL=length(BL); en12=rep(0,2); 7 jvec=dud=lev=NULL; 8 if(mlo == 0 & mhi == 0 & sg == 0 & newz == T) 9 { 10 cat("Minimal entries to gonogo are: (1) mlo, mhi, sg; or (2) newz=F.\nTry again.\n\n"); 11 return(); 12 } else { n2n3=0; endi=0; sgrem=sg; g=", "; } 13 if(!newz) {test=z$test; about = z$about; init=z$init; mlo=init[1]; mhi=init[2]; sg=init[3];} 14 15 if(!is.element(test,1:4)) {vv="test must be 1,2,3 or 4. Try again\n"; cat(vv); return();} 16 if(mhi < mlo) {vv="mhi-mlo must be nonnegative. Try again.\n"; cat(vv); return(); } 17 if(mlo == mhi & sg > 0) test=3; 18 if(mlo < mhi & sg == 0) test=4; 19 if(test < 4) {if(sg <= 0) {vv="sg must be positive. Try again.\n"; cat(vv); return(); }} 20 21 if(newz) 22 { 23 if(test == 1) blrb1(); 24 if(test == 2) blrb2(); 25 if(test == 3) blrb3(); 26 if(test == 4) blrb4(); 27 } 28 29 if(test == 1 | test == 2) 30 { 31 del5=(mhi-mlo)/6; 32 epsi=del5/1000; 33 if(sg>(mhi-mlo)/6+epsi){cat(paste("sg is too big (sg <= ",round(del5,4),")\nTry again\n\n",sep="")); 34 return();} 35 } 36 37 xx="Enter title (without quotes): "; yy="Enter units (without quotes): "; 38 if(newz) {dat0=data.frame(numeric(0)); titl=readline(xx); unit=readline(yy); n1=n2=n3=p=lam=0; 39 en=c(n1,n2,n3); about=wabout(c(mlo,mhi,sg,n1,n2,n3,p,lam,reso)); savinit=c(mlo,mhi,sg);} else 40 {dat0=z$d0; about=z$about; titl=z$title; unit=z$units; en=z$en; n1=en[1]; n2=en[2]; n3=en[3]; 41 p=z$p; reso=z$reso; n2n3=z$n2n3; ln=z$ln; init=z$init; mlo=init[1]; mhi=init[2]; sg=init[3]; 42 lam=z$lam; test=z$test; savinit=z$savinit; term1=z$term1;} 43 44 ttl0=titl; ttl1=ttl2=NULL; 45 46 if(ln & newz){ 47 if(test < 3) { u=fgs(mlo,mhi,sg); mlo=u[1]; mhi=u[2]; sg=u[3]; } 48 if(test == 3) { 49 vv="For ln=T Bruceton, mlo (same as mhi) must be positive.\n"; 50 vv1="Also, sg must be between 0 and mlo/3. Try again.\n"; 51 if(mlo <= 0 | sg <= 0 | sg >= mlo/3) {cat(vv); cat(vv1); return();} else 52 {mlo=log(mlo); mhi=log(mhi); sg=log(1+sg/mlo);} 53 } 54 if(test == 4) { 55 vv="For ln=T Langlie, mlo < mhi and both must be positive. Try again.\n"; 56 if(mlo <= 0 | mhi <= 0 | mlo >= mhi) {cat(vv); return();} else {mlo=log(mlo); mhi=log(mhi);} 57 } 58 } 59 60 if(!newz & test > 2) {BL=z$BL; dud=z$dud; lev=z$lev} 61 62 if(newz & test < 3) cat("\n"); 63 64 xx="Enter BL (nRev and two i's (one 0 is OK): "; 65 66 if(ln) h2="Log " else h2=""; 67 if(test == 1 & newz) titl=paste(h2,"3pod: ",titl,sep=""); 68 if(test == 2 & newz) titl=paste(h2,"Neyer: ",titl,sep=""); 69 70 if(newz & test > 2) 71 { 72 if(lBL == 0) 73 { 74 blrb6(); 75 xx=readline(xx); 76 xx=strsplit(xx," ",fixed=T); 77 BL=as.numeric(xx[[1]]); 78 } 79

Upload: others

Post on 25-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

# gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 1 2 #INDEX 1 through 35, XComm.R (35 functions) 3 4 gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,term1=T,BL=NULL,Y=NULL) 5 { 6 lY=length(Y); lBL=length(BL); en12=rep(0,2); 7 jvec=dud=lev=NULL; 8 if(mlo == 0 & mhi == 0 & sg == 0 & newz == T) 9 { 10 cat("Minimal entries to gonogo are: (1) mlo, mhi, sg; or (2) newz=F.\nTry again.\n\n"); 11 return(); 12 } else { n2n3=0; endi=0; sgrem=sg; g=", "; } 13 if(!newz) {test=z$test; about = z$about; init=z$init; mlo=init[1]; mhi=init[2]; sg=init[3];} 14 15 if(!is.element(test,1:4)) {vv="test must be 1,2,3 or 4. Try again\n"; cat(vv); return();} 16 if(mhi < mlo) {vv="mhi-mlo must be nonnegative. Try again.\n"; cat(vv); return(); } 17 if(mlo == mhi & sg > 0) test=3; 18 if(mlo < mhi & sg == 0) test=4; 19 if(test < 4) {if(sg <= 0) {vv="sg must be positive. Try again.\n"; cat(vv); return(); }} 20 21 if(newz) 22 { 23 if(test == 1) blrb1(); 24 if(test == 2) blrb2(); 25 if(test == 3) blrb3(); 26 if(test == 4) blrb4(); 27 } 28 29 if(test == 1 | test == 2) 30 { 31 del5=(mhi-mlo)/6; 32 epsi=del5/1000; 33 if(sg>(mhi-mlo)/6+epsi){cat(paste("sg is too big (sg <= ",round(del5,4),")\nTry again\n\n",sep="")); 34 return();} 35 } 36 37 xx="Enter title (without quotes): "; yy="Enter units (without quotes): "; 38 if(newz) {dat0=data.frame(numeric(0)); titl=readline(xx); unit=readline(yy); n1=n2=n3=p=lam=0; 39 en=c(n1,n2,n3); about=wabout(c(mlo,mhi,sg,n1,n2,n3,p,lam,reso)); savinit=c(mlo,mhi,sg);} else 40 {dat0=z$d0; about=z$about; titl=z$title; unit=z$units; en=z$en; n1=en[1]; n2=en[2]; n3=en[3]; 41 p=z$p; reso=z$reso; n2n3=z$n2n3; ln=z$ln; init=z$init; mlo=init[1]; mhi=init[2]; sg=init[3]; 42 lam=z$lam; test=z$test; savinit=z$savinit; term1=z$term1;} 43 44 ttl0=titl; ttl1=ttl2=NULL; 45 46 if(ln & newz){ 47 if(test < 3) { u=fgs(mlo,mhi,sg); mlo=u[1]; mhi=u[2]; sg=u[3]; } 48 if(test == 3) { 49 vv="For ln=T Bruceton, mlo (same as mhi) must be positive.\n"; 50 vv1="Also, sg must be between 0 and mlo/3. Try again.\n"; 51 if(mlo <= 0 | sg <= 0 | sg >= mlo/3) {cat(vv); cat(vv1); return();} else 52 {mlo=log(mlo); mhi=log(mhi); sg=log(1+sg/mlo);} 53 } 54 if(test == 4) { 55 vv="For ln=T Langlie, mlo < mhi and both must be positive. Try again.\n"; 56 if(mlo <= 0 | mhi <= 0 | mlo >= mhi) {cat(vv); return();} else {mlo=log(mlo); mhi=log(mhi);} 57 } 58 } 59 60 if(!newz & test > 2) {BL=z$BL; dud=z$dud; lev=z$lev} 61 62 if(newz & test < 3) cat("\n"); 63 64 xx="Enter BL (nRev and two i's (one 0 is OK): "; 65 66 if(ln) h2="Log " else h2=""; 67 if(test == 1 & newz) titl=paste(h2,"3pod: ",titl,sep=""); 68 if(test == 2 & newz) titl=paste(h2,"Neyer: ",titl,sep=""); 69 70 if(newz & test > 2) 71 { 72 if(lBL == 0) 73 { 74 blrb6(); 75 xx=readline(xx); 76 xx=strsplit(xx," ",fixed=T); 77 BL=as.numeric(xx[[1]]); 78 } 79

Page 2:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

80 lBL=length(BL); 81 if(lBL != 3){cat("3 integers are required.\nTry again\n\n"); return();} 82 83 tx=paste(BL,collapse=""); 84 if(all(BL[-1] == c(0,1)) | all(BL[-1] == c(1,1))) BL[2:3]=c(1,0); 85 I=BL[-1]; 86 a=prtrans(I); dud=a$dud; lev=a$lev; 87 pm=c(1,-1); iz=which(I==0); lz=length(iz); 88 if(lz == 1) I=I[-iz]; 89 zp=zpfun(I); 90 if(lz == 0)zp=c(0,1)+pm*zp; 91 if(lz == 1){if(iz == 1) zp=1-zp;} 92 pchar=paste(xlead0(zp,4),collapse=","); 93 94 cat(dud); cat("\n\n"); 95 t3=paste(BL,collapse=""); 96 # titl must be defined in gonogo (as it's passed to getd0 and to pdat1) 97 if(test == 3) titl=substitute(paste(h2,L[pchar]," ",Bruc[t3],": ",titl,sep="")); 98 if(test == 4) titl=substitute(paste(h2,L[pchar]," ",Lang[t3],": ",titl,sep="")); 99 ttl1=substitute(paste(L[pchar],sep="")); 100 if(test == 3) ttl2=substitute(paste(Bruc[t3],sep="")) else 101 ttl2=substitute(paste(Lang[t3],sep="")); 102 # titl can be made from ttl0, ttl1 and ttl2 in the other pdat functions as follows: 103 # ttl3=substitute(paste(h2,ttl1," ",ttl2,": ",ttl0,sep="")); 104 } 105 106 init=c(mlo,mhi,sg) 107 if(!newz) n2n3=prd0(z); 108 109 # n1 is the random test quantity eventually required to complete Phase I 110 111 if(lY == 0) 112 { 113 #------------------------------------------------------------------------------------ 114 115 if(test == 1) 116 { 117 if(endi == 0) 118 {w=phaseI1(dat0,mlo,mhi,sg,reso,about,titl,unit,ln); 119 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; sg=w[[4]];} # NEW with 3podm 120 121 if(endi == 0) 122 {w=phaseI2(d0,dat0,sg,reso,about,titl,unit,ln,term1); 123 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; sg=w[[4]]; } 124 en12[1]=nrow(d0); 125 126 if(endi == 0) 127 {w=phaseI3(d0,dat0,sg,reso,about,titl,unit,ln,term1); 128 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; } 129 n1=nrow(d0); 130 en12[2]=nrow(d0)-en12[1]; 131 132 } 133 if(test == 2) 134 { 135 if(endi == 0) 136 {w=nphaseI(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,term1); 137 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; sg=w[[4]];} # NEW with 3podm 138 n1=en12[1]=nrow(d0); 139 } 140 if(test == 3) 141 { 142 if(endi == 0) 143 {w=bphaseI(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL); 144 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; en12=w[[4]];} # NEW with 3podm 145 n1=nrow(d0); 146 } 147 148 if(test == 4) 149 { 150 if(endi == 0) 151 {w=lphaseI(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL); 152 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; en12=w[[4]];} # NEW with 3podm 153 n1=nrow(d0); 154 } 155 156 # Don't go to Phase II if mean(X[Y==1]) <= mean(X[Y==0]) 157 if(test < 3 & d.update(d0) < 1) {blrb7(); endi=1;} 158

Page 3:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

159 # Read here n2: the number of Phase II (D-Optimal) tests to run 160 161 if(endi == 0 & n2n3 != 2 & n2n3 != 3 & n2n3 != 4 & n2n3 != 5) 162 { 163 gg=glmmle(d0); g1=round(gg$mu,5); g2=round(gg$sig,5); 164 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 165 xx=paste("\nPhase I complete, (Mu, Sig) = (",g1,", ",g2,").\nEnter Phase II (D-Optimal) size 166 n2: ",sep=""); 167 if(n2 == 0) {n2=as.numeric(readline(xx)); if(n2==0)n2n3=2; cat("\n");} 168 if(n2 < 0) {n2=0; endi=1;} 169 if(n2 > 0) 170 { 171 en[2]=n2; 172 173 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 174 w=phaseII(d0,dat0,n2,reso,about,titl,unit,ln,term1); d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; 175 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 176 } 177 } 178 179 if(endi == 0) 180 { 181 if(n3 == 0) 182 { 183 gg=glmmle(d0); g1=round(gg$mu,5); g2=round(gg$sig,5); 184 jkl="complete"; if(n2 == 0) jkl="skipped"; 185 zz=""; 186 if(ln)zz=paste("\n\n** Starting values (tau2[1] & be) for Phase III, ln=T may need 187 tweaking.\n",sep=""); 188 xx=paste("\nPhase II ",jkl,", (Mu, Sig) = (",g1,", ",g2,").",zz,"\nEnter Phase III (S-189 RMJ) size n3: ",sep=""); 190 xx=readline(xx); n3=as.numeric(xx); 191 if(n3 == 0)endi=8; 192 if(n3 < 0){n3=0; endi=1;} 193 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 194 } 195 } 196 197 if(endi == 0 & n3 > 0 & p == 0) 198 { 199 xx="Enter p lam: "; 200 if(p==0) 201 { 202 xx=readline(xx); 203 xx=strsplit(xx," ",fixed=T); 204 xx=as.numeric(xx[[1]]); 205 nxx=length(xx); 206 p=xx[1]; if(nxx > 1)lam=xx[2]; 207 cat("\n"); 208 } 209 if(p >= 1 | p <= 0 | lam <= 0 | nxx != 2) 210 {p=0; lam=0; endi=1; n2n3=3; if(n2 > 0) n2n3=6; } 211 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 212 } 213 if(endi == 0) { 214 n2n3=4; if(n2 > 0) n2n3=7; 215 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 216 w=sphaseIII(d0,dat0,n3,p,reso,about,titl,unit,ln,lam); d0=w[[1]]; 217 dat0=w[[2]]; endi=w[[3]]; jvec=w[[4]]; } 218 219 # Adapted from bottom of prd0 220 if(endi == 0 | endi == 2 | endi == 8) { 221 gg=glmmle(d0); g1=round(gg$mu,5); g2=round(gg$sig,5); 222 xx=paste("\nPhase III complete, (Mu, Sig) = (",g1,", ",g2,").\n",sep=""); 223 cat(xx); 224 } else cat("Test Suspended\n") 225 226 en=c(n1,n2,n3); 227 if(test == 1 | test == 2) 228 { 229 ret=list(d0,about,titl,ttl0,ttl1,ttl2,unit,en,p,reso,n2n3,ln,init,lam,test,savinit,jvec,term1); 230 names(ret)=c("d0","about","title","ttl0","ttl1","ttl2","units","en","p","reso","n2n3","ln","init","lam"231 ,"test","savinit","jvec","term1"); 232 } 233 if(test == 3 | test == 4) 234 { 235 ret=list(d0,about,titl,ttl0,ttl1,ttl2,unit,en,p,reso,n2n3,ln,init,lam,test,savinit,jvec,BL,dud,lev,term236 1); 237

Page 4:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

names(ret)=c("d0","about","title","ttl0","ttl1","ttl2","units","en","p","reso","n2n3","ln","init","lam"238 ,"test","savinit","jvec","BL","dud","lev","term1"); 239 } 240 if(endi == 2 & n1 > 1) ptest(ret,1); 241 242 #------------------------------------------------------------------------------------ 243 } 244 245 if(lY > 0) 246 { 247 #------------------------------------------------------------------------------------ 248 249 if(test == 1) 250 { 251 if(endi == 0) 252 {w=phaseBI1(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,Y); 253 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; sg=w[[4]]; Y=w[[5]];} # NEW with 3podm 254 255 if(endi == 0) 256 {w=phaseBI2(d0,dat0,sg,reso,about,titl,unit,ln,term1,Y); 257 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; sg=w[[4]]; Y=w[[5]];} 258 en12[1]=nrow(d0); 259 260 if(endi == 0) 261 {w=phaseBI3(d0,dat0,sg,reso,about,titl,unit,ln,term1,Y); 262 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; Y=w[[4]];} 263 n1=nrow(d0); en12[2]=n1-en12[1]; 264 } 265 if(test == 2) 266 { 267 if(endi == 0) 268 {w=nphaseBI(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,term1,Y); 269 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; sg=w[[4]]; Y=w[[5]];} # NEW with 3podm 270 n1=en12[1]=nrow(d0); 271 } 272 if(test == 3) 273 { 274 if(endi == 0) 275 {w=bphaseBI(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL,Y); 276 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; Y=w[[4]]; en12=w[[5]];} # NEW with 3podm 277 n1=nrow(d0); 278 } 279 280 if(test == 4) 281 { 282 if(endi == 0) 283 {w=lphaseBI(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL,Y); 284 d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; Y=w[[4]]; en12=w[[5]];} # NEW with 3podm 285 n1=nrow(d0); 286 } 287 288 # Don't go to Phase II if mean(X[Y==1]) <= mean(X[Y==0]) 289 if(test < 3 & d.update(d0) < 1) {blrb7(); endi=1;} 290 291 # Read here n2: the number of Phase II (D-Optimal) tests to run 292 293 if(endi == 0 & n2n3 != 2 & n2n3 != 3 & n2n3 != 4 & n2n3 != 5) 294 { 295 gg=glmmle(d0); g1=round(gg$mu,5); g2=round(gg$sig,5); 296 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 297 xx=paste("\nPhase I complete, (Mu, Sig) = (",g1,", ",g2,").\nEnter Phase II (D-Optimal) size 298 n2: ",sep=""); 299 if(n2 == 0) {n2=as.numeric(readline(xx)); if(n2==0)n2n3=2; cat("\n");} 300 if(n2 < 0) {n2=0; endi=1;} 301 if(n2 > 0) 302 { 303 en[2]=n2; 304 305 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 306 w=phaseBII(d0,dat0,n2,reso,about,titl,unit,ln,term1,Y); d0=w[[1]]; dat0=w[[2]]; endi=w[[3]]; 307 Y=w[[4]]; 308 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 309 } 310 } 311 312 if(endi == 0) 313 { 314 if(n3 == 0) 315 { 316

Page 5:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

gg=glmmle(d0); g1=round(gg$mu,5); g2=round(gg$sig,5); 317 jkl="complete"; if(n2 == 0) jkl="skipped"; 318 zz=""; 319 if(ln)zz=paste("\n\n** Starting values (tau2[1] & be) for Phase III, ln=T may need 320 tweaking.\n",sep=""); 321 xx=paste("\nPhase II ",jkl,", (Mu, Sig) = (",g1,", ",g2,").",zz,"\nEnter Phase III (S-322 RMJ) size n3: ",sep=""); 323 xx=readline(xx); n3=as.numeric(xx); 324 if(n3 == 0)endi=8; 325 if(n3 < 0){n3=0; endi=1;} 326 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 327 } 328 } 329 330 if(endi == 0 & n3 > 0 & p == 0) 331 { 332 xx="Enter p lam: "; 333 if(p==0) 334 { 335 xx=readline(xx); 336 xx=strsplit(xx," ",fixed=T); 337 xx=as.numeric(xx[[1]]); 338 nxx=length(xx); 339 p=xx[1]; if(nxx > 1)lam=xx[2]; 340 cat("\n"); 341 } 342 if(p >= 1 | p <= 0 | lam <= 0 | nxx != 2) 343 {p=0; lam=0; endi=1; n2n3=3; if(n2 > 0) n2n3=6; } 344 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 345 } 346 if(endi == 0) { 347 n2n3=4; if(n2 > 0) n2n3=7; 348 about=wabout(c(savinit,n1,n2,n3,p,lam,reso)); 349 w=sphaseBIII(d0,dat0,n3,p,reso,about,titl,unit,ln,Y,lam); d0=w[[1]]; 350 dat0=w[[2]]; endi=w[[3]]; jvec=w[[4]]; Y=w[[5]]; } 351 352 # Adapted from bottom of prd0 353 if(endi == 0 | endi == 2 | endi == 8) { 354 gg=glmmle(d0); g1=round(gg$mu,5); g2=round(gg$sig,5); 355 xx=paste("\nPhase III complete, (Mu, Sig) = (",g1,", ",g2,").\n",sep=""); 356 cat(xx); 357 } else cat("Test Suspended\n") 358 359 en=c(n1,n2,n3); 360 jt=F; about1=chabout(about,en,4:6); if(about != about1) {jt=T; about=about1;} 361 362 if(test == 1 | test == 2) 363 { 364 ret=list(d0,about,titl,ttl0,ttl1,ttl2,unit,en,p,reso,n2n3,ln,init,lam,test,savinit,jvec,term1,en12); 365 names(ret)=c("d0","about","title","ttl0","ttl1","ttl2","units","en","p","reso","n2n3","ln","init","lam"366 ,"test","savinit","jvec","term1","en12"); 367 } 368 if(test == 3 | test == 4) 369 { 370 ret=list(d0,about,titl,ttl0,ttl1,ttl2,unit,en,p,reso,n2n3,ln,init,lam,test,savinit,jvec,term1,BL,dud,le371 v,en12); 372 names(ret)=c("d0","about","title","ttl0","ttl1","ttl2","units","en","p","reso","n2n3","ln","init", 373 "lam","test","savinit","jvec","term1","BL","dud","lev","en12"); 374 } 375 if((jt | endi == 2) & n1 > 1) ptest(ret,1); 376 377 #------------------------------------------------------------------------------------ 378 } 379 380 rd0=d0; rd0$X=round(rd0$X,5); names(rd0)[1]="i,X"; rd0$EX=round(rd0$EX,5); 381 write.table(rd0,file="gonogo.txt",quote=F,sep=",",na="i"); 382 return(ret); 383 } 384 385 phaseI1=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln) 386 { 387 nret=c("d0","dat0","endi","sg"); 388 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 389 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 390 d0=d1[-1,]; names(d0)=names(d1)=cnam; 391 d0$ID=as.character(d0$ID); 392 if(is.null(dat0)) dat0=d0; 393 endi=0; 394 mi=c(mlo,mhi); 395

Page 6:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

a=matrix(c(.75,.25,.25,.75),ncol=2,byrow=T); 396 xx=t(a%*%mi); 397 398 for(i in 1:2) {u=getd0(xx[i],d0,dat0,"I1",reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 399 if(endi == 1) break; } 400 if(endi == 0) 401 { 402 x=d0$X; y=d0$Y; 403 404 i1=0; 405 406 if(all(y==c(0,0))) 407 { 408 while(1) 409 { 410 i1=i1+1; 411 if(i1%%3 == 0) sg=2*sg; 412 xx=mi[2]+1.5*i1*sg; 413 u=getd0(xx,d0,dat0,"I1(i)",reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 414 if(d0$Y[nrow(d0)] == 1 | endi == 1) break; 415 } 416 } 417 418 if(all(y==c(1,1))) 419 { 420 while(1) 421 { 422 i1=i1+1; 423 if(i1%%3 == 0) sg=2*sg; 424 xx=mi[1]-1.5*i1*sg; 425 u=getd0(xx,d0,dat0,"I1(ii)",reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 426 427 if(d0$Y[nrow(d0)] == 0 | endi == 1) break; 428 } 429 } 430 431 if(all(y==c(0,1))) d0$ID=rep("I1(iii)",length(y)); 432 433 if(all(y==c(1,0))) 434 { 435 xx=c(mlo-3*sg,mhi+3*sg); 436 for(i in 1:2) 437 { 438 u=getd0(xx[i],d0,dat0,"I1(iv)",reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; 439 endi=u$endi; 440 if(endi == 1) break; 441 } 442 } 443 } 444 ret=list(d0,dat0,endi,sg); 445 names(ret)=nret; 446 return(ret); 447 } 448 449 phaseI2=function(d0,dat0,sg,reso,about,titl,unit,ln,term1) 450 { 451 nret=c("d0","dat0","endi","sg"); 452 xw = paste(" ** 3pod would normally enter I3 here **\n", sep = ""); 453 sav=0; 454 endi=0; 455 idii=""; 456 while(1) 457 { 458 # del = m1-M0; del < 0 ==> OVERLAP 459 j=m.update(d0); m1=j$m1; M0=j$M0; del=m1-M0; 460 while(del >= 1.5*sg & endi == 0) 461 { 462 if(endi == 0) 463 { 464 xx=(M0+m1)/2; 465 id=paste(idii,"I2(ib)",sep=""); 466 u=getd0(xx,d0,dat0,id,reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 467 468 j=m.update(d0); m1=j$m1; M0=j$M0; del=m1-M0; 469 } 470 } 471 if(del < 0 | endi == 1) {ret=list(d0,dat0,endi,sg); names=nret; return(ret)} 472 j=n.update(d0); n0=j$n0; n1=j$n1; 473 if(del >= 0 & endi == 0) 474

Page 7:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

{ 475 ixw=0; 476 if(n0 > n1 & endi == 0) 477 { 478 xx=m1+0.3*sg; 479 id=paste(idii,"I2(ic)",sep=""); 480 u=getd0(xx,d0,dat0,id,reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 481 if(d0$Y[nrow(d0)] == 0 | endi == 1) {ret=list(d0,dat0,endi,sg); names=nret; ixw=1;} 482 if(ixw == 1){ 483 if(term1) return(ret) else 484 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,0) | endi == 1) 485 {ret=list(d0,dat0,endi,sg); names=nret; return(ret); } } 486 } 487 if(d0$Y[nrow(d0)] == 1 & endi == 0) 488 { 489 xx=M0-.3*sg; 490 id=paste(idii,"I2(ic)",sep=""); 491 u=getd0(xx,d0,dat0,id,reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; 492 endi=u$endi; 493 if(d0$Y[nrow(d0)] == 1 | endi == 1) {ret=list(d0,dat0,endi,sg); names=nret; 494 ixw=1;} 495 if(ixw == 1){ 496 if(term1) {ret=list(d0,dat0,endi,sg); names=nret; return(ret)} else 497 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,1) | endi == 1) 498 {ret=list(d0,dat0,endi,sg); names=nret; return(ret); } } 499 } 500 if(d0$Y[nrow(d0)] == 0 & endi == 0) 501 { 502 sg=2*sg/3; 503 idii=paste(idii,"r",sep=""); 504 } 505 } 506 } 507 if(n0 <= n1 & endi == 0) 508 { 509 xx=M0-.3*sg; 510 id=paste(idii,"I2(id)",sep=""); 511 u=getd0(xx,d0,dat0,id,reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 512 if(d0$Y[nrow(d0)] == 1 | endi == 1) {ret=list(d0,dat0,endi,sg); names=nret; ixw=1;} 513 if(ixw == 1){ 514 if(term1) {ret=list(d0,dat0,endi,sg); names=nret; return(ret);} else 515 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,1) | endi == 1) 516 {ret=list(d0,dat0,endi,sg); names=nret; return(ret); } } 517 } 518 if(d0$Y[nrow(d0)] == 0 & endi == 0) 519 { 520 xx=m1+.3*sg; 521 id=paste(idii,"I2(id)",sep=""); 522 u=getd0(xx,d0,dat0,id,reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; 523 endi=u$endi; 524 if(d0$Y[nrow(d0)] == 0 | endi == 1) {ret=list(d0,dat0,endi,sg); names=nret; 525 ixw=1;} 526 if(ixw == 1){ 527 if(term1) {ret=list(d0,dat0,endi,sg); names=nret; return(ret);} else 528 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,0) | endi == 1) 529 {ret=list(d0,dat0,endi,sg); names=nret; return(ret); } } 530 } 531 if(d0$Y[nrow(d0)] == 1 & endi == 0) 532 { 533 sg=2*sg/3; 534 idii=paste(idii,"r",sep=""); 535 } 536 } 537 } 538 } 539 } 540 } 541 542 phaseI3=function(d0,dat0,sg,reso,about,titl,unit,ln,term1) 543 { 544 j=m.update(d0); M0=j$M0; m1=j$m1; del=m1-M0; 545 xx=(M0+m1)/2; 546 if(sg+del > 0)xx=xx+c(1,-1)*sg/2; 547 lxx=length(xx) 548 for(i in 1:lxx) 549 { 550 if(i < lxx) u=getd0(xx[i],d0,dat0,"I3",reso,about,titl,unit,ln); 551 if(i == lxx) u=getd0(xx[i],d0,dat0,"I3",reso,about,titl,unit,ln,cab=T); 552 d0=u$d0; dat0=u$dat0; endi=u$endi; 553

Page 8:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(!term1 & !ok1(d0)) endi=1; 554 if(endi == 1) break; 555 } 556 ret=list(d0,dat0,endi); 557 names(ret)=c("d0","dat0","endi"); 558 return(ret); 559 } 560 561 nphaseI=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,term1) 562 { 563 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 564 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 565 d0=d1[-1,]; names(d0)=names(d1)=cnam; 566 d0$ID=as.character(d0$ID); 567 if(is.null(dat0)) dat0=d0; 568 569 del=(mhi-mlo)/6; 570 571 eps=1e-007 572 n=0; 573 endi=0; 574 bl=c("B0","B1","B2","B3","B4"); 575 576 # lf is a flag to adjust X1 & X2 in the ln=T neyer case. Use of it makes it deviate a tad from 577 # a true neyer conducted on the logs - but this way X1 & X2 stay the same in both ln settings 578 lf=0; 579 580 while(endi == 0) 581 { 582 # PART 1 ************************************************************ 583 if(n == 0) block=0 else 584 { 585 j=n.update(d0); k0=j$n0; k1=j$n1; 586 xlo=min(d0$X) 587 xhi=max(d0$X) 588 if(k1 <= eps) block=1 else 589 { 590 if(k1 >= n-eps) block=2 else 591 { 592 # PART 2 ************************************************** 593 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 594 dif = round(m1-M0,14) 595 if(dif > sg) block=3 else 596 { 597 if(dif >= 0) block=4 else block=5; 598 } 599 } 600 } 601 } 602 # First 603 if(block == 0) if(!ln)xbef = (mlo+mhi)/2 else {v=ifg(mlo,mhi); xbef=log((v[1]+v[2])/2); lf=1;} 604 # All 0's 605 if(block == 1) if(lf == 0) xbef = max(c((mhi + xhi)/2, xhi + 2 * sg, 2 * xhi - xlo)) else 606 {xbef=log((v[1]+3*v[2])/4); lf=0;} 607 # All 1's 608 if(block == 2) if(lf == 0) xbef = min(c((mlo + xlo)/2, xlo - 2 * sg, 2 * xlo - xhi)) else 609 {xbef=log((3*v[1]+v[2])/4); lf=0;} 610 if(block == 3) xbef = (m1 + M0)/2 611 if(block == 4) 612 { 613 m=(m1+M0)/2; es=sg; sg=.8*sg; 614 m = max(xlo, min(m, xhi)) 615 es = min(es,(xhi-xlo)) 616 b = yinfomat(d0,m,es)$infm 617 xbef = m + kstar(b)*es 618 } 619 if(block == 5) {about=chabout(about,nrow(d0),5); if(term1) break else {if(ok1(d0)) break};} 620 u=getd0(xbef,d0,dat0,bl[block+1],reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 621 n=nrow(d0); 622 } 623 ret=list(d0,dat0,endi,sg); # NEW with 3podm 624 nret=c("d0","dat0","endi","sg"); # NEW with 3podm 625 names(ret)=nret; 626 return(ret); 627 } 628 629 bphaseI=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL) 630 { 631 nRev=BL[1]; I=BL[2:3]; I[I == 0] =-1; 632

Page 9:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

X=c(1,0); 633 nSeq=1+(I-I%%2)/2; 634 wz=which(I == -1); 635 if(length(wz) == 1) {X=X[-wz]; I=I[-wz]; nSeq=nSeq[-wz];} 636 lox=length(X); 637 udid=numeric(0); 638 639 nret=c("d0","dat0","endi","en12"); 640 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 641 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 642 d0=d1[-1,]; names(d0)=names(d1)=cnam; 643 d0$ID=as.character(d0$ID); 644 if(is.null(dat0)) dat0=d0; 645 646 en12=0; 647 648 for(ijk in 1:lox) 649 { 650 if(X[ijk] == 0) GE5=F else GE5=T; 651 652 # L=intToBitVect(nL), L is a List, nl is a vector of integers 653 # D's are the first 1:nSeq, U's are the last 1 or 2 depending on nAdd being 0 or 1, resp. 654 655 L=udli(I[ijk]); 656 nL=bintodec(L); 657 658 pl=zpfun(I[ijk]); 659 if(!GE5) pl=1-pl; 660 xx=mlo; 661 662 # initialize counter and accumulator 663 icnt=iacc=0; 664 dn=0; endi=0; ud=xud=numeric(0); yseq=numeric(0); 665 666 while(dn == 0 & endi == 0) 667 { 668 u=getd0(xx,d0,dat0,"IB",reso,about,titl,unit,ln); 669 670 d0=u$d0; dat0=u$dat0; endi=u$endi; 671 icnt=icnt+1; nx=length(d0$X); iacc=iacc+d0$X[[nx]]; 672 if(endi == 1) break; 673 y=d0$Y; 674 ny=length(y); 675 676 if(GE5) {yseq=c(yseq,y[ny]); udid=c(udid,y[ny]);} else 677 {yseq=c(yseq,1-y[ny]); udid=c(udid,1-y[ny]);} 678 679 lseq=list(yseq); ns=bintodec(lseq); 680 681 iw=which(nL == ns); 682 683 # Also will want to know if overlap has been achieved 684 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 685 dif = round(m1-M0,14); 686 if(!is.na(dif) & dif < 0 & nRev < 0) dn=1; 687 688 if(length(iw) == 1 & dn == 0) 689 { 690 xx=iacc/icnt; 691 xud=c(xud,xx); 692 nxud=length(xud); 693 kay=floor((xx-mlo)/sg); 694 pstar=(xx-mlo)/sg-floor((xx-mlo)/sg); 695 g=mlo+kay*sg; 696 697 if(GE5) 698 { 699 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=-2; if(pstar <= .5) xx=g-sg else xx=g;} 700 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=2; if(pstar <= .5) xx=g+sg else xx=g+2*sg;} 701 } else 702 { 703 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=2; if(pstar <= .5) xx=g+sg else xx=g+2*sg;} 704 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=-2; if(pstar <= .5) xx=g-sg else xx=g;} 705 } 706 icnt=iacc=0; 707 708 yseq=numeric(0); 709 cud=sum(abs(diff(ud))); 710 if(!is.na(dif) & nRev > 0) if(cud >= nRev & dif < 0) dn=1; 711

Page 10:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(!is.na(dif) & nRev == 0) if(dif < 0) dn=1; 712 713 # At this point, if dn = 1, the the reversal and overlap criteria are met 714 # Reset dn = 0 if Avg(X[Y==1]) <= Avg(X[Y==0]), i.e., if d.update(d0) < 1 715 if(d.update(d0) < 1) dn=0; 716 } 717 } 718 en12=c(en12,nx); 719 } 720 en12=diff(en12); 721 udid[abs(udid) != 2]=0; 722 udid[udid==-2]="D"; udid[udid==2]="U"; udid[udid == 0]=""; 723 d0$ID=udid; 724 ret=list(d0,dat0,endi,en12); # NEW with 3podm 725 names(ret)=nret; # NEW with 3podm 726 return(ret); 727 } 728 729 lphaseI=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL) 730 { 731 nRev=BL[1]; I=BL[2:3]; I[I == 0] =-1; 732 X=c(1,0); 733 nSeq=1+(I-I%%2)/2; 734 wz=which(I == -1); 735 if(length(wz) == 1) {X=X[-wz]; I=I[-wz]; nSeq=nSeq[-wz];} 736 lox=length(X); 737 udid=numeric(0); 738 739 nret=c("d0","dat0","endi","en12"); 740 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 741 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 742 d0=d1[-1,]; names(d0)=names(d1)=cnam; 743 d0$ID=as.character(d0$ID); 744 if(is.null(dat0)) dat0=d0; 745 746 en12=0; 747 748 for(ijk in 1:lox) 749 { 750 if(X[ijk] == 0)GE5=F else GE5=T; 751 752 # L=intToBitVect(nL), L is a List, nl is a vector of integers 753 # D's are the first 1:nSeq, U's are the last 1 or 2 depending on nAdd being 0 or 1, resp. 754 755 L=udli(I[ijk]); 756 nL=bintodec(L); 757 758 pl=zpfun(I[ijk]); 759 if(!GE5) pl=1-pl; 760 xx=mlo*(1-pl)+mhi*pl; 761 762 # initialize counter and accumulator 763 icnt=iacc=0; 764 dn=0; endi=0; ud=xud=numeric(0); yseq=numeric(0); 765 766 while(dn == 0 & endi == 0) 767 { 768 u=getd0(xx,d0,dat0,"IL",reso,about,titl,unit,ln); 769 d0=u$d0; dat0=u$dat0; endi=u$endi; 770 icnt=icnt+1; nx=length(d0$X); iacc=iacc+d0$X[[nx]]; 771 if(endi == 1) break; 772 773 y=d0$Y; 774 ny=length(y); 775 776 if(GE5) {yseq=c(yseq,y[ny]); udid=c(udid,y[ny]);} else 777 {yseq=c(yseq,1-y[ny]); udid=c(udid,1-y[ny]);} 778 779 lseq=list(yseq); ns=bintodec(lseq); 780 781 iw=which(nL == ns); 782 783 # Also will want to know if overlap has been achieved 784 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 785 dif = round(m1-M0,14); 786 if(!is.na(dif) & dif < 0 & nRev < 0) dn=1; 787 788 if(length(iw) == 1 & dn == 0) 789 { 790

Page 11:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(GE5) 791 { 792 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=-2;} 793 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=2;} 794 } else 795 { 796 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=2;} 797 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=-2;} 798 } 799 800 xud=c(xud,iacc/icnt); 801 nxud=length(xud); 802 rud=2*rev(ud)-1; 803 uc=cumsum(rud); 804 ic=which(uc == 0); 805 # Calculate xxa, xx, reset counters 806 if(length(ic) == 0) 807 { 808 if(GE5) 809 { 810 if(iw > nSeq[ijk]) xxa=mlo; 811 if(iw <= nSeq[ijk]) xxa=mhi; 812 } else 813 { 814 if(iw > nSeq[ijk]) xxa=mhi; 815 if(iw <= nSeq[ijk]) xxa=mlo; 816 } 817 } 818 if(length(ic) > 0) {ic=ic[1]; xxa=rev(xud); xxa=xxa[ic];} 819 xx=(xud[nxud]+xxa)/2; 820 821 icnt=iacc=0; 822 yseq=numeric(0); 823 cud=sum(abs(diff(ud))); 824 if(!is.na(dif) & nRev > 0) if(cud >= nRev & dif < 0) dn=1; 825 if(!is.na(dif) & nRev == 0) if(dif < 0) dn=1; 826 # At this point, if dn = 1, the the reversal and overlap criteria are met 827 # Reset dn = 0 if Avg(X[Y==1]) <= Avg(X[Y==0]), i.e., if d.update(d0) < 1 828 if(d.update(d0) < 1) dn=0; 829 } 830 } 831 en12=c(en12,nx); 832 } 833 en12=diff(en12); 834 udid[abs(udid) != 2]=0; 835 udid[udid==-2]="D"; udid[udid==2]="U"; udid[udid == 0]=""; 836 d0$ID=udid 837 838 ret=list(d0,dat0,endi,en12); # NEW with 3podm 839 names(ret)=nret; # NEW with 3podm 840 return(ret); 841 } 842 843 phaseII=function(d0,dat0,n2,reso,about,titl,unit,ln,term1) 844 { 845 xl=xu=xstar=mu2=mu4=sg2=sg4=rep(0,n2); 846 for(i in 1:n2) 847 { 848 nq=glmmle(d0); 849 mu2[i]=nq$mu; 850 sg2[i]=nq$sig; 851 xl[i]=min(d0$X); xu[i]=max(d0$X); 852 mu4[i]=max(xl[i],min(mu2[i],xu[i])); 853 sg4[i]=min(sg2[i],xu[i]-xl[i]); 854 b=yinfomat(d0,mu4[i],sg4[i])$infm; 855 xstar[i]=mu4[i]+kstar(b)*sg4[i]; 856 id="II1"; 857 if(i > 1) id="II2"; 858 u=getd0(xstar[i],d0,dat0,id,reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 859 if(term1) {if(endi == 1) break;} else 860 if(ok1(d0)$tf | endi == 1) break; 861 } 862 ret=list(d0,dat0,endi); 863 names=c("d0","dat0","endi"); 864 return(ret); 865 } 866 867 sphaseIII=function(d0,dat0,n3,p,reso,about,titl,unit,ln,lam=0) 868 { 869

Page 12:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

endi=0; 870 nret=c("d0","dat0","endi","jvec"); 871 jvec=matrix(rep(0,10*(n3+1)),ncol=10); 872 nq=glmmle(d0); 873 mu=nq$mu; sig=nq$sig; 874 875 # Calculate initial tau1^2 876 # this variance/covariance matrix (vcov1) is scale free 877 ww=yinfomat(d0,mu,sig); 878 tau2=sum(t(c(1,qnorm(p)^2))*diag(ww$vcov1)); 879 880 # Truncate tau2[1] 881 ti=round((c(3,5)/qnorm(.975))^2,4)*sig^2; 882 883 #** NEW 884 if(ln) ti=round((c(3,5)/qlnorm(.975))^2,4)*sig^2; 885 886 tau2=min(max(tau2,ti[1]),ti[2]); 887 888 # Use Mu Tilda and Sigma Tilda instead of Mu Hat and Sigma Hat 889 m1=min(d0$X,na.rm=T); 890 m2=max(d0$X,na.rm=T); 891 m2=min(c(mu,m2),na.rm=T); 892 mut=max(c(m1,m2),na.rm=T); 893 sigt=min(sig,diff(range(d0$X)),na.rm=T); 894 895 # Beta = 1/(2* SigmaTilda) per pp 9. You get beta = 0.4302985 896 # be=1/(2*sigt); 897 be=1/(2*sigt); 898 899 #** NEW 900 if(ln) be=(plnorm(qlnorm(p)))/(pnorm(qnorm(p))*sigt) 901 902 c1=f3point8(lam); 903 nu=sqrt(tau2)*c1; 904 905 xx=mut+qnorm(p)*sigt+nu; 906 u=getd0(xx,d0,dat0,"III1",reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; 907 ny=length(d0$Y); yy=d0$Y[ny]; 908 jvec[1,]=c(0,0,0,0,0,tau2,nu,0,xx,yy); 909 910 endi=u$endi; 911 912 if(endi != 1) 913 { 914 for(i in 1:n3) 915 { 916 # Compute next X|d0 917 vv=skewL(c1,nu,tau2,p,be); 918 a=vv[5]; tau2=vv[6]; nu=vv[7]; b=vv[8]; 919 xx=d0$X[nrow(d0)]-a*(d0$Y[nrow(d0)]-b); 920 921 if(i < n3) 922 { 923 u=getd0(xx,d0,dat0,"III2",reso,about,titl,unit,ln); d0=u$d0; dat0=u$dat0; endi=u$endi; 924 ny=length(d0$Y); 925 yy=d0$Y[ny] 926 jvec[i+1,]=c(vv,xx,yy); 927 if(endi == 1) {ret=list(d0,dat0,endi,jvec); names(ret)=nret; return(ret);} 928 } 929 if(i == n3) 930 { 931 d0=rbind(d0,d0[nrow(d0),]); 932 d0[nrow(d0),1:6]=c(0,0,0,round(xx,5),0,0); 933 d0$ID[nrow(d0)]="III3"; 934 jvec[i+1,]=c(vv,xx,NA); 935 endi=2; 936 } 937 } 938 } 939 jvec=data.frame(jvec); 940 names(jvec)=c("j","k","v","u","a","tau2","nu","b","x","y"); 941 ret=list(d0,dat0,endi,jvec); 942 names(ret)= nret; 943 return(ret); 944 } 945 946 # added cab to define n1 in the title of the graph produced by ptest 947 948

Page 13:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

getd0=function(xx,d0,dat0,ID,reso,about,titl,unit,ln,cab=F) 949 { 950 nret=c("d0","dat0","endi"); 951 mret=c("d0","about","title","units","ln"); 952 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 953 d1=data.frame(t(rep(0,6))); d1=cbind(d1,"END"); 954 names(d1)=names(d0)=cnam; 955 d0$ID=as.character(d0$ID); 956 if(is.null(dat0)) dat0=d1[-1,]; 957 n0=nrow(dat0); nd0=nrow(d0)+1; 958 endi=0; 959 if(n0 == 0) 960 { 961 u=getxr(xx,nd0,reso,ln); 962 d1[1,1:6]=c(u[1:2],1,u[3],xx,u[4]); d1$ID=ID; 963 if(u[2]*(1-u[2])!=0) 964 {endi=1; ret=list(d0,dat0,endi); names(ret)=nret; 965 ret5=list(d0,about,titl,unit,ln); names(ret5)=mret; 966 if(nrow(d0) > 0) {ptest(ret5,1);} 967 return(ret); 968 } 969 } 970 if(n0 > 0) {d1=dat0[1,]; dat0=dat0[-1,]; if(is.null(dat0)) dat0=d1[-1,]; n0=nrow(dat0);} 971 d0=rbind(d0,d1); 972 ret=list(d0,dat0,endi); 973 if(cab)about=chabout(about,nrow(d0),4); 974 ret5=list(d0,about,titl,unit,ln); names(ret5)=mret; 975 if(nrow(d0) > 1) ptest(ret5,1); 976 names(ret)=nret; 977 return(ret); 978 } 979 980 getxr=function(x,nd0,reso,ln) 981 { 982 buf=" "; 983 if(ln) x=exp(x); 984 if(nd0>9)buf=""; 985 rx=round(x,5); if(reso > 0)rx=round(x/reso)*reso; 986 xx = paste(buf,nd0,". Test at X ~ ",rx,". Enter X & R: ", sep = ""); 987 xx=readline(xx); 988 xx=as.numeric(unlist(strsplit(xx," "))); 989 tx=xx[1]; 990 if(ln) xx[1]=round(log(tx),5); 991 return(c(xx,rx,tx)); 992 } 993 994 phaseBI1=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,Y) 995 { 996 lY=length(Y); 997 nret=c("d0","dat0","endi","sg","Y"); 998 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 999 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 1000 d0=d1[-1,]; names(d0)=names(d1)=cnam; 1001 d0$ID=as.character(d0$ID); 1002 if(is.null(dat0)) dat0=d0; 1003 endi=0; 1004 mi=c(mlo,mhi); 1005 a=matrix(c(.75,.25,.25,.75),ncol=2,byrow=T); 1006 xx=t(a%*%mi); 1007 1008 for(i in 1:min(lY,2)) {u=getBd0(xx[i],d0,dat0,"I1",reso,about,titl,unit,ln,Y[i]); d0=u$d0; dat0=u$dat0; 1009 endi=u$endi; if(endi == 1) break; } 1010 Y=Y[-(1:min(lY,2))]; lY=length(Y); if(lY == 0) endi=1; 1011 if(endi == 0) 1012 { 1013 x=d0$X; y=d0$Y; 1014 i1=0; 1015 if(all(y==c(0,0))) 1016 { 1017 while(lY > 0) 1018 { 1019 i1=i1+1; 1020 if(i1%%3 == 0) sg=2*sg; 1021 xx=mi[2]+1.5*i1*sg; 1022 u=getBd0(xx,d0,dat0,"I1(i)",reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi; 1023 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1024 if(d0$Y[nrow(d0)] == 1 | endi == 1) break; 1025 } 1026 } 1027

Page 14:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

1028 if(all(y==c(1,1))) 1029 { 1030 while(lY > 0) 1031 { 1032 i1=i1+1; 1033 if(i1%%3 == 0) sg=2*sg; 1034 xx=mi[1]-1.5*i1*sg; 1035 u=getBd0(xx,d0,dat0,"I1(ii)",reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi;1036 1037 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1038 if(d0$Y[nrow(d0)] == 0 | endi == 1) break; 1039 } 1040 } 1041 1042 if(all(y==c(0,1))) d0$ID=rep("I1(iii)",length(y)); 1043 1044 if(all(y==c(1,0))) 1045 { 1046 xx=c(mlo-3*sg,mhi+3*sg); 1047 for(i in 1:min(lY,2)) 1048 { 1049 u=getBd0(xx[i],d0,dat0,"I1(iv)",reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; 1050 endi=u$endi; 1051 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1052 if(endi == 1) break; 1053 } 1054 } 1055 } 1056 ret=list(d0,dat0,endi,sg,Y); 1057 names(ret)=nret; 1058 return(ret); 1059 } 1060 1061 phaseBI2=function(d0,dat0,sg,reso,about,titl,unit,ln,term1,Y) 1062 { 1063 nret=c("d0","dat0","endi","sg","Y"); 1064 xw = paste(" ** 3pod would normally enter I3 here **\n", sep = ""); 1065 sav=0; 1066 endi=0; 1067 idii=""; 1068 while(1) 1069 { 1070 # del = m1-M0; del < 0 ==> OVERLAP 1071 j=m.update(d0); m1=j$m1; M0=j$M0; del=m1-M0; 1072 while(del >= 1.5*sg & endi == 0) 1073 { 1074 if(endi == 0) 1075 { 1076 xx=(M0+m1)/2; 1077 id=paste(idii,"I2(ib)",sep=""); 1078 u=getBd0(xx,d0,dat0,id,reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi;1079 1080 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1081 j=m.update(d0); m1=j$m1; M0=j$M0; del=m1-M0; 1082 } 1083 } 1084 if(del < 0 | endi == 1) {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret)} 1085 j=n.update(d0); n0=j$n0; n1=j$n1; 1086 if(del >= 0 & endi == 0) 1087 { 1088 ixw=0; 1089 if(n0 > n1 & endi == 0) 1090 { 1091 xx=m1+0.3*sg; 1092 id=paste(idii,"I2(ic)",sep=""); 1093 u=getBd0(xx,d0,dat0,id,reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi; 1094 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1095 if(d0$Y[nrow(d0)] == 0 | endi == 1) {ret=list(d0,dat0,endi,sg,Y); names=nret; ixw=1;} 1096 if(ixw == 1){ 1097 if(term1) return(ret) else 1098 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,0) | endi == 1) 1099 {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret); } } 1100 } 1101 if(d0$Y[nrow(d0)] == 1 & endi == 0) 1102 { 1103 xx=M0-.3*sg; 1104 id=paste(idii,"I2(ic)",sep=""); 1105

Page 15:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

u=getBd0(xx,d0,dat0,id,reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; 1106 endi=u$endi; 1107 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1108 if(d0$Y[nrow(d0)] == 1 | endi == 1) {ret=list(d0,dat0,endi,sg,Y); names=nret; 1109 ixw=1;} 1110 if(ixw == 1){ 1111 if(term1) {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret)} else 1112 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,1) | endi == 1) 1113 {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret); } } 1114 } 1115 if(d0$Y[nrow(d0)] == 0 & endi == 0) 1116 { 1117 sg=2*sg/3; 1118 idii=paste(idii,"r",sep=""); 1119 } 1120 } 1121 } 1122 if(n0 <= n1 & endi == 0) 1123 { 1124 xx=M0-.3*sg; 1125 id=paste(idii,"I2(id)",sep=""); 1126 u=getBd0(xx,d0,dat0,id,reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi; 1127 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1128 if(d0$Y[nrow(d0)] == 1 | endi == 1) {ret=list(d0,dat0,endi,sg,Y); names=nret; ixw=1;} 1129 if(ixw == 1){ 1130 if(term1) {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret);} else 1131 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,1) | endi == 1) 1132 {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret); } } 1133 } 1134 if(d0$Y[nrow(d0)] == 0 & endi == 0) 1135 { 1136 xx=m1+.3*sg; 1137 id=paste(idii,"I2(id)",sep=""); 1138 u=getBd0(xx,d0,dat0,id,reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; 1139 endi=u$endi; 1140 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1141 if(d0$Y[nrow(d0)] == 0 | endi == 1) {ret=list(d0,dat0,endi,sg,Y); names=nret; 1142 ixw=1;} 1143 if(ixw == 1){ 1144 if(term1) {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret);} else 1145 {if(ixw == 1 & sav == 0) {cat(xw); sav=1; ixw=0}; if(ok1(d0,0) | endi == 1) 1146 {ret=list(d0,dat0,endi,sg,Y); names=nret; return(ret); } } 1147 } 1148 if(d0$Y[nrow(d0)] == 1 & endi == 0) 1149 { 1150 sg=2*sg/3; 1151 idii=paste(idii,"r",sep=""); 1152 } 1153 } 1154 } 1155 } 1156 } 1157 } 1158 1159 phaseBI3=function(d0,dat0,sg,reso,about,titl,unit,ln,term1,Y) 1160 { 1161 j=m.update(d0); M0=j$M0; m1=j$m1; del=m1-M0; 1162 xx=(M0+m1)/2; 1163 if(sg+del > 0)xx=xx+c(1,-1)*sg/2; 1164 lxx=length(xx) 1165 for(i in 1:lxx) 1166 { 1167 if(i < lxx) u=getBd0(xx[i],d0,dat0,"I3",reso,about,titl,unit,ln,Y[1]); 1168 if(i == lxx) u=getBd0(xx[i],d0,dat0,"I3",reso,about,titl,unit,ln,Y[1],cab=T); 1169 d0=u$d0; dat0=u$dat0; endi=u$endi; 1170 if(!term1 & !ok1(d0)) endi=1; 1171 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1172 if(endi == 1) break; 1173 } 1174 ret=list(d0,dat0,endi,Y); 1175 names(ret)=c("d0","dat0","endi","Y"); 1176 return(ret); 1177 } 1178 1179 nphaseBI=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,term1,Y) 1180 { 1181 lY=length(Y) 1182 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 1183 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 1184

Page 16:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

d0=d1[-1,]; names(d0)=names(d1)=cnam; 1185 d0$ID=as.character(d0$ID); 1186 if(is.null(dat0)) dat0=d0; 1187 1188 del=(mhi-mlo)/6; 1189 1190 eps=1e-007 1191 n=0; 1192 endi=0; 1193 bl=c("B0","B1","B2","B3","B4"); 1194 1195 # lf is a flag to adjust X1 & X2 in the ln=T neyer case. Use of it makes it deviate a tad from 1196 # a true neyer conducted on the logs - but this way X1 & X2 stay the same in both ln settings 1197 lf=0; 1198 1199 while(endi == 0) 1200 { 1201 # PART 1 ************************************************************ 1202 if(n == 0) block=0 else 1203 { 1204 j=n.update(d0); k0=j$n0; k1=j$n1; 1205 xlo=min(d0$X) 1206 xhi=max(d0$X) 1207 if(k1 <= eps) block=1 else 1208 { 1209 if(k1 >= n-eps) block=2 else 1210 { 1211 # PART 2 ************************************************** 1212 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 1213 dif = round(m1-M0,14) 1214 if(dif > sg) block=3 else 1215 { 1216 if(dif >= 0) block=4 else block=5; 1217 } 1218 } 1219 } 1220 } 1221 # First 1222 if(block == 0) if(!ln)xbef = (mlo+mhi)/2 else {v=ifg(mlo,mhi); xbef=log((v[1]+v[2])/2); lf=1;} 1223 # All 0's 1224 if(block == 1) if(lf == 0) xbef = max(c((mhi + xhi)/2, xhi + 2 * sg, 2 * xhi - xlo)) else 1225 {xbef=log((v[1]+3*v[2])/4); lf=0;} 1226 # All 1's 1227 if(block == 2) if(lf == 0) xbef = min(c((mlo + xlo)/2, xlo - 2 * sg, 2 * xlo - xhi)) else 1228 {xbef=log((3*v[1]+v[2])/4); lf=0;} 1229 if(block == 3) xbef = (m1 + M0)/2 1230 if(block == 4) 1231 { 1232 m=(m1+M0)/2; es=sg; sg=.8*sg; 1233 m = max(xlo, min(m, xhi)) 1234 es = min(es,(xhi-xlo)) 1235 #v = ykpm(d0,m,es) 1236 #xbef = v$xstar 1237 b = yinfomat(d0,m,es)$infm 1238 xbef = m + kstar(b)*es 1239 } 1240 if(block == 5) {about=chabout(about,nrow(d0),5); if(term1) break else {if(ok1(d0)) break};} 1241 u=getBd0(xbef,d0,dat0,bl[block+1],reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi; 1242 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1243 n=nrow(d0); 1244 } 1245 ret=list(d0,dat0,endi,sg,Y); # NEW with 3podm 1246 nret=c("d0","dat0","endi","sg","Y"); # NEW with 3podm 1247 names(ret)=nret; 1248 return(ret); 1249 } 1250 1251 bphaseBI=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL,Y) 1252 { 1253 nRev=BL[1]; I=BL[2:3]; I[I == 0] =-1; 1254 X=c(1,0); 1255 nSeq=1+(I-I%%2)/2; 1256 wz=which(I == -1); 1257 if(length(wz) == 1) {X=X[-wz]; I=I[-wz]; nSeq=nSeq[-wz];} 1258 lox=length(X); 1259 udid=numeric(0); 1260 1261 nret=c("d0","dat0","endi","Y","en12"); 1262 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 1263

Page 17:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 1264 d0=d1[-1,]; names(d0)=names(d1)=cnam; 1265 d0$ID=as.character(d0$ID); 1266 if(is.null(dat0)) dat0=d0; 1267 1268 en12=0; 1269 1270 for(ijk in 1:lox) 1271 { 1272 if(X[ijk] == 0) GE5=F else GE5=T; 1273 1274 # L=intToBitVect(nL), L is a List, nl is a vector of integers 1275 # D's are the first 1:nSeq, U's are the last 1 or 2 depending on nAdd being 0 or 1, resp. 1276 1277 L=udli(I[ijk]); 1278 nL=bintodec(L); 1279 1280 pl=zpfun(I[ijk]); 1281 if(!GE5) pl=1-pl; 1282 xx=mlo; 1283 1284 # initialize counter and accumulator 1285 icnt=iacc=0; 1286 dn=0; endi=0; ud=xud=numeric(0); yseq=numeric(0); 1287 1288 while(dn == 0 & endi == 0) 1289 { 1290 u=getBd0(xx,d0,dat0,"",reso,about,titl,unit,ln,Y[1]); 1291 1292 d0=u$d0; dat0=u$dat0; endi=u$endi; 1293 icnt=icnt+1; nx=length(d0$X); iacc=iacc+d0$X[[nx]]; 1294 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1295 y=d0$Y; 1296 ny=length(y); 1297 1298 if(GE5) {yseq=c(yseq,y[ny]); udid=c(udid,y[ny]);} else 1299 {yseq=c(yseq,1-y[ny]); udid=c(udid,1-y[ny]);} 1300 1301 lseq=list(yseq); ns=bintodec(lseq); 1302 iw=which(nL == ns); 1303 1304 # Also will want to know if overlap has been achieved 1305 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 1306 dif = round(m1-M0,14); 1307 if(!is.na(dif) & dif < 0 & nRev < 0) dn=1; 1308 1309 if(length(iw) == 1 & dn == 0) 1310 { 1311 xx=iacc/icnt; 1312 xud=c(xud,xx); 1313 nxud=length(xud); 1314 kay=floor((xx-mlo)/sg); 1315 pstar=(xx-mlo)/sg-floor((xx-mlo)/sg); 1316 g=mlo+kay*sg; 1317 1318 if(GE5) 1319 { 1320 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=-2; if(pstar <= .5) xx=g-sg else xx=g;} 1321 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=2; if(pstar <= .5) xx=g+sg else xx=g+2*sg;} 1322 } else 1323 { 1324 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=2; if(pstar <= .5) xx=g+sg else xx=g+2*sg;} 1325 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=-2; if(pstar <= .5) xx=g-sg else xx=g;} 1326 } 1327 icnt=iacc=0; 1328 1329 yseq=numeric(0); 1330 cud=sum(abs(diff(ud))); 1331 if(!is.na(dif) & nRev > 0) if(cud >= nRev & dif < 0) dn=1; 1332 if(!is.na(dif) & nRev == 0) if(dif < 0) dn=1; 1333 1334 # At this point, if dn = 1, the the reversal and overlap criteria are met 1335 # Reset dn = 0 if Avg(X[Y==1]) <= Avg(X[Y==0]), i.e., if d.update(d0) < 1 1336 if(d.update(d0) < 1) dn=0; 1337 } 1338 } 1339 en12=c(en12,nx); 1340 } 1341 en12=diff(en12); 1342

Page 18:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

udid[abs(udid) != 2]=0; 1343 udid[udid==-2]="D"; udid[udid==2]="U"; udid[udid == 0]=""; 1344 d0$ID=udid; 1345 ret=list(d0,dat0,endi,Y,en12); # NEW with 3podm 1346 names(ret)=nret; # NEW with 3podm 1347 return(ret); 1348 } 1349 1350 lphaseBI=function(dat0,mlo,mhi,sg,reso,about,titl,unit,ln,BL,Y) 1351 { 1352 nRev=BL[1]; I=BL[2:3]; I[I == 0] =-1; 1353 X=c(1,0); 1354 nSeq=1+(I-I%%2)/2; 1355 wz=which(I == -1); 1356 if(length(wz) == 1) {X=X[-wz]; I=I[-wz]; nSeq=nSeq[-wz];} 1357 lox=length(X); 1358 udid=numeric(0); 1359 1360 nret=c("d0","dat0","endi","Y","en12"); 1361 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 1362 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 1363 d0=d1[-1,]; names(d0)=names(d1)=cnam; 1364 d0$ID=as.character(d0$ID); 1365 if(is.null(dat0)) dat0=d0; 1366 1367 en12=0; 1368 1369 for(ijk in 1:lox) 1370 { 1371 if(X[ijk] == 0)GE5=F else GE5=T; 1372 1373 # L=intToBitVect(nL), L is a List, nl is a vector of integers 1374 # D's are the first 1:nSeq, U's are the last 1 or 2 depending on nAdd being 0 or 1, resp. 1375 1376 L=udli(I[ijk]); 1377 nL=bintodec(L); 1378 1379 pl=zpfun(I[ijk]); 1380 if(!GE5) pl=1-pl; 1381 xx=mlo*(1-pl)+mhi*pl; 1382 1383 # initialize counter and accumulator 1384 icnt=iacc=0; 1385 dn=0; endi=0; ud=xud=numeric(0); yseq=numeric(0); 1386 1387 while(dn == 0 & endi == 0) 1388 { 1389 u=getBd0(xx,d0,dat0,"",reso,about,titl,unit,ln,Y[1]); 1390 d0=u$d0; dat0=u$dat0; endi=u$endi; 1391 icnt=icnt+1; nx=length(d0$X); iacc=iacc+d0$X[[nx]]; 1392 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1393 y=d0$Y; 1394 ny=length(y); 1395 1396 if(GE5) {yseq=c(yseq,y[ny]); udid=c(udid,y[ny]);} else 1397 {yseq=c(yseq,1-y[ny]); udid=c(udid,1-y[ny]);} 1398 1399 lseq=list(yseq); ns=bintodec(lseq); 1400 1401 iw=which(nL == ns); 1402 1403 # Also want to know if overlap has been achieved 1404 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 1405 dif = round(m1-M0,14); 1406 if(!is.na(dif) & dif < 0 & nRev < 0) dn=1; 1407 1408 if(length(iw) == 1 & dn == 0) 1409 { 1410 if(GE5) 1411 { 1412 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=-2;} 1413 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=2;} 1414 } else 1415 { 1416 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=2;} 1417 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=-2;} 1418 } 1419 1420 xud=c(xud,iacc/icnt); 1421

Page 19:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

nxud=length(xud); 1422 rud=2*rev(ud)-1; 1423 uc=cumsum(rud); 1424 ic=which(uc == 0); 1425 # Calculate xxa, xx, reset counters 1426 if(length(ic) == 0) 1427 { 1428 if(GE5) 1429 { 1430 if(iw > nSeq[ijk]) xxa=mlo; 1431 if(iw <= nSeq[ijk]) xxa=mhi; 1432 } else 1433 { 1434 if(iw > nSeq[ijk]) xxa=mhi; 1435 if(iw <= nSeq[ijk]) xxa=mlo; 1436 } 1437 } 1438 if(length(ic) > 0) {ic=ic[1]; xxa=rev(xud); xxa=xxa[ic];} 1439 xx=(xud[nxud]+xxa)/2; 1440 1441 icnt=iacc=0; 1442 yseq=numeric(0); 1443 cud=sum(abs(diff(ud))); 1444 if(!is.na(dif) & nRev > 0) if(cud >= nRev & dif < 0) dn=1; 1445 if(!is.na(dif) & nRev == 0) if(dif < 0) dn=1; 1446 # At this point, if dn = 1, then the reversal and overlap criteria are met 1447 # Reset dn = 0 if Avg(X[Y==1]) <= Avg(X[Y==0]), i.e., if d.update(d0) < 1 1448 if(d.update(d0) < 1) dn=0; 1449 } 1450 } 1451 en12=c(en12,nx); 1452 } 1453 en12=diff(en12); 1454 udid[abs(udid) != 2]=0; 1455 udid[udid==-2]="D"; udid[udid==2]="U"; udid[udid == 0]=""; 1456 d0$ID=udid 1457 1458 ret=list(d0,dat0,endi,Y,en12); 1459 names(ret)=nret; # NEW with 3podm 1460 return(ret); 1461 } 1462 1463 phaseBII=function(d0,dat0,n2,reso,about,titl,unit,ln,term1,Y) 1464 { 1465 xl=xu=xstar=mu2=mu4=sg2=sg4=rep(0,n2); 1466 lY=length(Y); 1467 for(i in 1:min(n2,lY)) 1468 { 1469 nq=glmmle(d0); 1470 mu2[i]=nq$mu; 1471 sg2[i]=nq$sig; 1472 xl[i]=min(d0$X); xu[i]=max(d0$X); 1473 mu4[i]=max(xl[i],min(mu2[i],xu[i])); 1474 sg4[i]=min(sg2[i],xu[i]-xl[i]); 1475 b=yinfomat(d0,mu4[i],sg4[i])$infm; 1476 xstar[i]=mu4[i]+kstar(b)*sg4[i]; 1477 id="II1"; 1478 if(i > 1) id="II2"; 1479 u=getBd0(xstar[i],d0,dat0,id,reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi; 1480 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1481 if(term1) {if(endi == 1) break;} else 1482 if(ok1(d0)$tf | endi == 1) break; 1483 } 1484 ret=list(d0,dat0,endi,Y); 1485 names=c("d0","dat0","endi","Y"); 1486 return(ret); 1487 } 1488 1489 sphaseBIII=function(d0,dat0,n3,p,reso,about,titl,unit,ln,Y,lam=0) 1490 { 1491 lY=length(Y); 1492 endi=0; 1493 nret=c("d0","dat0","endi","jvec","Y"); 1494 jvec=matrix(rep(0,10*(n3+1)),ncol=10); 1495 nq=glmmle(d0); 1496 mu=nq$mu; sig=nq$sig; 1497 1498 # Calculate initial tau1^2 1499 # this variance/covariance matrix (vcov1) is scale free 1500

Page 20:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

ww=yinfomat(d0,mu,sig); 1501 tau2=sum(t(c(1,qnorm(p)^2))*diag(ww$vcov1)); 1502 1503 # Truncate tau2[1] 1504 ti=round((c(3,5)/qnorm(.975))^2,4)*sig^2; 1505 1506 #** NEW 1507 if(ln) ti=round((c(3,5)/qlnorm(.975))^2,4)*sig^2; 1508 1509 tau2=min(max(tau2,ti[1]),ti[2]); 1510 1511 # Use Mu Tilda and Sigma Tilda instead of Mu Hat and Sigma Hat 1512 m1=min(d0$X,na.rm=T); 1513 m2=max(d0$X,na.rm=T); 1514 m2=min(c(mu,m2),na.rm=T); 1515 mut=max(c(m1,m2),na.rm=T); 1516 sigt=min(sig,diff(range(d0$X)),na.rm=T); 1517 1518 # Beta = 1/(2* SigmaTilda) per pp 9. You get beta = 0.4302985 1519 be=1/(2*sigt); 1520 1521 #** NEW 1522 if(ln) be=plnorm(qlnorm(p))/(pnorm(qnorm(p))*sigt) 1523 1524 c1=f3point8(lam); 1525 nu=sqrt(tau2)*c1; 1526 1527 xx=mut+qnorm(p)*sigt+nu; 1528 u=getBd0(xx,d0,dat0,"III1",reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; 1529 ny=length(d0$Y); yy=d0$Y[ny]; 1530 jvec[1,]=c(0,0,0,0,0,tau2,nu,0,xx,yy); 1531 1532 endi=u$endi; 1533 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1534 1535 if(endi != 1) 1536 { 1537 mn3=min(n3,lY); 1538 for(i in 1:mn3) 1539 { 1540 # Compute next X|d0 1541 vv=skewL(c1,nu,tau2,p,be); 1542 a=vv[5]; tau2=vv[6]; nu=vv[7]; b=vv[8]; 1543 xx=d0$X[nrow(d0)]-a*(d0$Y[nrow(d0)]-b); 1544 1545 if(i < mn3) 1546 { 1547 u=getBd0(xx,d0,dat0,"III2",reso,about,titl,unit,ln,Y[1]); d0=u$d0; dat0=u$dat0; endi=u$endi; 1548 Y=Y[-1]; lY=length(Y); if(lY == 0) endi=1; 1549 ny=length(d0$Y); 1550 yy=d0$Y[ny] 1551 jvec[i+1,]=c(vv,xx,yy); 1552 if(endi == 1) {ret=list(d0,dat0,endi,jvec); names(ret)=nret; return(ret);} 1553 } 1554 if(i == mn3) 1555 { 1556 d0=rbind(d0,d0[nrow(d0),]); 1557 d0[nrow(d0),1:6]=c(0,0,0,round(xx,5),0,0); 1558 d0$ID[nrow(d0)]="III3"; 1559 jvec[i+1,]=c(vv,xx,NA); 1560 endi=2; 1561 } 1562 } 1563 } 1564 jvec=data.frame(jvec); 1565 names(jvec)=c("j","k","v","u","a","tau2","nu","b","x","y"); 1566 ret=list(d0,dat0,endi,jvec,Y); 1567 names(ret)= nret; 1568 return(ret); 1569 } 1570 1571 getBd0=function(xx,d0,dat0,ID,reso,about,titl,unit,ln,Y,cab=F) 1572 { 1573 nret=c("d0","dat0","endi"); 1574 mret=c("d0","about","title","units","ln"); 1575 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 1576 d1=data.frame(t(rep(0,6))); d1=cbind(d1,"END"); 1577 names(d1)=names(d0)=cnam; 1578 d0$ID=as.character(d0$ID); 1579

Page 21:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(is.null(dat0)) dat0=d1[-1,]; 1580 n0=nrow(dat0); nd0=nrow(d0)+1; 1581 endi=0; 1582 if(n0 == 0) 1583 { 1584 u=getBxr(xx,nd0,reso,ln,Y) 1585 d1[1,1:6]=c(u[1:2],1,u[3],xx,u[4]); d1$ID=ID; 1586 if(u[2]*(1-u[2])!=0) 1587 {endi=1; ret=list(d0,dat0,endi); names(ret)=nret; 1588 ret5=list(d0,about,titl,unit,ln); names(ret5)=mret; 1589 if(nrow(d0) > 0) {ptest(ret5,1);} 1590 return(ret); 1591 } 1592 } 1593 if(n0 > 0) {d1=dat0[1,]; dat0=dat0[-1,]; if(is.null(dat0)) dat0=d1[-1,]; n0=nrow(dat0);} 1594 d0=rbind(d0,d1); 1595 ret=list(d0,dat0,endi); 1596 if(cab)about=chabout(about,nrow(d0),4); 1597 ret5=list(d0,about,titl,unit,ln); names(ret5)=mret; 1598 if(nrow(d0) > 1) ptest(ret5,1); 1599 names(ret)=nret; 1600 return(ret); 1601 } 1602 1603 getBxr=function(x,nd0,reso,ln,Y) 1604 { 1605 buf=" "; 1606 if(ln) x=exp(x); 1607 if(nd0>9)buf=""; 1608 rx=round(x,5); if(reso > 0)rx=round(x/reso)*reso; 1609 xx=c(rx,Y) 1610 tx=xx[1]; 1611 if(ln) xx[1]=round(log(tx),5); 1612 return(c(xx,rx,tx)); 1613 } 1614 1615 prd0=function(z) 1616 { 1617 test=z$test; 1618 d00=z$d0; 1619 en=z$en; 1620 pp=z$p; 1621 llam=z$lam; 1622 n2n3=z$n2n3; 1623 n=cumsum(en); 1624 n0=nrow(d00); 1625 ln=z$ln; 1626 u=d00$X; 1627 if(ln) u=round(exp(u),5); 1628 cat(paste("Enter title (without quotes): ",z$title,"\n",sep="")); 1629 cat(paste("Enter units (without quotes): ",z$units,"\n",sep="")); 1630 if(n0 == 0)return(n2n3) 1631 if(test > 2) 1632 { 1633 a=paste(z$trans,collapse=" "); 1634 xx=paste("Enter nRev nSeq nAdd X (without quotes): ",a,"\n",sep=""); 1635 cat(xx); 1636 dud=prtrans(z$BL); 1637 } else cat("\n") 1638 for(i in 1:n0) 1639 { 1640 buf=" ";if(i>9)buf=""; 1641 xx = paste(buf,i,". Test at X ~ ",d00$RX[i],". Enter X & R: ",u[i]," ",d00$Y[i],"\n", sep = 1642 ""); 1643 cat(xx); 1644 1645 if(i == en[1] & (en[2] != 0 | n2n3 ==2)){ 1646 gg=glmmle(d00[1:n[1],]); g1=round(gg$mu,5); g2=round(gg$sig,5); 1647 xx=paste("\nPhase I complete, (Mu, Sig) = (",g1,", ",g2,").\n",sep=""); 1648 cat(xx); 1649 1650 if(en[2] == 0 & i == en[1] & n2n3 == 2) 1651 { 1652 xx=paste("Enter Phase II (D-Optimal) size n2: ",en[2],"\n",sep=""); 1653 cat(xx); 1654 } 1655 1656 if(en[2] == 0 & en[3] > 0) 1657 { 1658

Page 22:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

xx=paste("Enter Phase II (D-Optimal) size n2: ",en[2],"\n",sep=""); 1659 cat(xx); 1660 } 1661 1662 if(en[2] > 0) 1663 { 1664 xx=paste("Enter Phase II (D-Optimal) size n2: ",en[2],"\n\n",sep=""); 1665 cat(xx); 1666 } 1667 } 1668 1669 if(en[2] != 0 & i == n[2]){ 1670 if(en[3]>0) 1671 { 1672 gg=glmmle(d00[1:n[2],]); g1=round(gg$mu,5); g2=round(gg$sig,5); 1673 xx=paste("\nPhase II complete, (Mu, Sig) = (",g1,", ",g2,").\n",sep=""); 1674 cat(xx); 1675 } 1676 i7=0 1677 if(en[3] > 0) 1678 { 1679 xx=paste("Enter Phase III (RMJ) size n3: ",en[3],"\n",sep=""); 1680 cat(xx); 1681 i7=1 1682 } 1683 if(pp > 0 & pp < 1) 1684 { 1685 xx=paste("Enter Phase III (RMJ) size n3: ",en[3],"\n",sep=""); 1686 if(i7 == 0)cat(xx); 1687 xx=paste("Enter p lam: ",pp," ",llam,"\n\n",sep=""); 1688 cat(xx); 1689 } 1690 } 1691 1692 if(en[2] == 0 & en[3] > 0 & i >= n[2] & n2n3 != 5){ 1693 gg=glmmle(d00[1:n[2],]); g1=round(gg$mu,5); g2=round(gg$sig,5); 1694 xx=paste("\nPhase I complete, (Mu, Sig) = (",g1,", ",g2,").\n",sep=""); 1695 cat(xx); 1696 xx=paste("Enter Phase II (D-Optimal) size n2: ",en[2],"\n",sep=""); 1697 cat(xx); 1698 xx=paste("\n\nPhase II skipped, (Mu, Sig) = (",g1,", ",g2,").\n",sep=""); 1699 cat(xx); 1700 xx=paste("Enter Phase III (RMJ) size n3: ",en[3],"\n",sep=""); 1701 cat(xx); 1702 1703 if(n2n3 == 4) {xx=paste("Enter p lam: ",pp," ",llam,"\n\n",sep=""); cat(xx); } 1704 n2n3=5; 1705 } 1706 } 1707 return(n2n3) 1708 } 1709 1710 d.update=function(dat) 1711 { 1712 x=dat[,1]; 1713 y=dat[,2]; 1714 x1=x[y==1]; 1715 n1=length(x1); 1716 x0=x[y==0]; 1717 n0=length(x0); 1718 if(n1*n0 != 0) return(sign(mean(x1)-mean(x0))) else return(0) 1719 } 1720 1721 ok1=function(dat,y=2) 1722 { 1723 nr=nrow(dat); 1724 yy=dat$Y[nr]; 1725 j1=m.update(dat); 1726 j2=d.update(dat); 1727 j3=sign(j1$M0-j1$m1); 1728 if(j2 == 1 & j3 == 1) tf=T else tf=F; 1729 if(y == 2) tf & yy==y; 1730 return(tf) 1731 } 1732 1733 chabout=function(about,s47,loc) 1734 { 1735 x=about; 1736 x1=gsub("[|]",",",x); 1737

Page 23:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

x2=gsub("[{]","vv=c(",x1) 1738 x3=gsub("[}]",")",x2) 1739 eval(parse(text=paste(x3))) 1740 vv[loc]=s47; 1741 a=wabout(vv); 1742 return(a) 1743 } 1744 1745 wabout=function(vv) 1746 { 1747 f=","; 1748 c=sub("^(-?)0.", "\\1.", vv); 1749 about=paste("{",c[1],f,c[2],f,c[3],"|",c[4],f,c[5],f,c[6],"|",c[7],f,c[8],f,c[9],"}",sep=""); 1750 return(about); 1751 } 1752 1753 blrb7=function() 1754 { 1755 x= 1756 " 1757 Entry into Phase II requires that a positive and finite sigma exists. 1758 Thus, M0 > m1 (for overlap) & delta = Avg(X[Y==1]) - Avg(X[Y==0]) > 0. 1759 The second condition ensures that the regression slope coefficient is 1760 positive. Since your completed 3pod or Neyer Phase I did not meet both 1761 conditions, it has been suspended for your further review. Bruceton 1762 and Langlie Phase I's have been programmed to continue on until both 1763 conditions are met. 1764 1765 " 1766 cat(x) 1767 return() 1768 } 1769 1770 blrb8=function() 1771 { 1772 x= 1773 " 1774 Going from I3 to Phase II requires that a positive, finite sigma exists. 1775 Thus, M0 > m1 (for overlap) & delta = Avg(X[Y==1]) - Avg(X[Y==0]) > 0. 1776 The second condition ensures that the regression slope coefficient is 1777 positive. Since your completed 3pod or Neyer Phase I did not meet both 1778 conditions, it has been suspended for your further review. Bruceton 1779 and Langlie Phase I's have been programmed to continue on until both 1780 conditions are met. 1781 1782 " 1783 cat(x) 1784 return() 1785 1786 } 1787 1788 about4=function(x) 1789 { 1790 x1=gsub("[|]",",",x); 1791 x2=gsub("[{]","a=c(",x1); 1792 x3=gsub("[}]",")",x2); 1793 eval(parse(text=paste(x3))); 1794 return(a[4:7]); 1795 } 1796 1797 fixw=function(w,k=1) 1798 { 1799 # lop off the last k entries and resume test 1800 if(k < 1) return(w); 1801 for(i in 1:k)w=fixw1(w) 1802 return(w) 1803 } 1804 1805 fixw1=function(w) 1806 { 1807 d0=w$d0; 1808 n=nrow(d0); 1809 1810 about=w$about; 1811 en=w$en; 1812 p=w$p; 1813 n2n3=w$n2n3; 1814 #neyer=w$neyer; 1815 test=w$test 1816

Page 24:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

1817 l=about4(about); 1818 l0=length(which(l==0)); 1819 1820 if(l0 == 4) 1821 { 1822 # Case 1 1823 cas=1; d0=d0[-n,]; if(n > 0)en[1]=n-1; 1824 } 1825 1826 if(l0 == 3) 1827 { 1828 # Case 2 1829 cas=2; d0=d0[-n,]; en[1]=en[1]-1; #l[1]=0; 1830 } 1831 1832 if(l0 == 2) 1833 { 1834 if(n > l[1] & n < l[1]+l[2]) 1835 { 1836 # Case 4; 1837 cas=4; d0=d0[-n,]; #en[2]=en[2]-1; 1838 } 1839 1840 if(n == l[1]+l[2]) 1841 { 1842 # Case 5; 1843 cas=5; d0=d0[-n,]; #en[2]=en[2]-1; 1844 } 1845 1846 if(n == l[1]) 1847 { 1848 # Case 3; 1849 cas=3; en[2]=0; #l[2]=0; 1850 } 1851 } 1852 1853 if(l0 == 1) 1854 { 1855 # Case 6 1856 cas=6; en[3]=0; n2n3=0; #l[3]=0; 1857 } 1858 1859 if(l0 == 0) 1860 { 1861 if(n == l[1]+l[2]) 1862 { 1863 # Case 7 1864 cas=7; p=0; n2n3=6; #l[4]=0; 1865 } 1866 if(n > l[1]+l[2] & n <= l[1]+l[2]+l[3]) 1867 { 1868 # Case 8 1869 cas=8; d0=d0[-n,]; #en[3]=en[3]-1; 1870 } 1871 if(n > l[1]+l[2]+l[3]) 1872 { 1873 # Case 9 1874 cas=9; d0=d0[-n,]; d0=d0[-(n-1),]; #en[3]=en[3]-1; 1875 } 1876 } 1877 1878 w$d0=d0; 1879 w$en=en; 1880 w$p=p; 1881 w$n2n3=n2n3; 1882 1883 nen1=en[1]; if(en[2] == 0) nen1=0; 1884 1885 s47=c(nen1,en[2:3],p); loc=4:7; 1886 1887 if(cas > 1 | test == 2) w$about=chabout(about,s47,loc); 1888 1889 rd0=d0; rd0$X=round(rd0$X,5); names(rd0)[1]="i,X"; 1890 rd0$EX=round(rd0$EX,5); 1891 rd0$TX=round(rd0$TX,5); 1892 write.table(rd0,file="fixw.txt",quote=F,sep=",",na="i"); 1893 1894 if(en[3] == 0)w$jvec=NULL; 1895

Page 25:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

1896 return(w) 1897 } 1898 1899 pdat1=function(dat,notitle=F,ud=F) 1900 { 1901 # when resuming, names(dat) = d0, about, title, units and ln. That's it! 1902 # That's because ptest(dat,1) is called from getd0 1903 dt=dtt=dat$d0; about=dat$about; titl=dat$title; unit=dat$unit; ln=dat$ln; 1904 ttl0=dat$ttl0; ttl1=dat$ttl1; ttl2=dat$ttl2; en12=dat$en12; en=dat$en; 1905 h2=""; if(ln) h2="Log "; 1906 # pee, neyer, & test aren't defined during the test. Need to infer them. 1907 pee=dat$p; test=dat$test; 1908 x=dt$X; y=dt$Y; id=dt$ID; nid=length(id); 1909 1910 if(is.null(about)) {cat("This function only works for lists created by gonogo\n\n"); return();} 1911 1912 newid="I"; test=34; oldids=id[nid]; 1913 if(is.element(id[1],c("I1","I1(i)","I1(ii)","I1(iii)","I1(iv)"))) test=1; 1914 1915 if(id[1] == "B0") test=2; 1916 1917 if(length(pee) == 0) pee=0; 1918 fini=0; if(id[nid]=="III3") fini=1; 1919 if(fini == 1) {dtt=dtt[-nid,]; x=x[-nid]; y=y[-nid]; id=id[-nid]; nid=nid-1;} 1920 zee=x[1]; 1921 if(pee*(1-pee) > 0 & fini == 1) { yu=glmmle(dtt); zee=yu$mu+qnorm(pee)*yu$sig; } 1922 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[1],",",n[2],",",n[3],"|p,",lambda,",res}",sep1923 ="")); 1924 w=pretty(x,n=10); 1925 ens=1:nid; rd=which(y==1); gr=which(y==0); 1926 ylm=range(pretty(c(x,max(x,na.rm=T)+diff(range(x))/80),n=10)); 1927 1928 # for tick locations 1929 lb=nid-1; if(lb > 30) lb=ceiling(lb/2); 1930 1931 if(nid == 1) return(); 1932 1933 ft=T; 1934 if(nid > 1) 1935 { 1936 par(mar=c(4,4,5,2) + 0.1); 1937 lnum=2.3; 1938 if(!ln)plot(c(ens,1),c(x,zee),type="n",xlab="",ylab="",ylim=ylm,lab=c(lb,5,7)) else 1939 { 1940 par(mar=c(4,3,5,3) + 0.1); 1941 plot(c(ens,1),c(x,zee),type="n",xlab="",ylab="",ylim=ylm,yaxt="n"); 1942 w7=pretty(exp(x),n=6) 1943 axis(2,at=log(w7),lab=round(w7,1),srt=90,tcl=-.4,mgp=c(1,.5,0)); 1944 w8=pretty(x,n=6) 1945 axis(4,at=w8,lab=round(w8,1),srt=90,tcl=-.4,mgp=c(1,.5,0)); 1946 mtext("Log Scale",side=4,line=1.6); 1947 lnum=1.8; 1948 } 1949 mtext(paste("Test Level (",unit,")",sep=""),side=2,line=lnum); 1950 mtext("Trial Number",side=1,line=2.2); 1951 1952 points(ens[rd],x[rd],pch=25,cex=.7,bg=4); 1953 points(ens[gr],x[gr],pch=24,cex=.7,bg=3); 1954 1955 if(test == 1) tf=add3pod(dtt,ylm); 1956 if(test == 2) tf=addneyr(dtt,ylm); 1957 if(test > 2) 1958 { 1959 addBorL(dtt,ylm,ud); 1960 if(length(en12)==2) 1961 { 1962 abline(v=en12[1]+.5,lty=3); 1963 xd1=dt$X[1:en12[1]]; yd1=dt$Y[1:en12[1]]; 1964 i10=which(yd1==0 & xd1==max(xd1[yd1==0])); i10=i10[1]; 1965 i11=which(yd1==1 & xd1==min(xd1[yd1==1])); i11=i11[1]; 1966 xd2=dt$X[en12[1]+1:en12[2]]; yd2=dt$Y[en12[1]+1:en12[2]]; 1967 i20=which(yd2==0 & xd2==max(xd2[yd2==0])); i20=i20[1]; 1968 i21=which(yd2==1 & xd2==min(xd2[yd2==1])); i21=i21[1]; 1969 lines(c(i10,en12[1]+.5),rep(xd1[i10],2),col=3,lty=4); 1970 lines(c(i11,en12[1]+.5),rep(xd1[i11],2),col=4,lty=4); 1971 lines(c(en12[1]+i20,.5+sum(en12)),rep(xd2[i20],2),col=3,lty=4); 1972 lines(c(en12[1]+i21,.5+sum(en12)),rep(xd2[i21],2),col=4,lty=4); 1973 } 1974

Page 26:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

} 1975 if(test == 2) {if(tf[1]) about=chabout(about,nrow(dtt),4);} 1976 1977 if(!notitle) 1978 { 1979 mtext(titl,side=3,line=3.4,cex=1.2,col=1); 1980 mtext(about1,side=3,line=1.8,cex=1.2); 1981 mtext(about,side=3,line=0.5,cex=1.2); 1982 } 1983 1984 if(fini == 1) 1985 { 1986 axis(4,label=F,at=dt$RX[nid+1],tcl=.25,lwd=2); # Next EX had test cont'd (BL, Inside Box) 1987 axis(4,label=F,at=zee,tcl=-.25,lwd=2); # zee = pth quantile (BL, Outside Box) 1988 } 1989 reset(); 1990 } 1991 } 1992 1993 pdat2=function(dat,notitle=F) 1994 { 1995 dt=dtt=dat$d0; about=dat$about; titl=dat$titl; ln=dat$ln; 1996 ttl0=dat$ttl0; ttl1=dat$ttl1; ttl2=dat$ttl2; test=dat$test; 1997 tnam=c("3pod","Neyer"); 1998 if(is.null(about)) {cat("This function only works for lists created by gonogo\n\n"); return();} 1999 # pee & neyer aren't defined while running the test. Need to infer neyer. 2000 pee=dat$p; 2001 id=dt$ID; nid=length(id); 2002 if(length(pee) == 0) pee=0; 2003 fini=0; if(id[nid]=="III3") fini=1; 2004 if(fini == 1) {dtt=dtt[-nid,]; id=id[-nid]; nid=nid-1;} 2005 if(pee*(1-pee) > 0 & fini == 1) { yu=glmmle(dtt); zee=yu$mu+qnorm(pee)*yu$sig; } 2006 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[1],",",n[2],",",n[3],"|p,",lambda,",res}",sep2007 ="")); 2008 2009 kp=0; 2010 for(j in 1:nid) 2011 { 2012 jj=m.update(dtt[1:j,]); 2013 M0=jj$M0; m1=jj$m1; 2014 uv=c(M0,m1); 2015 if(!any(is.na(uv))) {if(M0 > m1) kp=j;} 2016 if(kp > 0) break; 2017 } 2018 mus=sigs=zee=zee0=rep(0,nid-kp+1); 2019 2020 if(kp == 0) cat("ptest(z,plt=2) option requires having completed Phase I2 (i.e., achieving overlap)\n"); 2021 if(kp > 0) 2022 { 2023 for(j in kp:nid) {g=glmmle(dtt[1:j,]); mus[j-kp+1]=g$mu; sigs[j-kp+1]=g$sig;} 2024 if(pee > 0 & pee < 1)zee=mus+qnorm(pee)*sigs; 2025 par(mfrow=c(2,1), mar=c(1.5,2.5,.5,.5), oma=c(2,2,3.5,2)); 2026 lmu=pretty(mus); lsig=pretty(sigs); lx=pretty(c(kp,nid)); rx=kp:nid; rxx=range(rx); 2027 if(diff(rxx)==0)rxx=rxx+c(-1,1) 2028 plot(kp:nid,mus,type="l",xlab="",ylab="",xlim=rxx,xaxt="n",ylim=range(lmu),yaxt="n"); 2029 axis(1,at=kp:nid,labels=T,tck=-.03,mgp=c(1,.4,0),cex.axis=.8); 2030 axis(2,at=lmu,labels=T,tck=-.02,mgp=c(1,.4,0),las=2,cex.axis=.8); 2031 if(ln) mtext("Mean(Log)",side=2,line=3,cex=1) else mtext("Mean",side=2,line=3,cex=1); 2032 2033 lt=3; abline(h=lmu,lty=lt); abline(v=lx,lty=lt); 2034 points(kp:nid,mus,pch=16,cex=.8); 2035 if(kp == nid) nlx=2 else nlx=nid-kp; 2036 plot(kp:nid,sigs,type="l",xlab="",ylab="",ylim=range(lsig),yaxt="n",xlim=rxx,xaxt="n"); 2037 axis(1,at=kp:nid,labels=T,tck=-.03,mgp=c(1,.4,0),cex.axis=.8); 2038 axis(2,at=lsig,labels=T,tck=-.02,mgp=c(1,.4,0),las=2,cex.axis=.8); 2039 mtext("Cumulative Test Size (n)",side=1,line=0,cex=1,outer=T); 2040 if(ln) mtext("SD(Log)",side=2,line=3,cex=1) else mtext("SD",side=2,line=3,cex=1); 2041 2042 abline(h=lsig,lty=lt); abline(v=lx,lty=lt); 2043 points(kp:nid,sigs,pch=16,cex=.8); 2044 par(mfrow=c(1,1)); 2045 els=c(2.5,1); 2046 about8=paste(ttl0,", Sequence of MLE's",sep=""); 2047 if(!notitle) 2048 { 2049 mtext(about8,side=3,line=2.8,cex=1.1); 2050 if(test > 2){ 2051 mtext(ttl1,side=3,line=1.4,cex=1.1,adj=0); 2052 mtext(ttl2,side=3,line=.3,cex=1.1,adj=0); 2053

Page 27:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

} else mtext(tnam[test],side=3,line=.3,cex=1.1,adj=0); 2054 mtext(about1,side=3,line=1.4,cex=1.1,adj=1); 2055 mtext(about,side=3,line=.3,cex=1.1,adj=1); 2056 } 2057 } 2058 reset(); 2059 if(pee == 0) return(matrix(c(mus,sigs),ncol=2)) else return(matrix(c(mus,sigs,zee),ncol=3)); 2060 } 2061 2062 pdat3=function(w,notitle=F) 2063 { 2064 dt=dtt=w$d0; about=w$about; titl=w$titl; unit=w$unit; ln=w$ln; pee=w$p; 2065 ttl0=w$ttl0; ttl1=w$ttl1; ttl2=w$ttl2; test=w$test; 2066 if(test > 4 | is.null(w$about)) {cat("This function only works for lists created by gonogo\n\n"); return();} 2067 2068 blrb5(); 2069 2070 xx="Enter conf and J: "; 2071 xx=readline(xx); cat("\n"); 2072 xx=as.numeric(unlist(strsplit(xx," "))); 2073 conf=xx[1]; J=xx[2]; 2074 2075 cf=round(conf,4); cf=as.character(cf); cf=gsub("0.",".",cf,fixed=T); 2076 pd=""; if(test == 3 | test == 4) pd=", "; 2077 pcf=substitute(paste(ttl1,pd,c[1],"=",cf,sep="")); 2078 2079 tnam=c("3pod","Neyer"); 2080 if(is.null(about)) {cat("This function only works for lists created by gonogo\n\n"); return();} 2081 id=dt$ID; nid=length(id); 2082 if(length(pee) == 0) pee=0; 2083 fini=0; if(id[nid]=="III3") fini=1; 2084 if(fini == 1) {dtt=dtt[-nid,]; id=id[-nid]; nid=nid-1;} 2085 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[1],",",n[2],",",n[3],"|p,",lambda,",res}",sep2086 ="")); 2087 2088 kp=0; 2089 for(j in 1:nid) 2090 { 2091 jj=m.update(dtt[1:j,]); 2092 M0=jj$M0; m1=jj$m1; 2093 uv=c(M0,m1); 2094 if(!any(is.na(uv))) {if(M0 > m1) kp=j;} 2095 if(kp > 0) break; 2096 } 2097 2098 kp=1; 2099 2100 if(kp > 0) 2101 { 2102 if(ln) z=qrda(dtt,conf,J,ln=T,labx=unit) else 2103 z=qrda(dtt,conf,J,labx=unit); 2104 rmzm=xlead0(z$mu,3); rmzs=xlead0(z$sig,3); 2105 about2=substitute(paste(ttl0,", (",hat(mu),",",hat(sigma),",n) = (",rmzm,",",rmzs,",",nid,")",sep="")); 2106 if(!notitle) 2107 { 2108 mtext(about2,side=3,line=2.6,cex=1.1); 2109 if(test > 2){ 2110 mtext(ttl2,side=3,line=.1,cex=1.1,adj=0); 2111 } else mtext(tnam[test],side=3,line=.3,cex=1.1,adj=0); 2112 mtext(pcf,side=3,line=1.4,cex=1.1,adj=0); 2113 mtext(about1,side=3,line=1.4,cex=1.1,adj=1); 2114 mtext(about,side=3,line=.3,cex=1.1,adj=1); 2115 } 2116 } 2117 return(z) 2118 } 2119 2120 intToBitVect = function(x) 2121 { 2122 # x is a vector of numbers 2123 nx=length(x) 2124 L=vector("list",nx) 2125 for(i in 1:nx) 2126 { 2127 xi=x[i] 2128 tmp = rev(as.numeric(intToBits(xi))) 2129 id = seq_len(match(1,tmp,length(tmp))-1) 2130 L[[i]]=tmp[-id] 2131 } 2132

Page 28:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

return(L) 2133 } 2134 2135 #INDEX 36 through 53, Xsim.R (18 functions) 2136 2137 gonogoSim=function(mlo,mhi,sg,n2=0,n3=0,p=0,lam=0,dm=0,ds=0,reso=0,ln=F,plt=0,iseed=-2138 1,IIgo=T,M=1,test=1,BL=c(4,1,0)) 2139 { 2140 dat0=data.frame(numeric(0)); 2141 dud=lev=NULL; 2142 jvec=NULL; 2143 transf=NULL; 2144 if(M <= 0) M=1; 2145 sgrem=sg=M*sg; mlo1=mlo=M*mlo; mhi1=mhi=M*mhi; dm=M*dm; ds=M*ds; 2146 en12=numeric(0); 2147 2148 if(!is.element(test,1:4)) {vv="test must be 1,2,3 or 4. Try again\n"; cat(vv); return();} 2149 if(test < 4) {if(sg <= 0) {vv="sg must be positive. Try again.\n"; cat(vv); return(); }} 2150 if(mhi < mlo) {vv="mhi-mlo must be nonnegative. Try again.\n"; cat(vv); return(); } 2151 2152 if(test < 3) 2153 { 2154 del5=(mhi-mlo)/6; 2155 epsi=del5/1000; 2156 if(sg>(mhi-mlo)/6+epsi){cat(paste("sg is too big (sg <= ",round(del5,4),")\nTry again\n\n",sep="")); 2157 return();} 2158 } 2159 2160 if(!IIgo) {n2=n3=p=lam=0}; 2161 2162 if(n3 != 0 & (p <= 0 | p >= 1 | lam <= 0)) {cat(paste("p must be between 0 & 1 and lambda > 0.\nTry 2163 again\n\n",sep="")); return();} 2164 2165 savinit=c(mlo,mhi,sg); 2166 if(ln) {v=fgs(mlo,mhi,sg); mlo=v[1]; mhi=v[2]; sg=v[3];} 2167 init=c(mlo,mhi,sg); 2168 2169 if(test > 2) 2170 { 2171 tx=paste(BL,collapse=""); 2172 if(all(BL[-1] == c(0,1)) | all(BL[-1] == c(1,1))) BL[2:3]=c(1,0); 2173 I=BL[-1]; 2174 a=prtrans(I); dud=a$dud; lev=a$lev; 2175 pm=c(1,-1); iz=which(I==0); lz=length(iz); 2176 if(lz == 1) I=I[-iz]; 2177 zp=zpfun(I); 2178 if(lz == 0)zp=c(0,1)+pm*zp; 2179 if(lz == 1){if(iz == 1) zp=1-zp;} 2180 pchar=paste(xlead0(zp,4),collapse=","); 2181 } 2182 2183 if(test == 4) {tmu=(mlo+mhi)/2+dm; tsig=(mhi-mlo)/6+ds;} 2184 if(test < 4) {tmu=(mlo+mhi)/2+dm; tsig=sg+ds;} 2185 2186 if (test == 1) 2187 { 2188 w=pI1(mlo,mhi,sg,tmu,tsig,reso,ln,iseed); 2189 d0=w[[1]]; dat0=w[[2]]; 2190 2191 w=pI2(d0,dat0,sg,tmu,tsig,reso,ln,iseed); 2192 d0=w[[1]]; dat0=w[[2]]; sg=w[[3]]; n12=0; n1=n11=nrow(d0); 2193 2194 if(IIgo) 2195 { 2196 w=pI3(d0,dat0,sg,tmu,tsig,reso,ln,iseed); 2197 d0=w[[1]]; dat0=w[[2]]; n1=nrow(d0); n12=n1-n11; 2198 2199 if(n2 < 0) n2=max(-(n2+n11+n12),0); 2200 if(n2 > 0) {w=pII(d0,dat0,tmu,tsig,n2,reso,ln,iseed); d0=w[[1]]; dat0=w[[2]];} 2201 if(n3 < 0) n3=max(-(n3+n2+n11+n12),0); 2202 if(n3 > 0 & p*(1-p) > 0 & lam >= 0) {w=spIIIsim(d0,dat0,tmu,tsig,n3,p,lam,reso,ln,iseed); d0=w[[1]]; 2203 dat0=w[[2]]; jvec=w[[3]];} 2204 } 2205 } 2206 2207 if(test == 2) 2208 { 2209 w=npI(mlo,mhi,sg,tmu,tsig,reso,ln,iseed); 2210 d0=w[[1]]; dat0=w[[2]]; n1=n11=nrow(d0); n12=0; 2211

Page 29:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

2212 if(IIgo) 2213 { 2214 if(n2 < 0) n2=max(-(n2+n11+n12),0); 2215 if(n2 > 0) {w=pII(d0,dat0,tmu,tsig,n2,reso,ln,iseed); d0=w[[1]]; dat0=w[[2]];} 2216 if(n3 < 0) n3=max(-(n3+n2+n11+n12),0); 2217 if(n3 > 0 & p*(1-p) > 0 & lam >= 0) {w=spIIIsim(d0,dat0,tmu,tsig,n3,p,lam,reso,ln,iseed); d0=w[[1]]; 2218 dat0=w[[2]]; jvec=w[[3]];} 2219 } 2220 } 2221 2222 if(test > 2) 2223 { 2224 if(test == 3) w=bpI(mlo,mhi,sg,tmu,tsig,reso,ln,iseed,BL) else 2225 w=lpI(mlo,mhi,sg,tmu,tsig,reso,ln,iseed,BL) 2226 d0=w[[1]]; dat0=w[[2]]; n1=n11=nrow(d0); n12=0; 2227 en12=w[[3]]; n11=en12[1]; if(length(en12) > 1) n12=en12[2]; 2228 2229 if(IIgo) 2230 { 2231 if(n2 < 0) n2=max(-(n2+n11+n12),0); 2232 if(n2 > 0) {w=pII(d0,dat0,tmu,tsig,n2,reso,ln,iseed); d0=w[[1]]; dat0=w[[2]];} 2233 if(n3 < 0) n3=max(-(n3+n2+n11+n12),0); 2234 if(n3 > 0 & p*(1-p) > 0 & lam >= 0) {w=spIIIsim(d0,dat0,tmu,tsig,n3,p,lam,reso,ln,iseed); d0=w[[1]]; 2235 dat0=w[[2]]; jvec=w[[3]];} 2236 } 2237 } 2238 2239 en=c(n11,n12,n2,n3); 2240 v=glmmle(d0); 2241 2242 abo=wabout13(M,mlo1,mhi1,sgrem,p,n11,n12,n2,n3,lam,reso); 2243 2244 h1=""; if(ln) h1="Log "; 2245 2246 titl=NULL; 2247 2248 rmzm=gsub("0.",".",as.character(round(tmu,3)),fixed=T); 2249 rmzs=gsub("0.",".",as.character(round(tsig,3)),fixed=T); 2250 if(iseed < 0) 2251 {ttl0=substitute(paste("(",mu[t],", ",sigma[t],") = (",rmzm,", ",rmzs,"), ", 2252 delta[t]," = (",dm,", ",ds,")",sep=""));} else 2253 {ttl0=substitute(paste("(",mu[t],", ",sigma[t],") = (",rmzm,", ",rmzs,"), ", 2254 delta[t]," = (",dm,", ",ds,"), ",i[s]," = ",iseed,sep=""));} 2255 2256 ttl1=ttl2=NULL; 2257 if(ln) h2="Log " else h2=""; 2258 if(test == 1) ttl2=paste(h2,"3pod",sep=""); 2259 if(test == 2) ttl2=paste(h2,"Neyer",sep=""); 2260 if(test == 3 | test == 4) 2261 { 2262 if(test == 3) ttl1=substitute(paste(h2,Bruc[tx],sep="")); 2263 if(test == 4) ttl1=substitute(paste(h2,Lang[tx],sep="")); 2264 ttl2=substitute(paste(h2,L[pchar],sep="")); 2265 } 2266 2267 if(M==1)uni="X" else uni=paste(M,"X",sep=""); 2268 ret=list(d0,jvec,tmu,tsig,v$mu,v$sig,en,abo,titl,ttl1,ttl2,ttl0,uni,p,reso,ln,lam,test,M,dm,ds,iseed,BL2269 ,dud,lev); 2270 names(ret)=c("d0","jvec","tmu","tsig","mhat","shat","en","about","title","ttl1","ttl2","ttl0","units","2271 p","reso", 2272 "ln","lam","test","M","dm","ds","iseed","BL","dud","lev") 2273 if(is.element(plt,c(1,2,3))) ptest(ret,plt); 2274 2275 return(ret); 2276 } 2277 2278 pI1=function(mlo,mhi,sg,tmu,tsig,reso,ln,iseed,dat0=data.frame(numeric(0))) 2279 { 2280 nret=c("d0","dat0"); 2281 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 2282 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 2283 d0=d1[-1,]; names(d0)=names(d1)=cnam; 2284 d0$ID=as.character(d0$ID); 2285 if(is.null(dat0)) dat0=d0; 2286 del=(mhi-mlo)/6; 2287 epsi=del/1000; 2288 mi=c(mlo,mhi); 2289 a=matrix(c(.75,.25,.25,.75),ncol=2,byrow=T); 2290

Page 30:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

xx=t(a%*%mi); 2291 2292 for(i in 1:2) {u=gd0(xx[i],d0,dat0,"I1",tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; } 2293 2294 i1=0; 2295 2296 x=d0$X; y=d0$Y; 2297 if(all(y==c(0,0))) 2298 { 2299 xx=mi[2]; 2300 while(1) 2301 { 2302 i1=i1+1; 2303 if(i1%%3 == 0) sg=2*sg; 2304 xx=xx+1.5*i1*sg; 2305 u=gd0(xx,d0,dat0,"I1(i)",tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2306 if(d0$Y[nrow(d0)] == 1) break; 2307 } 2308 } 2309 2310 if(all(y==c(1,1))) 2311 { 2312 xx=mi[1]; 2313 while(1) 2314 { 2315 i1=i1+1; 2316 if(i1%%3 == 0) sg=2*sg; 2317 xx=xx-1.5*i1*sg; 2318 u=gd0(xx,d0,dat0,"I1(ii)",tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2319 if(d0$Y[nrow(d0)] == 0) break; 2320 } 2321 } 2322 2323 if(all(y==c(0,1))) d0$ID=rep("I1(iii)",length(y)); 2324 2325 if(all(y==c(1,0))) 2326 { 2327 xx=c(mlo-3*sg,mhi+3*sg); 2328 for(i in 1:2) 2329 { 2330 u=gd0(xx[i],d0,dat0,"I1(iv)",tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2331 } 2332 } 2333 ret=list(d0,dat0); 2334 names(ret)=nret; 2335 return(ret); 2336 } 2337 2338 pI2=function(d0,dat0,sg,tmu,tsig,reso,ln,iseed) 2339 { 2340 nret=c("d0","dat0","sg"); 2341 idii=""; 2342 while(1) 2343 { 2344 # del = m1-M0; del < 0 ==> OVERLAP 2345 j=m.update(d0); m1=j$m1; M0=j$M0; del=m1-M0; 2346 while(del >= 1.5*sg) 2347 { 2348 xx=(M0+m1)/2; 2349 id=paste(idii,"I2(ib)",sep=""); 2350 u=gd0(xx,d0,dat0,id,tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2351 j=m.update(d0); m1=j$m1; M0=j$M0; del=m1-M0; 2352 } 2353 if(del < 0) {ret=list(d0,dat0,sg); names=nret; return(ret);} 2354 j=n.update(d0); n0=j$n0; n1=j$n1; 2355 if(del >= 0) 2356 { 2357 if(n0 > n1) 2358 { 2359 xx=m1+0.3*sg; 2360 id=paste(idii,"I2(ic)",sep=""); 2361 u=gd0(xx,d0,dat0,id,tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2362 if(d0$Y[nrow(d0)] == 0) {ret=list(d0,dat0,sg); names=nret; return(ret);} 2363 if(d0$Y[nrow(d0)] == 1) 2364 { 2365 xx=M0-.3*sg; 2366 id=paste(idii,"I2(ic)",sep=""); 2367 u=gd0(xx,d0,dat0,id,tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2368 if(d0$Y[nrow(d0)] == 1) {ret=list(d0,dat0,sg); names=nret; return(ret);} 2369

Page 31:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(d0$Y[nrow(d0)] == 0) 2370 { 2371 sg=2*sg/3; 2372 idii=paste(idii,"r",sep=""); 2373 } 2374 } 2375 } 2376 if(n0 <= n1) 2377 { 2378 xx=M0-.3*sg; 2379 id=paste(idii,"I2(id)",sep=""); 2380 u=gd0(xx,d0,dat0,id,tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2381 if(d0$Y[nrow(d0)] == 1) {ret=list(d0,dat0,sg); names=nret; return(ret);} 2382 if(d0$Y[nrow(d0)] == 0) 2383 { 2384 xx=m1+.3*sg; 2385 id=paste(idii,"I2(id)",sep=""); 2386 u=gd0(xx,d0,dat0,id,tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2387 if(d0$Y[nrow(d0)] == 0) {ret=list(d0,dat0,sg); names=nret; return(ret);} 2388 if(d0$Y[nrow(d0)] == 1) 2389 { 2390 sg=2*sg/3; 2391 idii=paste(idii,"r",sep=""); 2392 } 2393 } 2394 } 2395 } 2396 } 2397 ret=list(d0,dat0,sg); names(ret)=nret; return(ret); 2398 } 2399 2400 pI3=function(d0,dat0,sg,tmu,tsig,reso,ln,iseed) 2401 { 2402 j=m.update(d0); M0=j$M0; m1=j$m1; del=m1-M0; 2403 xx=(M0+m1)/2; 2404 if(sg+del > 0)xx=xx+c(1,-1)*sg/2; 2405 lxx=length(xx) 2406 for(i in 1:lxx) 2407 { 2408 if(i < lxx) u=gd0(xx[i],d0,dat0,"I3",tmu,tsig,reso,ln,iseed); 2409 if(i == lxx) u=gd0(xx[i],d0,dat0,"I3",tmu,tsig,reso,ln,iseed); 2410 d0=u$d0; dat0=u$dat0; 2411 } 2412 ret=list(d0,dat0); 2413 names(ret)=c("d0","dat0"); 2414 return(ret); 2415 } 2416 2417 npI=function(mlo,mhi,sg,tmu,tsig,reso,ln,iseed,dat0=data.frame(numeric(0))) 2418 { 2419 nret=c("d0","dat0"); 2420 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 2421 d1=data.frame(t(rep(0,6))); d1=cbind(d1,"END"); 2422 d0=d1[-1,]; names(d0)=names(d1)=cnam; 2423 d0$ID=as.character(d0$ID); 2424 if(is.null(dat0)) dat0=d0; 2425 2426 del=(mhi-mlo)/6; 2427 epsi=del/1000; 2428 2429 eps=1e-007 2430 n=0; 2431 2432 bl=c("B0","B1","B2","B3","B4"); 2433 2434 # lf: a flag to adjust X1 & X2 in the ln=T neyer case 2435 # which deviates a tad from a true neyer on the logs 2436 # but allows X1 & X2 to stay the same in both ln modes 2437 2438 lf=0; 2439 2440 while(1) 2441 { 2442 # PART 1 ************************************************************ 2443 if(n == 0) block=0 else 2444 { 2445 j=n.update(d0); k0=j$n0; k1=j$n1; 2446 xlo=min(d0$X) 2447 xhi=max(d0$X) 2448

Page 32:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(k1 <= eps) block=1 else 2449 { 2450 if(k1 >= n-eps) block=2 else 2451 { 2452 # PART 2 ************************************************** 2453 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 2454 dif = round(m1-M0,14) 2455 if(dif > sg) block=3 else 2456 { 2457 if(dif >= 0) block=4 else block=5; 2458 } 2459 } 2460 } 2461 } 2462 2463 # First 2464 if(block == 0) if(!ln)xbef = (mlo+mhi)/2 else {v=ifg(mlo,mhi); xbef=log((v[1]+v[2])/2); lf=1;} 2465 # All 0's 2466 if(block == 1) if(lf == 0) xbef = max(c((mhi + xhi)/2, xhi + 2 * sg, 2 * xhi - xlo)) else 2467 {xbef=log((v[1]+3*v[2])/4); lf=0;} 2468 # All 1's 2469 if(block == 2) if(lf == 0) xbef = min(c((mlo + xlo)/2, xlo - 2 * sg, 2 * xlo - xhi)) else 2470 {xbef=log((3*v[1]+v[2])/4); lf=0;} 2471 2472 if(block == 3) xbef = (m1 + M0)/2 2473 if(block == 4) 2474 { 2475 m=(m1+M0)/2; es=sg; sg=.8*sg; 2476 m = max(xlo, min(m, xhi)) 2477 es = min(es,(xhi-xlo)) 2478 b = yinfomat(d0,m,es)$infm 2479 xbef = m + kstar(b)*es 2480 } 2481 if(block == 5) break; 2482 u=gd0(xbef,d0,dat0,bl[block+1],tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2483 n=nrow(d0); 2484 } 2485 ret=list(d0,dat0); 2486 names(ret)=nret; 2487 return(ret); 2488 } 2489 2490 bpI=function(mlo,mhi,sg,tmu,tsig,reso,ln,iseed,BL,dat0=data.frame(numeric(0))) 2491 { 2492 nRev=BL[1]; I=BL[2:3]; I[I == 0] =-1; 2493 X=c(1,0); 2494 nSeq=1+(I-I%%2)/2; 2495 wz=which(I == -1); 2496 if(length(wz) == 1) {X=X[-wz]; I=I[-wz]; nSeq=nSeq[-wz];} 2497 lox=length(X); 2498 udid=numeric(0); 2499 2500 nret=c("d0","dat0","en12"); 2501 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 2502 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 2503 d0=d1[-1,]; names(d0)=names(d1)=cnam; 2504 d0$ID=as.character(d0$ID); 2505 if(is.null(dat0)) dat0=d0; 2506 2507 en12=0; 2508 2509 for(ijk in 1:lox) 2510 { 2511 if(X[ijk] == 0)GE5=F else GE5=T; 2512 2513 # L=intToBitVect(nL), L is a List, nl is a vector of integers 2514 # D's are the first 1:nSeq, U's are the last 1 or 2 depending on nAdd being 0 or 1, resp. 2515 2516 L=udli(I[ijk]); 2517 nL=bintodec(L); 2518 2519 pl=zpfun(I[ijk]); 2520 if(!GE5)pl=1-pl; 2521 xx=mlo; 2522 2523 # initialize counter and accumulator 2524 icnt=iacc=0; 2525 dn=0; ud=xud=numeric(0); yseq=numeric(0); 2526 2527

Page 33:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

while(dn == 0) 2528 { 2529 u=gd0(xx,d0,dat0,"IB",tmu,tsig,reso,ln,iseed) 2530 2531 d0=u$d0; dat0=u$dat0; 2532 icnt=icnt+1; nx=length(d0$X); iacc=iacc+d0$X[[nx]]; 2533 y=d0$Y; 2534 ny=length(y); 2535 2536 if(GE5) {yseq=c(yseq,y[ny]); udid=c(udid,y[ny]);} else 2537 {yseq=c(yseq,1-y[ny]); udid=c(udid,1-y[ny]);} 2538 2539 lseq=list(yseq); ns=bintodec(lseq); 2540 2541 iw=which(nL == ns); 2542 2543 # Also will want to know if overlap has been achieved 2544 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 2545 dif = round(m1-M0,14); 2546 if(!is.na(dif) & dif < 0 & nRev < 0) dn=1; 2547 2548 if(length(iw) == 1 & dn == 0) 2549 { 2550 xx=iacc/icnt; 2551 xud=c(xud,xx); 2552 nxud=length(xud); 2553 kay=floor((xx-mlo)/sg); 2554 pstar=(xx-mlo)/sg-floor((xx-mlo)/sg); 2555 g=mlo+kay*sg; 2556 2557 if(GE5) 2558 { 2559 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=-2; if(pstar <= .5) xx=g-sg else xx=g;} 2560 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=2; if(pstar <= .5) xx=g+sg else xx=g+2*sg;} 2561 } else 2562 { 2563 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=2; if(pstar <= .5) xx=g+sg else xx=g+2*sg;} 2564 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=-2; if(pstar <= .5) xx=g-sg else xx=g;} 2565 } 2566 icnt=iacc=0; 2567 2568 yseq=numeric(0); 2569 cud=sum(abs(diff(ud))); 2570 if(!is.na(dif) & nRev > 0) if(cud >= nRev & dif < 0) dn=1; 2571 if(!is.na(dif) & nRev == 0) if(dif < 0) dn=1; 2572 2573 # At this point, if dn = 1, the the reversal and overlap criteria are met 2574 # Reset dn = 0 if Avg(X[Y==1]) <= Avg(X[Y==0]), i.e., if d.update(d0) < 1 2575 if(d.update(d0) < 1) dn=0; 2576 } 2577 } 2578 en12=c(en12,nx); 2579 } 2580 en12=diff(en12); 2581 udid[abs(udid) != 2]=0; 2582 udid[udid==-2]="D"; udid[udid==2]="U"; udid[udid == 0]=""; 2583 d0$ID=udid; 2584 ret=list(d0,dat0,en12); 2585 names(ret)=nret; 2586 return(ret); 2587 } 2588 2589 lpI=function(mlo,mhi,sg,tmu,tsig,reso,ln,iseed,BL,dat0=data.frame(numeric(0))) 2590 { 2591 nRev=BL[1]; I=BL[2:3]; I[I == 0] =-1; 2592 X=c(1,0); 2593 nSeq=1+(I-I%%2)/2; 2594 wz=which(I == -1); 2595 if(length(wz) == 1) {X=X[-wz]; I=I[-wz]; nSeq=nSeq[-wz];} 2596 lox=length(X); 2597 udid=numeric(0); 2598 2599 nret=c("d0","dat0","en12"); 2600 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 2601 d1=data.frame(t(rep(0,6)));d1=cbind(d1,"END"); 2602 d0=d1[-1,]; names(d0)=names(d1)=cnam; 2603 d0$ID=as.character(d0$ID); 2604 if(is.null(dat0)) dat0=d0; 2605 2606

Page 34:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

en12=0; 2607 2608 for(ijk in 1:lox) 2609 { 2610 if(X[ijk] == 0)GE5=F else GE5=T; 2611 2612 # L=intToBitVect(nL), L is a List, nl is a vector of integers 2613 # D's are the first 1:nSeq, U's are the last 1 or 2 depending on nAdd being 0 or 1, resp. 2614 2615 L=udli(I[ijk]); 2616 nL=bintodec(L); 2617 2618 pl=zpfun(I[ijk]); 2619 if(!GE5)pl=1-pl; 2620 xx=mlo*(1-pl)+mhi*pl; 2621 2622 # initialize counter and accumulator 2623 icnt=iacc=0; 2624 dn=0; ud=xud=numeric(0); yseq=numeric(0); 2625 2626 while(dn == 0) 2627 { 2628 u=gd0(xx,d0,dat0,"IB",tmu,tsig,reso,ln,iseed) 2629 d0=u$d0; dat0=u$dat0; 2630 icnt=icnt+1; nx=length(d0$X); iacc=iacc+d0$X[[nx]]; 2631 2632 y=d0$Y; 2633 ny=length(y); 2634 2635 if(GE5) {yseq=c(yseq,y[ny]); udid=c(udid,y[ny]);} else 2636 {yseq=c(yseq,1-y[ny]); udid=c(udid,1-y[ny]);} 2637 2638 lseq=list(yseq); ns=bintodec(lseq); 2639 2640 iw=which(nL == ns); 2641 2642 # Also will want to know if overlap has been achieved 2643 j=m.update(d0); m1=j$m1; M0=j$M0; dif=m1-M0; 2644 dif = round(m1-M0,14); 2645 if(!is.na(dif) & dif < 0 & nRev < 0) dn=1; 2646 2647 if(length(iw) == 1 & dn == 0) 2648 { 2649 if(GE5) 2650 { 2651 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=-2;} 2652 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=2;} 2653 } else 2654 { 2655 if(iw > nSeq[ijk]) {ud=c(ud,1); udid[ny]=2;} 2656 if(iw <= nSeq[ijk]) {ud=c(ud,0); udid[ny]=-2;} 2657 } 2658 2659 xud=c(xud,iacc/icnt); 2660 nxud=length(xud); 2661 rud=2*rev(ud)-1; 2662 uc=cumsum(rud); 2663 ic=which(uc == 0); 2664 # Calculate xxa, xx, reset counters 2665 if(length(ic) == 0) 2666 { 2667 if(GE5) 2668 { 2669 if(iw > nSeq[ijk]) xxa=mlo; 2670 if(iw <= nSeq[ijk]) xxa=mhi; 2671 } else 2672 { 2673 if(iw > nSeq[ijk]) xxa=mhi; 2674 if(iw <= nSeq[ijk]) xxa=mlo; 2675 } 2676 } 2677 if(length(ic) > 0) {ic=ic[1]; xxa=rev(xud); xxa=xxa[ic];} 2678 xx=(xud[nxud]+xxa)/2; 2679 2680 icnt=iacc=0; 2681 yseq=numeric(0); 2682 cud=sum(abs(diff(ud))); 2683 if(!is.na(dif) & nRev > 0) if(cud >= nRev & dif < 0) dn=1; 2684 if(!is.na(dif) & nRev == 0) if(dif < 0) dn=1; 2685

Page 35:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

# At this point, if dn = 1, the the reversal and overlap criteria are met 2686 # Reset dn = 0 if Avg(X[Y==1]) <= Avg(X[Y==0]), i.e., if d.update(d0) < 1 2687 if(d.update(d0) < 1) dn=0; 2688 } 2689 } 2690 en12=c(en12,nx); 2691 } 2692 en12=diff(en12); 2693 udid[abs(udid) != 2]=0; 2694 udid[udid==-2]="D"; udid[udid==2]="U"; udid[udid == 0]=""; 2695 d0$ID=udid; 2696 2697 ret=list(d0,dat0,en12); 2698 names(ret)=nret; 2699 return(ret); 2700 } 2701 2702 pII=function(d0,dat0,tmu,tsig,n2,reso,ln,iseed) 2703 { 2704 # Wu/Tian definition of n2 would be n2 = n2-nrow(d0); 2705 xl=xu=xstar=mu2=mu4=sg2=sg4=rep(0,n2); 2706 for(i in 1:n2) 2707 { 2708 nq=glmmle(d0); 2709 mu2[i]=nq$mu; 2710 sg2[i]=nq$sig; 2711 xl[i]=min(d0$X); xu[i]=max(d0$X); 2712 mu4[i]=max(xl[i],min(mu2[i],xu[i])); 2713 sg4[i]=min(sg2[i],xu[i]-xl[i]); 2714 b=yinfomat(d0,mu4[i],sg4[i])$infm; 2715 xstar[i]=mu4[i]+kstar(b)*sg4[i]; 2716 id="II1"; 2717 if(i > 1) id="II2"; 2718 u=gd0(xstar[i],d0,dat0,"II",tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2719 } 2720 ret=list(d0,dat0); 2721 names(ret)=c("d0","dat0"); 2722 return(ret); 2723 } 2724 2725 spIIIsim=function(d0,dat0,tmu,tsig,n3,p,lam,reso,ln,iseed) 2726 { 2727 jvec=matrix(rep(0,10*(n3+1)),ncol=10); 2728 nq=glmmle(d0); 2729 mu=nq$mu; sig=nq$sig; 2730 2731 # Calculate initial tau1^2 2732 # this variance/covariance matrix (vcov1) is scale free 2733 ww=yinfomat(d0,mu,sig); 2734 tau2=sum(t(c(1,qnorm(p)^2))*diag(ww$vcov1)); 2735 2736 # Truncate tau2[1] 2737 ti=round((c(3,5)/qnorm(.975))^2,4)*sig^2; 2738 2739 #** NEW 2740 if(ln) ti=round((c(3,5)/qlnorm(.975))^2,4)*sig^2; 2741 2742 tau2=min(max(tau2[1],ti[1]),ti[2]); 2743 2744 # Use Mu Tilda and Sigma Tilda instead of Mu Hat and Sigma Hat 2745 m1=min(d0$X,na.rm=T); 2746 m2=max(d0$X,na.rm=T); 2747 m2=min(c(mu,m2),na.rm=T); 2748 mut=max(c(m1,m2),na.rm=T); 2749 sigt=min(sig,diff(range(d0$X)),na.rm=T); 2750 2751 # Beta = 1/(2* SigmaTilda) per pp 9. You get beta = 0.4302985 2752 be=1/(2*sigt); 2753 2754 #** NEW 2755 if(ln) be=plnorm(qlnorm(p))/(pnorm(qnorm(p))*sigt) 2756 2757 c1=f3point8(lam); 2758 nu=sqrt(tau2)*c1; 2759 2760 xx=mut+qnorm(p)*sigt+nu; 2761 u=gd0(xx,d0,dat0,"III1",tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2762 ny=length(d0$Y); yy=d0$Y[ny]; 2763 jvec[1,]=c(0,0,0,0,0,tau2,nu,0,xx,yy); 2764

Page 36:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

for(i in 1:n3) 2765 { 2766 # Compute next X|d0 2767 vv=skewL(c1,nu,tau2,p,be); 2768 a=vv[5]; tau2=vv[6]; nu=vv[7]; b=vv[8]; 2769 xx=d0$X[nrow(d0)]-a*(d0$Y[nrow(d0)]-b); 2770 2771 if(i < n3) 2772 { 2773 u=gd0(xx,d0,dat0,"III2",tmu,tsig,reso,ln,iseed); d0=u$d0; dat0=u$dat0; 2774 ny=length(d0$Y); 2775 yy=d0$Y[ny] 2776 jvec[i+1,]=c(vv,xx,yy); 2777 } 2778 if(i == n3) 2779 { 2780 d0=rbind(d0,d0[nrow(d0),]); 2781 d0[nrow(d0),1:6]=c(0,0,0,round(xx,5),0,0); 2782 d0$ID[nrow(d0)]="III3"; 2783 jvec[i+1,]=c(vv,xx,NA); 2784 } 2785 } 2786 jvec=data.frame(jvec); 2787 names(jvec)=c("j","k","v","u","a","tau2","nu","b","x","y"); 2788 ret=list(d0,dat0,jvec); 2789 names(ret)=c("d0","dat0","jvec"); 2790 return(ret); 2791 } 2792 2793 gd0=function(xx,d0,dat0,ID,mu,sig,reso,ln,iseed=-1) 2794 { 2795 nret=c("d0","dat0"); 2796 cnam=c("X","Y","COUNT","RX","EX","TX","ID"); 2797 d1=data.frame(t(rep(0,6))); d1=cbind(d1,"END"); 2798 names(d1)=names(d0)=cnam; 2799 d0$ID=as.character(d0$ID); 2800 if(is.null(dat0)) dat0=d1[-1,]; 2801 n0=nrow(dat0); nd0=nrow(d0)+1; 2802 iset=0; if(iseed >= 0)iset=nd0+iseed; 2803 if(n0 == 0) 2804 { 2805 u=gxr(xx,mu,sig,reso,ln,iset); 2806 d1[1,1:6]=c(u[1:2],1,u[3],xx,u[4]); d1$ID=ID; 2807 } 2808 if(n0 > 0) {d1=dat0[1,]; dat0=dat0[-1,]; if(is.null(dat0)) dat0=d1[-1,]; n0=nrow(dat0);} 2809 d0=rbind(d0,d1); 2810 ret=list(d0,dat0); 2811 names(ret)=nret; 2812 return(ret); 2813 } 2814 2815 gxr=function(x,mu,sig,reso,ln,iset) 2816 { 2817 if(iset > 0) set.seed(iset); 2818 xsav=x; 2819 if(ln) x=exp(x); 2820 rx=round(x,6); if(reso > 0)rx=round(x/reso)*reso; 2821 # rx=the stress; Choose a random strength (stren, that is NOT on log scale) 2822 if(ln) stren=rlnorm(1, meanlog = mu, sdlog = sig) else stren=mu+rnorm(1)*sig; 2823 # If stren is bigger than rx (stress) then r=0; 2824 r=0; if(stren <= rx) r=1; 2825 x=tx=round(rx,5); 2826 if(ln) x=round(log(tx),5) 2827 return(c(x,r,rx,tx)); 2828 } 2829 2830 ntau = function(dat,response=1) 2831 { 2832 # NOTE: ntau(dat,response=0) == -ntau(dat,response=1) 2833 # Whatever the response(i.e., 0 or 1) with Pr[response increases as stress increases] 2834 # then a positive ntau(dat) <---> to a proper non-decreasing CDF response model 2835 # a negative ntau <---> to a flat response model <---> Mu=-Inf, Sig=Inf, pnorm((X-Mu)/Sig)=C 2836 # where C=#responses/#tested = r/n, say. then (X-MU)/Sig=qnorm(r/n) for all X ==> Sig=K, Mu=X-K 2837 # For K = Inf (i.e., K very large). 2838 2839 if(response==0) dat$Y=1-dat$Y; 2840 st=dat$X; 2841 i1=which(dat$Y==1); 2842 i0=which(dat$Y==0); 2843

Page 37:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

r1=r0=n=dat$COUNT; 2844 r1[i0]=0; 2845 r0[i1]=0; 2846 nt=sum(n); n1=sum(r1); 2847 tau1=sum((r1/n-n1/nt)*(n*st)) 2848 tau2=sum(r1*st)-n1*sum(n*st)/nt 2849 tau3=sum(r1*st)-n1*mean(st,weights=n) 2850 tau4=n1*(mean(st,weights=r1)-mean(st,weights=n)) 2851 return(tau4) 2852 } 2853 2854 wabout13=function(M,cmlo,cmhi,csg,p,n11,n12,n2,n3,lam,reso) 2855 { 2856 g=", "; f=","; 2857 cp=as.character(p); cp=gsub("0.",".",cp,fixed=T); 2858 cl=as.character(lam); cl=gsub("0.",".",cl,fixed=T); 2859 cr=as.character(reso); cr=gsub("0.",".",cr,fixed=T); 2860 cmlo=as.character(cmlo); cmlo=gsub("0.",".",cmlo,fixed=T); 2861 cmhi=as.character(cmhi); cmhi=gsub("0.",".",cmhi,fixed=T); 2862 csg=as.character(csg); csg=gsub("0.",".",csg,fixed=T); 2863 if(M == 1) 2864 { 2865 if(n3 == 0) about=paste("{",cmlo,f,cmhi,f,csg,"|",n11,f,n12,f,n2,f,n3,"|","-",f,"-",f,cr,"}",sep="") else 2866 about=paste("{",cmlo,f,cmhi,f,csg,"|",n11,f,n12,f,n2,f,n3,"|",cp,f,cl,f,cr,"}",sep="") 2867 } else 2868 { 2869 if(n3 == 0) about=paste("{",cmlo,f,cmhi,f,csg,"|",n11,f,n12,f,n2,f,n3,"|","-",f,"-",f,cr,f,M,"}",sep="") else 2870 about=paste("{",cmlo,f,cmhi,f,csg,"|",n11,f,n12,f,n2,f,n3,"|",cp,f,cl,f,cr,f,M,"}",sep="") 2871 } 2872 return(about) 2873 } 2874 2875 pSdat1=function(dat,notitle=F,ud=F) 2876 { 2877 dt=dtt=dat$d0; about=dat$about; titl=dat$titl; unit=dat$unit; pee=dat$p; 2878 ln=dat$ln; test=dat$test; tmu=dat$tmu; tsig=dat$tsig; lev=dat$lev; 2879 ttl1=dat$ttl1; ttl2=dat$ttl2; ttl0=dat$ttl0; 2880 res=dat$reso; 2881 M=dat$M; dm=dat$dm; ds=dat$ds; iseed=dat$iseed; en=dat$en; 2882 en12=en[1:2]; 2883 2884 if(length(pee) == 0) pee=0; 2885 x=dt$X; y=dt$Y; id=dt$ID; nid=length(id); 2886 2887 fini=0; if(id[nid]=="III3") fini=1; 2888 if(fini == 1) {dtt=dtt[-nid,]; x=x[-nid]; y=y[-nid]; id=id[-nid]; nid=nid-1;} 2889 zee=tzee=x[1]; 2890 if(pee*(1-pee) > 0 & fini == 1) 2891 { 2892 yu=glmmle(dtt); zee=yu$mu+qnorm(pee)*yu$sig; 2893 tzee=dat$tmu+qnorm(pee)*dat$tsig; 2894 } 2895 2896 # orig units were (mlo,mhi,sg). new units are (mlo,mhi,sg)*M. 2897 # To get X's, zee and tzee back into original units divide them by M 2898 # x=x/M; zee=zee/M; tzee=tzee/M; 2899 2900 if(M == 1) 2901 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[11],",",n[12],",",n[2],",",n[3],"|p,",lambda,2902 ",res}",sep="")) else 2903 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[11],",",n[12],",",n[2],",",n[3],"|p,",lambda,2904 ",res,M}",sep="")); 2905 2906 ens=1:nid; rd=which(y==1); gr=which(y==0); 2907 xtz=c(x,tzee,zee); 2908 ylm=range(pretty(c(xtz,max(xtz,na.rm=T)+diff(range(xtz))/80),n=10)); 2909 2910 # for tick locations 2911 lb=nid-1; if(lb > 30) lb=ceiling(lb/2); 2912 2913 if(nid == 1) return(); 2914 2915 if(nid > 1) 2916 { 2917 par(mar=c(4,4,5,2) + 0.1); 2918 lnum=2.3; 2919 if(!ln)plot(c(ens,1),c(x,zee),type="n",xlab="",ylab="",ylim=ylm,lab=c(lb,5,7)) else 2920 { 2921 par(mar=c(4,3,5,3) + 0.1); 2922

Page 38:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

plot(c(ens,1),c(x,zee),type="n",xlab="",ylab="",ylim=ylm,yaxt="n"); 2923 w7=pretty(exp(x),n=6) 2924 axis(2,at=log(w7),lab=round(w7,1),srt=90,tcl=-.4,mgp=c(1,.5,0)); 2925 w8=pretty(x,n=6) 2926 axis(4,at=w8,lab=round(w8,1),srt=90,tcl=-.4,mgp=c(1,.5,0)); 2927 mtext("Log Scale",side=4,line=1.6); 2928 lnum=1.8; 2929 } 2930 mtext(paste("Test Level (",unit,")",sep=""),side=2,line=lnum); 2931 mtext("Trial Number",side=1,line=2.2); 2932 points(ens[rd],x[rd],pch=25,cex=.7,bg=4); 2933 points(ens[gr],x[gr],pch=24,cex=.7,bg=3); 2934 2935 if(test == 1) g7=add3pod(dtt,ylm,sim=T); 2936 if(test == 2) g7=addneyr(dtt,ylm,sim=T); 2937 if(test > 2) g7=addBorL(dtt,ylm,ud); 2938 if(test < 3) kp=g7[2]; 2939 if(test > 2) 2940 { 2941 text((en[1]+en[2])/2+.5,ylm[2],"I",cex=.9); 2942 if(en[3] > 0 & en[2] == 0) text(en[1]+en[3]/2+.5,ylm[2],"II",cex=.9); 2943 if(en[4] > 0 & en[2] == 0) text(en[1]+en[3]+en[4]/2+.5,ylm[2],"III",cex=.9); 2944 } 2945 2946 if(test > 2) 2947 { 2948 if(length(en12)==2) 2949 { 2950 abline(v=en12[1]+.5,lty=3); 2951 xd1=dt$X[1:en12[1]]; yd1=dt$Y[1:en12[1]]; 2952 i10=which(yd1==0 & xd1==max(xd1[yd1==0])); i10=i10[1]; 2953 i11=which(yd1==1 & xd1==min(xd1[yd1==1])); i11=i11[1]; 2954 xd2=dt$X[en12[1]+1:en12[2]]; yd2=dt$Y[en12[1]+1:en12[2]]; 2955 i20=which(yd2==0 & xd2==max(xd2[yd2==0])); i20=i20[1]; 2956 i21=which(yd2==1 & xd2==min(xd2[yd2==1])); i21=i21[1]; 2957 lines(c(i10,en12[1]+.5),rep(xd1[i10],2),col=3,lty=4); 2958 lines(c(i11,en12[1]+.5),rep(xd1[i11],2),col=4,lty=4); 2959 lines(c(en12[1]+i20,.5+sum(en12)),rep(xd2[i20],2),col=3,lty=4); 2960 lines(c(en12[1]+i21,.5+sum(en12)),rep(xd2[i21],2),col=4,lty=4); 2961 } 2962 } 2963 2964 a0=1; 2965 2966 if(!notitle) 2967 { 2968 if(test > 2) 2969 { 2970 mtext(ttl1,side=3,line=1.8,cex=1.2,adj=0); 2971 } 2972 mtext(titl,line=.3,cex=1.2,adj=0); 2973 mtext(ttl2,side=3,line=0.5,cex=1.2,adj=0); 2974 mtext(ttl0,side=3,line=3.4,cex=1.2); 2975 mtext(about1,side=3,line=1.8,cex=1.2,adj=a0); 2976 mtext(about,side=3,line=0.5,cex=1.2,adj=a0); 2977 if(en[2] > 0) abline(v=en[1]+.5,lty=3) 2978 } 2979 2980 if(fini == 1) 2981 { 2982 axis(4,label=F,at=dt$RX[nid+1],tcl=.25,lwd=2); # Next EX had test cont'd (BL, Inside Box) 2983 axis(4,label=F,at=zee,tcl=-.25,lwd=2); # zee = pth quantile (BL, Outside Box) 2984 axis(4,label=F,at=tzee,tcl=-.25,lwd=2,col=8); # zee = pth quantile 2985 axis(4,label=F,at=tzee,tcl=.25,lwd=2,col=8); # zee = pth quantile 2986 } 2987 } 2988 reset(); 2989 return(); 2990 } 2991 2992 pSdat2=function(dat,notitle=F) 2993 { 2994 dt=dtt=dat$d0; about=dat$about; titl=dat$titl; pee=dat$p; 2995 ln=dat$ln; iseed=dat$iseed; lev=dat$lev; 2996 ttl1=dat$ttl1; ttl2=dat$ttl2; ttl0=dat$ttl0; test=dat$test; 2997 tmu=dat$tmu; tsig=dat$tsig; 2998 M=dat$M; dm=dat$dm; ds=dat$ds; 2999 3000 if(length(pee) == 0) pee=0; 3001

Page 39:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

id=dt$ID; nid=length(id); 3002 fini=0; if(id[nid]=="III3") fini=1; 3003 if(fini == 1) {dtt=dtt[-nid,]; id=id[-nid]; nid=nid-1;} 3004 3005 if(M == 1) 3006 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[11],",",n[12],",",n[2],",",n[3],"|p,",lambda,3007 ",res}",sep="")) else 3008 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[11],",",n[12],",",n[2],",",n[3],"|p,",lambda,3009 ",res,M}",sep="")); 3010 3011 kp=0; 3012 for(j in 1:nid) 3013 { 3014 jj=m.update(dtt[1:j,]); 3015 M0=jj$M0; m1=jj$m1; 3016 uv=c(M0,m1); 3017 if(!any(is.na(uv))) {if(M0 > m1) kp=j;} 3018 if(kp > 0) break; 3019 } 3020 3021 mus=sigs=zee=rep(0,nid-kp+1); 3022 3023 if(kp == 0) cat("ptest(z,plt=2) option requires having completed Phase I2 (i.e., achieving overlap)\n"); 3024 if(kp > 0) 3025 { 3026 for(j in kp:nid) {g=glmmle(dtt[1:j,]); mus[j-kp+1]=g$mu; sigs[j-kp+1]=g$sig;} 3027 if(pee > 0 & pee < 1)zee=mus+qnorm(pee)*sigs; 3028 par(mfrow=c(2,1), mar=c(1.5,2.5,.5,.5), oma=c(2,2,3.5,2)); 3029 lmu=pretty(mus); lsig=pretty(sigs); lx=pretty(c(kp,nid)); rx=kp:nid; rxx=range(rx); 3030 if(diff(rxx)==0)rxx=rxx+c(-1,1) 3031 plot(kp:nid,mus,type="l",xlab="",ylab="",xlim=rxx,xaxt="n",ylim=range(lmu),yaxt="n"); 3032 axis(1,at=kp:nid,labels=T,tck=-.03,mgp=c(1,.4,0),cex.axis=.8); 3033 axis(2,at=lmu,labels=T,tck=-.02,mgp=c(1,.4,0),las=2,cex.axis=.8); 3034 if(ln) mtext("Mean(Log)",side=2,line=3,cex=1) else mtext("Mean",side=2,line=3,cex=1); 3035 3036 lt=3; abline(h=lmu,lty=lt); abline(v=lx,lty=lt); 3037 points(kp:nid,mus,pch=16,cex=.8); 3038 if(kp == nid) nlx=2 else nlx=nid-kp; 3039 plot(kp:nid,sigs,type="l",xlab="",ylab="",ylim=range(lsig),yaxt="n",xlim=rxx,xaxt="n"); 3040 axis(1,at=kp:nid,labels=T,tck=-.03,mgp=c(1,.4,0),cex.axis=.8); 3041 axis(2,at=lsig,labels=T,tck=-.02,mgp=c(1,.4,0),las=2,cex.axis=.8); 3042 mtext("Cumulative Test Size (n)",side=1,line=0,cex=1,outer=T); 3043 if(ln) mtext("SD(Log)",side=2,line=3,cex=1) else mtext("SD",side=2,line=3,cex=1); 3044 3045 abline(h=lsig,lty=lt); abline(v=lx,lty=lt); 3046 points(kp:nid,sigs,pch=16,cex=.8); 3047 par(mfrow=c(1,1)); 3048 els=c(2.5,1); 3049 3050 if(!notitle) 3051 { 3052 mtext(ttl0,line=2.7,cex=1.1); 3053 mtext(ttl1,side=3,line=1.5,cex=1.1,adj=0); 3054 mtext(about1,side=3,line=1.4,cex=1.1,adj=1); 3055 mtext(ttl2,side=3,line=.3,cex=1.1,adj=0); 3056 mtext(about,side=3,line=.3,cex=1.1,adj=1); 3057 } 3058 3059 } 3060 reset(); 3061 return(matrix(c(mus,sigs,zee),ncol=3)); 3062 } 3063 3064 pSdat3=function(dat,notitle=F) 3065 { 3066 dt=dtt=dat$d0; about=dat$about; titl=dat$titl; unit=dat$unit; 3067 ln=dat$ln; iseed=dat$iseed; lev=dat$lev; test=dat$test; 3068 tmu=dat$tmu; tsig=dat$tsig; 3069 M=dat$M; dm=dat$dm; ds=dat$ds; 3070 ttl1=dat$ttl1; ttl2=dat$ttl2; ttl0=dat$ttl0; 3071 id=dt$ID; nid=length(id); 3072 fini=0; if(id[nid]=="III3") fini=1; 3073 if(fini == 1) {dtt=dtt[-nid,]; nid=nid-1;} 3074 3075 if(M == 3076 1)about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[11],",",n[12],",",n[2],",",n[3],"|p,",lambd3077 a,",res}",sep="")) else 3078 about1=expression(paste("{",mu[lo],",",mu[hi],",",sigma[g],"|",n[11],",",n[12],",",n[2],",",n[3],"|p,",lambda,3079 ",res,M}",sep="")); 3080

Page 40:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

3081 kp=0; 3082 for(j in 1:nid) 3083 { 3084 jj=m.update(dtt[1:j,]); 3085 M0=jj$M0; m1=jj$m1; 3086 uv=c(M0,m1); 3087 if(!any(is.na(uv))) {if(M0 > m1) kp=j;} 3088 if(kp > 0) break; 3089 } 3090 3091 if(kp == 0) cat("ptest(z,plt=3) option requires having completed Phase I2 (i.e., achieving overlap)\n"); 3092 if(kp > 0) 3093 { 3094 blrb5(); 3095 3096 xx="Enter conf and J: "; 3097 xx=readline(xx); cat("\n"); 3098 xx=as.numeric(unlist(strsplit(xx," "))); 3099 conf=xx[1]; J=xx[2]; 3100 cf=round(conf,4); cf=as.character(cf); cf=gsub("0.",".",cf,fixed=T); 3101 pcf=substitute(paste(c[1],"=",cf,sep="")); 3102 3103 if(ln) z=qrda(dtt,conf,J,ln=T,labx=unit) else 3104 z=qrda(dtt,conf,J,labx=unit); 3105 r1=.5; if(test == 3 | test == 4) r1=1; 3106 ntx=substitute(paste(ttl1,", ",pcf,sep="")); 3107 3108 if(!notitle) 3109 { 3110 if(test == 3 | test == 4)mtext(ntx,side=3,line=1.6,cex=1.1,adj=0) else 3111 mtext(pcf,side=3,line=1.5,cex=1.1,adj=0) 3112 mtext(ttl0,side=3,line=2.8,cex=1.1); 3113 mtext(about1,side=3,line=1.4,cex=1.1,adj=1); 3114 mtext(ttl2,side=3,line=.2,cex=1.1,adj=0); 3115 mtext(about,side=3,line=.2,cex=1.1,adj=1); 3116 } 3117 3118 } 3119 return(z) 3120 } 3121 3122 # NEXT TWO TO REPRODUCE FIGURE 4 IN CHANCE ARTICLE 3123 3124 nmel3=function(mu,sg,conf,nt,ns,isd0,test=1,targp=.5,meth=3,fixx=T,inum=-1,icirc=numeric(0)) 3125 { 3126 3127 # Offsets: dm=ds=0 3128 # Sigma=Sigma True, Vnom=True Mu 3129 # mlo=Vnom-4*Sigma, mhi=Vnom+4*Sigma, sg=Sigma (Scaled by 10) 3130 # True Mu = (mlo+mhi)/2 3131 # True Sig = sg 3132 # nt = n test 3133 3134 t0=proc.time() 3135 mnfv=mass=numeric(0); 3136 fail=fMASS=fMNFV=fBOTH=0; 3137 k=4; v0=50; #(CHANCE Article) 3138 i=0 3139 savtest=NULL 3140 em=es=ts=cee=numeric(0) 3141 gnum=numeric(0) 3142 3143 while(i < ns) 3144 { 3145 i=i+1 3146 isd=isd0+nt*(i-1); 3147 mlo=mu-k*sg; 3148 mhi=mu+k*sg; 3149 if(test==2)g=gonogoSim(mlo,mhi,sg,n2=--nt,test=2,iseed=isd) else 3150 g=gonogoSim(mlo,mhi,sg,n2=-nt,test=1,iseed=isd) 3151 #if(i == 1431) {savtest=g} 3152 if(length(icirc) == 1) { if(i == icirc) savtest=g; } 3153 3154 if(i == inum) gnum=g 3155 em=c(em,g$mhat) 3156 es=c(es,g$shat) 3157 u=lims(meth,g$d0,conf,P=c(.001,.000001)) 3158 3159

Page 41:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

mnfv=c(mnfv,u[1,1]) 3160 mass=c(mass,u[2,2]) 3161 3162 if(u[1,1] <= v0) m1=1 else m1=0 3163 if(u[2,2] <= v0) m2=1 else m2=0 3164 3165 fMNFV=fMNFV+m1; 3166 fMASS=fMASS+m2; 3167 fBOTH=fBOTH+m1*m2; 3168 eff=m1+m2-m1*m2; 3169 fail=fail+eff; 3170 cee=c(cee,1+eff) 3171 ts=c(ts,1-fail/i) 3172 #if(!fixx & i >= ns & targp == fail/i) break 3173 #if(fixx & i == ns) break 3174 if(i == ns) break 3175 } 3176 pass=1-fail/i 3177 t1=proc.time()-t0 3178 t1=as.numeric(t1[3]) 3179 w=which(cee == 2) 3180 print(round(c(t1,ns,i,mu,sg,pass),6)); 3181 3182 mmm=list(nt=nt,isd0=isd0,mu=mu,sg=sg,nsim=ns,i=i,fMNFV=fMNFV,fMASS=fMASS, 3183 fBOTH=fBOTH,Ppass=pass,t1=t1,em=em,es=es,w=w,conf=conf,inum=inum, 3184 gnum=gnum,ts=ts,meth=meth,mnfv=mnfv,mass=mass,targp=targp,savtest=savtest) 3185 3186 if(length(icirc) == 1) plotmm(mmm,icirc) else plotmm(mmm) 3187 3188 return(mmm) 3189 } 3190 3191 plotmm=function(mm,icirc=numeric(0)) 3192 { 3193 w=mm$w 3194 fMNFV=mm$fMNFV 3195 fBOTH=mm$fBOTH 3196 fMASS=mm$fMASS 3197 ii=mm$i 3198 mass=mm$mass 3199 mnfv=mm$mnfv 3200 sg=mm$sg 3201 mu=mm$mu 3202 isd0=mm$isd0 3203 nt=mm$nt 3204 3205 aa=paste("Counts per Quadrant Number (1, 2, 3, 4) = (",ii+fBOTH-fMNFV-fMASS,", ",fMNFV-fBOTH,", ",fBOTH,", 3206 ",fMASS-fBOTH,")",sep="") 3207 t3=ii-(fMNFV+fMASS-fBOTH); 3208 t4=round(t3/ii,3) 3209 t1=round(10*mu,3); t2=round(10*sg,3); ti=mm$isd0; 3210 bb=substitute(paste("2000 Simulations with ",V[nom]," = ",t1,", ",sigma[nom]," = ",t2,", ",i[seed[0]]," = 3211 ",ti,sep="")); 3212 bbb=substitute(paste("Figure 4. Pr [Qualifying ] = ",t3," / ",ii," = ",t4,sep="")); 3213 3214 plot(10*mnfv,10*mass,pch=16,cex=.4,xlab="",ylab="",type="n") 3215 points(10*mnfv[-w],10*mass[-w],pch=16,cex=.4,col=1) 3216 points(10*mnfv[w],10*mass[w],pch=16,cex=.4,col=1) 3217 mtext("MNFV",side=1,line=2.3) 3218 mtext("MASS",side=2,line=2.3) 3219 mtext(bb,side=3,line=1.6,cex=1) 3220 mtext(bbb,side=1,line=3.5,cex=.9) 3221 mtext(aa,side=3,line=.6,cex=1) 3222 3223 abline(v=500,lty=3) 3224 abline(h=500,lty=3) 3225 3226 if(length(icirc == 1)) 3227 { 3228 points(10*mm$mnfv[icirc],10*mm$mass[icirc],cex=1.2) 3229 ti1=paste("Test ",isd0+nt*(icirc-1),": ",sep="") 3230 text(432,643,ti1,cex=1) 3231 points(470,641,pch=16,cex=.4) 3232 points(470,641,cex=1.2) 3233 lines(c(389,481),c(632,632),lty=1) 3234 ti2=paste("MNFV = ",round(10*mm$mnfv[icirc],4),sep="") 3235 ti3=paste("MASS = ",round(10*mm$mass[icirc],4),sep="") 3236 text(436,623,ti2,cex=.9) 3237 text(436,608,ti3,cex=.9) 3238

Page 42:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

} 3239 3240 return() 3241 } 3242 3243 #INDEX 54-96, XComm (41 functions plus two constants) 3244 3245 skewL=function(c1,nu,tau2,p,be) 3246 { 3247 # tau2 = the square of tau 3248 # nu = sqrt(tau2)*c1 where c1 = f3point8(lambda) (solving 3.8) 3249 # Compute a by 3.9 & 3.12 (below u=E(Zn*M(Zn)) & v=E(M(Zn)) ) 3250 3251 j=qnorm(p)+be*nu; 3252 k=sqrt(1+be^2*tau2); 3253 v=pnorm(j/k); 3254 u=be*tau2*dnorm(j/k)/k+nu*v; 3255 a=(u-nu*v)/(v*(1-v)); 3256 3257 # Compute next tau2 by 3.4 & 3.12 3258 3259 ntau2=a^2*v*(1-v)-2*a*(u-nu*v)+tau2; 3260 3261 # Compute next nu 3262 3263 nnu=sqrt(ntau2)*c1; 3264 3265 # Compute next b by 3.10 & 3.12 3266 3267 b=v-(nu-nnu)/a; 3268 3269 return(c(j,k,v,u,a,ntau2,nnu,b)) 3270 } 3271 3272 n.update=function(dat) 3273 { 3274 n1=sum(dat[,2]); 3275 n0=ncol(t(dat))-n1; 3276 ret=list(n0,n1); 3277 names(ret)=c("n0","n1"); 3278 return(ret); 3279 } 3280 3281 m.update=function(dat) 3282 { 3283 n1=sum(dat[,2]); 3284 n0=ncol(t(dat))-n1; 3285 M0=m1=NA 3286 if(n0 > 0) M0=max(dat[dat[,2]==0,1],na.rm=T); 3287 if(n1 > 0) m1=min(dat[dat[,2]==1,1],na.rm=T); 3288 ret=list(M0,m1); 3289 names(ret)=c("M0","m1"); 3290 return(ret); 3291 } 3292 3293 glmmle = function(mydata, lgit = F) 3294 { 3295 mydata=na.omit(mydata); 3296 x = rep(mydata$X, mydata$COUNT); 3297 y = rep(mydata$Y, mydata$COUNT); 3298 options(warn = -1); # otherwise, R version complains in following while loop 3299 nmxx=c("mu","sig","llik","anom","mix","overlap","remo0","remo1","bigk","okk","mhat","shat","xm","xs"); 3300 bigk=okk=numeric(0); 3301 3302 j=m.update(mydata); M0=j$M0; m1=j$m1; 3303 xm=(j$M0+j$m1)/2; xs=(j$M0-j$m1); 3304 remo0=remo1=0; 3305 3306 if(all(y==1) | all(y==0)) 3307 { 3308 anom=T; mix=F; overlap=F; mu=NA; sig=NA; ll=NA; 3309 xx=list(mu, sig, ll, anom, mix, overlap, remo0, remo1, bigk, okk, mu, sig, xm, xs); 3310 names(xx)=nmxx; 3311 return(xx); 3312 } 3313 3314 if(xs < 0) 3315 { 3316 anom=T; mix=T; overlap=F; mu=xm; sig=-xs/6; ll=0; 3317

Page 43:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

xx=list(mu, sig, ll, anom, mix, overlap, remo0, remo1, bigk, okk, mu, sig, xm, xs); 3318 names(xx)=nmxx; 3319 return(xx); 3320 } 3321 3322 if(xs == 0) 3323 { 3324 anom=T; mix=T; overlap=T; mu=xm; sig=0; iw=which(x==M0); ll=NA; if(M0 > 0) ll=log(M0^iw); 3325 xx=list(mu, sig, ll, anom, mix, overlap, remo0, remo1, bigk, okk, mu, sig, xm, xs); 3326 names(xx)=nmxx; 3327 return(xx); 3328 } 3329 3330 u=tauf(x,y); tau=u$tau; p1=u$p1; 3331 3332 if(tau <= 0) 3333 { 3334 anom=T; mix=T; overlap=T; mu=-Inf; sig=Inf; 3335 iov=x >= M0 & x <= m1; 3336 ovx=x[iov]; nov=length(ovx); 3337 ll=sum(y[ovx])*log(p1) + (nov-sum(y[ovx]))*log(1-p1); 3338 xx=list(mu, sig, ll, anom, mix, overlap, remo0, remo1, bigk, okk, mu, sig, xm, xs); 3339 names(xx)=nmxx; 3340 return(xx); 3341 } 3342 3343 # KNOW xs > 0 & tauf(x,y) > 0 3344 # R's GLM WORKS WITH NEAR 0/1 FITTED PROBABILITIES (unlike S's GLM) 3345 3346 if(lgit) xglm = glm(y ~ x, family = binomial(link = logit)) else 3347 xglm = glm(y ~ x, family = binomial(link = probit)) 3348 ab = as.vector(xglm$coef); 3349 3350 anom=F; mix=T; overlap=T; mu= -ab[1]/ab[2]; sig=1/ab[2]; ll=llik(mydata,mu,sig); 3351 xx=list(mu, sig, ll, anom, mix, overlap, remo0, remo1, bigk, okk, mu, sig, xm, xs); 3352 names(xx)=nmxx; 3353 return(xx); 3354 } 3355 3356 llik = function(mydata, mu, sig) 3357 { 3358 # Remove rows of data having NA's in them 3359 mydata=na.omit(mydata) 3360 x = mydata$X 3361 y = mydata$Y 3362 n = mydata$COUNT 3363 i1 = which(y == 1) 3364 eps = 1e-006 3365 if(sig < eps) sig = eps 3366 ll = n[i1] * log(pnorm((x[i1] - mu)/sig)) 3367 ll = c(ll, n[ - i1] * log(1 - pnorm((x[ - i1] - mu)/sig))) 3368 a=sum(ll); if(is.na(a))a=-Inf; 3369 return(a) 3370 } 3371 3372 tauf = function(x,y) 3373 { 3374 # See A. B. OWEN and P. A. ROEDIGER, The Sign of the Logistic Regression Coefficient, 3375 # The American Statistician, November 2014, Vol. 68, No. 4, pp 297 - 301 3376 3377 st=x; 3378 i1=which(y==1); 3379 i0=which(y==0); 3380 r1=r0=n=rep(1,length(x)); 3381 r1[i0]=0; 3382 r0[i1]=0; 3383 nt=sum(n); n1=sum(r1); n0=sum(r0); 3384 # tau1=sum((r1/n-n1/nt)*(n*st)); tau2=sum(r1*st)-n1*sum(n*st)/nt; 3385 # tau3=sum(r1*st)-n1*weighted.mean(st,n); 3386 # tau4=n1*(weighted.mean(st,r1)-weighted.mean(st,n)); 3387 tau5=n0*n1*(weighted.mean(st,r1)-weighted.mean(st,r0))/(n0+n1); 3388 xx=list(tau5,n1/nt); 3389 names(xx)=c("tau","p1"); 3390 return(xx) 3391 } 3392 3393 # yinfomat returns a scale-free (SF) version of infm, vcov and deti 3394 # yqrda has been adjusted accordingly: 3395 # actual infm = SF infm X sig^2; actual vcov = SF vcov / sig^2 3396

Page 44:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

# actual deti = SF deti / sig^4; (Note: actual rho = SF rho) 3397 3398 yinfomat = function(dat, mu, sig) 3399 { 3400 n = dat$COUNT 3401 k = (dat$X - mu)/sig 3402 p = pnorm(k) * (1 -pnorm(k)) 3403 3404 z = dnorm(k) 3405 v = n*z^2/p 3406 v[which(v == Inf)]=0 3407 3408 # z, e.g., z = 4.881666e-226, is s.t. z^2 == 0 exactly 3409 # so that, when p == 0 exactly, v = 0/0 = NA 3410 # Therefore, have to remove the NA's if there are any 3411 iy=which(is.na(v)) 3412 if(length(iy) > 0){v=v[-iy]; k=k[-iy];} 3413 3414 b11= sum(v) 3415 b21 = b12 = sum(v*k) 3416 b22 = sum(v*k^2) 3417 3418 # FISHER INFORMATION MATRIX 3419 infm = matrix(c(b11, b12, b21, b22), nrow = 2, byrow = T) 3420 # DETERMINANT OF INFORMATION MATRIX 3421 deti = det(infm) 3422 # VARIANCE COVARIANCE MATRIX 3423 vcov1 = solve(infm) 3424 # CORRELATION COEFFICIENT 3425 rho=vcov1[1,2]/sqrt(vcov1[1,1]*vcov1[2,2]); 3426 xx=list(vcov1,infm,deti,rho); 3427 names(xx)=c("vcov1","infm","deti","rho"); 3428 return(xx) 3429 } 3430 3431 Sk=function(k,b) 3432 { 3433 # b is the information matrix 3434 v=b[1,1]*k^2-2.0*b[1,2]*k+b[2,2] 3435 return(v) 3436 } 3437 3438 Gk=function(k) 3439 { 3440 pk=pnorm(k) 3441 gk=dnorm(k)/sqrt(pk*(1-pk)) 3442 return(gk^2) 3443 } 3444 3445 dgs=function(k,b) 3446 { 3447 # derrivative of g^2*s, where g=dk/sqrt(pk*(1-pk)) 3448 # s=b11*k^2-2*b12*k+b22, b=Information Matrix 3449 pk=pnorm(k) 3450 dk=dnorm(k) 3451 sk=b[1,1]*k^2-2*b[1,2]*k+b[2,2] 3452 j=2*(b[1,1]-sk)*k-(2*b[1,2]+dk*sk*(1-2*pk)/(pk*(1-pk))) 3453 return(j) 3454 } 3455 3456 kstar=function(b) 3457 { 3458 # b=information matrix; presumption: kmax & b12 have opposite signs 3459 # first part finds [l2,0] or [0,l2] containing the max g(k)^2*s(k) 3460 # second part solves for the zero of d/dk of g(k)^2*s(k) 3461 # this function uses functions Sk, Gk and dgs 3462 del=-1 3463 k1=0 3464 val1=Gk(k1)*Sk(k1,b) 3465 val2=val1+1 3466 if(b[1,2] <= 0)del=1 3467 while(val2 > val1) 3468 { 3469 k2=k1+del 3470 val2=Gk(k2)*Sk(k2,b) 3471 k1=k2 3472 } 3473 eps=.000001 3474 k1=0 3475

Page 45:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

v1=dgs(k1,b) 3476 v2=dgs(k2,b) 3477 while(abs(k2-k1) > eps | abs(v2-v1) > eps) 3478 { 3479 kmid=(k1+k2)/2 3480 vmid=dgs(kmid,b) 3481 if(v1*vmid > 0){v1=vmid; k1=kmid;} else {v2=vmid; k2=kmid;} 3482 } 3483 kmax=(k1+k2)/2 3484 return(kmax) 3485 } 3486 3487 pavdf=function(data.df, ln, plotit = F, lineit = F, labx = "STIMULUS", laby = 3488 "PROBABILITY OF RESPONSE", titl = "PAV SOLUTION") 3489 { 3490 # 3491 # FUNCTION TO COMPUTE AND PLOT POOLED ADJACENT VIOLATORS (PAV) ALGORITHM 3492 # responses are assumed to be 1 where Pr[Y=1] increases as the stress increases 3493 # data.df is a 3 Column dataframe who's Column Names are: 3494 # X=Stresses, Y=Responses, COUNT=Number of Y's per X, respectively. 3495 # RETURNS list with components: $full, matrix with a number of rows = length(events) 3496 # $unique, matrix with number of rows = length(unique(x)) 3497 # $coords, matrix with each row a point for plotting pav 3498 # solution vs x for each unique prob estimate 3499 # 3500 events = data.df$Y 3501 trials = data.df$COUNT 3502 x = data.df$X 3503 x = rep(x, trials) 3504 events = rep(events, trials) 3505 trials = rep(1, length(x)) 3506 k = length(events) 3507 if(length(x) == 0.) x = 1.:k else 3508 { 3509 events = events[order(x)] 3510 trials = trials[order(x)] 3511 x = sort(x) 3512 xuniq = unique(x) 3513 k = length(xuniq) 3514 evtmp = rep(0., k) 3515 tritmp = rep(0., k) 3516 for(i in 1.:k) { 3517 evtmp[i] = sum(events[x == xuniq[i]]) 3518 tritmp[i] = sum(trials[x == xuniq[i]]) 3519 } 3520 } 3521 events = evtmp 3522 trials = tritmp 3523 p = matrix(0., k, 1.) 3524 pp = matrix(0., k, k) 3525 for(i in 1.:k) { 3526 sum1 = 0. 3527 sum2 = 0. 3528 for(j in i:k) { 3529 sum1 = sum1 + events[j] 3530 sum2 = sum2 + trials[j] 3531 pp[i, j] = sum1/sum2 3532 } 3533 temp = as.matrix(pp[(1.:i), (i:k)]) 3534 p[i] = ifelse(i > 1., max(apply(temp, 1., min)), min(temp)) 3535 } 3536 puniq = unique(p) 3537 kk = length(puniq) 3538 xp = rep(0., kk) 3539 for(i in 1.:kk) { 3540 xp[i] = min(xuniq[p == puniq[i]]) 3541 } 3542 3543 if(ln) {xp=exp(xp); xplt = c(xp[1.], rep(xp[-1.], rep(2., length(xp) - 1.)), max(exp(x)));} else 3544 xplt = c(xp[1.], rep(xp[-1.], rep(2., length(xp) - 1.)), max(x)) 3545 pplt = c(rep(puniq, rep(2., length(puniq)))) 3546 if(plotit) { 3547 if(!lineit) 3548 plot(xplt, pplt, type = "n", xlab = labx, ylab = laby, main 3549 = titl) 3550 lines(xplt, pplt, lwd = 2.) 3551 } 3552 xx = list(full = cbind(xuniq, events/trials, p), unique = cbind(xp, puniq), 3553 coords = cbind(xplt, pplt)) 3554

Page 46:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

return(xx) 3555 } 3556 3557 blrb1=function() 3558 { 3559 x= 3560 " 3561 This program executes the 3podm sensitivity test procedure as described in: 3562 1. Wu, C. F. J, Tian, Y., Three-phase optimal design of sensitivity 3563 experiments Journal of Statistical Planning and Inference 149 (2014), 1-15 3564 2. Wang, D. P., Tian, Y., Wu, C. F. Jeff, A Skewed Version of the Robbins-Munro- 3565 Joseph Procedure for Binary Response, Statistica Sinica (2015), 1679-1689 3566 3. Wang, D. P., Tian, Y., Wu, C. F. Jeff, Comprehensive Comparisons of Major 3567 Design Procedures for Sensitivity Testing (2018), Journal of Quality 3568 Technology (To Appear) 3569 3570 Questions about the R code or use of the procedure may be directed to: 3571 Paul Roediger, UTRS, Inc. <[email protected]>, and/or 3572 Douglas Ray, US Army ARDEC, Picatinny Arsenal <[email protected]> 3573 3574 " 3575 cat(x) 3576 return() 3577 } 3578 3579 blrb2=function() 3580 { 3581 x= 3582 " 3583 This program executes the Neyer sensitivity test procedure as described in: 3584 1. Neyer, Barry T., A D-Optimality-Based Sensitivity Test, Technometrics, 36, 3585 61-70 (1994) 3586 2. Ray, D. M., Roediger, P. A., and Neyer, B. T., Commentary: Three-phase 3587 optimal design of sensitivity experiments, Journal of Statistical Planning 3588 and Inference, 149, 20-25 (2014) 3589 3. http://neyersoftware.com/SensitivityTest/SensitivityTestFlyer.htm 3590 3591 Questions about the R code or use of the procedure may be directed to: 3592 Paul Roediger, UTRS, Inc. <[email protected]>, and/or 3593 Douglas Ray, US Army ARDEC, Picatinny Arsenal <[email protected]> 3594 3595 " 3596 cat(x) 3597 return() 3598 } 3599 3600 blrb3=function() 3601 { 3602 x= 3603 " 3604 This program executes the Bruceton sensitivity test procedure* as described in: 3605 1. Dixon, W. J., Mood, A. M., A method for obtaining and analyzing sensitivity 3606 data, Journal of the American Statistical Association, 43, pp. 109-126, (1948) 3607 2. Dixon, W. J., Massey, F. J., Introduction to Statistical Analysis, McGraw-Hill, 2nd 3608 Edition, Chapter 6, (1957) 3609 3. Einbinder, S.K., Reliability Models and Estimation of Stress-Strength, 3610 Dissertation, Polytechnic Institute of Brooklyn (1973) 3611 4. Wetherill, G.B., Sequential Estimation of Quantal Response Curves, 3612 Journal of the Royal Statististical Society, B, Vol. 25, pp. 1-48, (1963) 3613 3614 * Developed at the Explosives Research Laboratory in Bruceton, PA (1941-1945) 3615 http://www.dtic.mil/dtic/tr/fulltext/u2/116878.pdf 3616 3617 Questions about the R code or use of the procedure may be directed to: 3618 Paul Roediger, UTRS, Inc. <[email protected]>, and/or 3619 Douglas Ray, US Army ARDEC, Picatinny Arsenal <[email protected]> 3620 3621 " 3622 cat(x) 3623 return() 3624 } 3625 3626 blrb4=function() 3627 { 3628 x= 3629 " 3630 This program executes the Langlie sensitivity test procedure as described in: 3631 1. Langlie, H. J., A Reliability Test Method For “One-Shot” Items, Publication 3632 No. U-1792, Aeronutronic Division of Ford Motor Company (1962) 3633

Page 47:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

2. Einbinder, S.K., Reliability Models and Estimation of Stress-Strength, 3634 Dissertation, Polytechnic Institute of Brooklyn (1973) 3635 3. Einbinder, S. K., One Shot Sensitivity Test for Extreme Percentage Points, 3636 ARO Report 74-1, Proceedings of the Nineteenth Conference on the Design of 3637 Experiments in Army Research, Development and Testing, pp. 369-386, (1974) 3638 http://www.dtic.mil/dtic/tr/fulltext/u2/a002564.pdf 3639 4. Wetherill, G.B., Sequential Estimation of Quantal Response Curves, 3640 Journal of the Royal Statististical Society, B, Vol. 25, pp. 1-48, (1963) 3641 3642 Questions about the R code or use of the procedure may be directed to: 3643 Paul Roediger, UTRS, Inc. <[email protected]>, and/or 3644 Douglas Ray, US Army ARDEC, Picatinny Arsenal <[email protected]> 3645 3646 " 3647 cat(x) 3648 return() 3649 } 3650 3651 blrb5=function() 3652 { 3653 x= 3654 " 3655 3656 This function requires two inputs, conf & J. Choose J from the following ... 3657 3658 ------------------------------------------ ----------------------- 3659 | To Plot Confidence Interval(s) about: || Via the Method(s) | 3660 | Probability (p) | Quantile (q) | p&q || FM | LR | GLM | 3661 -------|-------------------|---------------|------||-------|-------|-------| 3662 | | 1 | 2 | 3 || X | | | 3663 | |-------------------|---------------|------||-------|-------|-------| 3664 | | | | 4 || | X | | 3665 | |-------------------|---------------|------||-------|-------|-------| 3666 | Enter | 5 | 6 | 7 || | | X | 3667 | this |-------------------|---------------|------||-------|-------|-------| 3668 | value | 8 | 9 | || X | X | | 3669 | for |-------------------|---------------| -----||-------|-------|-------| 3670 | J | 10 | 11 | || X | | X | 3671 | |-------------------|---------------| -----||-------|-------|-------| 3672 | | 12 | 13 | || | X | X | 3673 | |-------------------|---------------| -----||-------|-------|-------| 3674 | | 14 | 15 | || X | X | X | 3675 ------- ------------------------------------------ ----------------------- 3676 3677 " 3678 cat(x) 3679 return() 3680 } 3681 3682 blrb6=function() 3683 { 3684 x= 3685 " 3686 Three entries (separated by blanks) are required, namely - 3687 3688 (1) nRev: the number of reversals needed to exit Phase I, and 3689 (2) two i values (chosen from the following table) 3690 3691 i Down(X=1,O=0) Up(X=1,O=0) p 3692 ---- --------------- --------------------- ---------- 3693 | 1 | X | O | .500000 | 3694 | 3 | XX | {O, XO} | .707107 | 3695 | 5 | XXX | {O, XO, XXO} | .793701 | 3696 | 7 | XXXX | {O, XO, XXO, XXXO} | .840896 | 3697 | : | : | : | : | 3698 ---- --------------- --------------------- --------- 3699 | 0 | - | - | - | 3700 | 2 | {XX, XOX} | {O, XOO} | .596968 | 3701 | 4 | {XXX, XXOX} | {O, XO, XXOO} | .733614 | 3702 | 6 | {XXXX, XXXOX} | {O, XO, XXO, XXXOO} | .804119 | 3703 | : | : | : | : | 3704 ---- --------------- --------------------- ---------- 3705 Up(X=0,O=1) Down(X=0,O=1) 1-p 3706 3707 " 3708 cat(x) 3709 return() 3710 } 3711 3712

Page 48:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

# Two functions to solve equation 3.8 in skewed RMJ paper 3713 3714 f38=function(x,l) 3715 { 3716 a=(l-1)*pnorm(-x)+1; 3717 b=(l-1)*dnorm(-x); 3718 h=a*x-b; 3719 return(h); 3720 } 3721 3722 f3point8=function(l) 3723 { 3724 if(l <= 0 | l == 1) return(0); 3725 x=0; del=0.2; h=1; 3726 v=f38(x,l); 3727 # l > 1 3728 if(v < 0) 3729 { 3730 while(h > 0) 3731 { 3732 ll=x; 3733 x=x+del; 3734 h=f38(x,l)*v; 3735 } 3736 ul=x; 3737 } 3738 3739 # l < 1 3740 if(v > 0) 3741 { 3742 while(h > 0) 3743 { 3744 ul=x; 3745 x=x-del; 3746 h=f38(x,l)*v; 3747 } 3748 ll=x; 3749 } 3750 3751 eps=.000001; 3752 w=10; 3753 m=(ll+ul)/2; 3754 while(abs(w) > eps) 3755 { 3756 w=f38(m,l); 3757 3758 if(w < 0) ll=m else ul=m; 3759 3760 m=(ll+ul)/2; 3761 } 3762 m=(ll+ul)/2; 3763 return(m); 3764 } 3765 3766 fgs=function(mlo,mhi,sg) 3767 { 3768 fg0=log((mhi+3*mlo)^3/(16*(3*mhi+mlo)))/2; 3769 fg1=log((3*mhi+mlo)^3/(16*(mhi+3*mlo)))/2; 3770 fsg=(fg1-fg0)/7; 3771 u=c(fg0,fg1,fsg); 3772 return(u) 3773 } 3774 3775 ifg=function(fg0,fg1) 3776 { 3777 m1=4*exp((fg0+3*fg1)/4); 3778 m0=4*exp((3*fg0+fg1)/4); 3779 mhi=(3*m1-m0)/8; 3780 mlo=(3*m0-m1)/8; 3781 v=c(mlo,mhi); 3782 return(v) 3783 } 3784 3785 addneyr=function(dtt,ylm,sim=F) 3786 { 3787 tf=F; 3788 id=dtt$ID; 3789 nid=length(id); 3790 x=dtt$X; 3791

Page 49:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

s1=c("B0","B1","B2","B3","B4","II1","II2","III1","III2"); 3792 s2=c(rep("I",5),rep("II",2),rep("III",2)); ns=length(s1); 3793 for(i in 1:ns) id=gsub(s1[i],s2[i],id); 3794 u=id[1]; vee=numeric(0); 3795 # vee = index of the first test that isn't I, i.e., vee=numeric(0) when you're still in I 3796 if(nid > 1){for(i in 2:nid) if(id[i]!=u) {vee=c(vee,i); u=id[i];}} 3797 nv=length(vee); 3798 ul=c(vee-1,nid); ll=c(1,vee); 3799 ml=(ll+ul)/2; lab=unique(id); 3800 iv=2; if(nv<=1)iv=1; 3801 3802 text(ml,rep(ylm[2],nv+1),lab,cex=.9); 3803 3804 if(nv == 0) 3805 { 3806 j=m.update(dtt); 3807 M0=j$M0; 3808 m1=j$m1; 3809 w0=which(x==M0); 3810 w1=which(x==m1); 3811 vc=c(M0,m1,w0,w1); 3812 3813 if(!any(is.na(vc)) & M0 > m1) 3814 { 3815 lines(c(w0[[1]],nid+1),c(M0,M0),col=3,lty=4); lines(c(w1[[1]],nid+1),c(m1,m1),col=4,lty=4); 3816 tf=T; 3817 } 3818 } 3819 3820 if(nv > 0) 3821 { 3822 lt=rep(5,nv); abline(v=vee-.5,lty=lt); 3823 3824 j=m.update(dtt[1:(vee[1]-1),]); 3825 M0=j$M0; 3826 m1=j$m1; 3827 w0=which(x==M0); 3828 w1=which(x==m1); 3829 lines(c(w0[[1]],vee[1]-.5),c(M0,M0),col=3,lty=4); lines(c(w1[[1]],vee[1]-.5),c(m1,m1),col=4,lty=4); 3830 } 3831 kp=0; 3832 if(sim) 3833 { 3834 k=1; 3835 if(nv >= 1)k=vee[iv]-1; 3836 for(j in k:nid) { jj=m.update(dtt[1:j,]); M0=jj$M0; m1=jj$m1; uv=c(M0,m1); if(any(is.na(uv))) 3837 break; if(M0 > m1) kp=j; if(kp > 0) break; } 3838 } 3839 return(c(tf,kp)) 3840 } 3841 3842 add3pod=function(dtt,ylm,sim=F) 3843 { 3844 tf=F; 3845 id=dtt$ID; 3846 nid=length(id); 3847 x=dtt$X; 3848 s1=c("r","I1\\(i\\)","I1\\(ii\\)","I1\\(iii\\)","I1\\(iv\\)","I2\\(ib\\)","I2\\(ic\\)","I2\\(id\\)","II1","II23849 ","III1","III2"); 3850 s2=c("",rep("I1",4),rep("I2",3),rep("II",2),rep("III",2)); ns=length(s1); 3851 for(i in 1:ns) id=gsub(s1[i],s2[i],id); 3852 u=id[1]; vee=numeric(0); 3853 # vee = index of the first test that isn't I1, i.e., vee=numeric(0) when you're still in I1 3854 if(nid > 1){for(i in 2:nid) if(id[i]!=u) {vee=c(vee,i); u=id[i];}} 3855 nv=length(vee); 3856 ul=c(vee-1,nid); ll=c(1,vee); 3857 ml=(ll+ul)/2; lab=unique(id); 3858 iv=2; if(nv<=1)iv=1; 3859 3860 text(ml,rep(ylm[2],nv+1),lab,cex=.9); 3861 lt=c(2,2); if(nv > 2) lt=c(lt,rep(4,nv-2)); lt=lt+1; 3862 3863 if(nv > 0) 3864 { 3865 abline(v=vee-.5,lty=lt); 3866 j=m.update(dtt[1:(vee[iv]-1),]); 3867 M0=j$M0; 3868 m1=j$m1; 3869 w0=which(x==M0); 3870

Page 50:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

w1=which(x==m1); 3871 3872 if((nv > 1 | length(vee) != 0) & M0 > m1) 3873 { 3874 lines(c(w0[[1]],vee[iv]-.5),c(M0,M0),col=3,lty=4); lines(c(w1[[1]],vee[iv]-.5),c(m1,m1),col=4,lty=4); 3875 } else 3876 { 3877 j=m.update(dtt); 3878 M0=j$M0; 3879 m1=j$m1; 3880 w0=which(x==M0); 3881 w1=which(x==m1); 3882 if(M0 > m1) 3883 { 3884 lines(c(w0[[1]],nid+1),c(M0,M0),col=3,lty=4); lines(c(w1[[1]],nid+1),c(m1,m1),col=4,lty=4); 3885 #tf=T 3886 } 3887 } 3888 } 3889 kp=0; 3890 if(sim) 3891 { 3892 k=1; 3893 if(nv >= 1)k=vee[iv]-1; 3894 for(j in k:nid) { jj=m.update(dtt[1:j,]); M0=jj$M0; m1=jj$m1; uv=c(M0,m1); if(any(is.na(uv))) 3895 break; if(M0 > m1) kp=j; if(kp > 0) break; } 3896 } 3897 return(c(tf,kp)) 3898 } 3899 3900 addBorL=function(dtt,ylm,ud) 3901 { 3902 id=dtt$ID; lid=length(id); 3903 w1=which(is.element(id,c("IB","IL","D","U",""," "))); 3904 l1=length(w1); 3905 if(l1 > 0) 3906 { 3907 en1=max(w1); a=is.element (id,c(" ","D","U")); b=any(a); 3908 if(b & ud) {mx=max(which(a)); text(1:mx,rep(ylm[2],mx),id[1:mx],cex=.6);} else 3909 text(mean(range(w1)),ylm[2],"I",cex=.9); 3910 3911 if(l1 > 1) 3912 { 3913 dtw=dtt[1:en1,]; 3914 xx=dtw$X; yy=dtw$Y; 3915 j=m.update(dtw); 3916 M0=j$M0; 3917 m1=j$m1; 3918 del=m1-M0; 3919 if(!is.na(del)) 3920 { 3921 w0=which(xx==M0 & yy==0); 3922 w1=which(xx==m1 & yy==1); 3923 if(del < 0) 3924 { 3925 lines(c(w0[[1]],en1+.5),c(M0,M0),col=3,lty=4); 3926 lines(c(w1[[1]],en1+.5),c(m1,m1),col=4,lty=4); 3927 } 3928 } 3929 } 3930 } 3931 3932 w2=which(is.element(id,c("II","II1","II2"))); 3933 l2=length(w2); 3934 if(l2 > 0) {en2=max(w2); abline(v=en1+.5,lty=5); 3935 text(mean(range(w2)),ylm[2],"II",cex=.9); 3936 } 3937 3938 w3=which(is.element(id,c("III","III1","III2","III3"))); 3939 l3=length(w3); 3940 if(l3 > 0) {abline(v=en2+.5,lty=5); en3=max(w3); 3941 text(mean(range(w3)),ylm[2],"III",cex=.9);} 3942 return() 3943 } 3944 3945 ptest=function(dat,plt,notitle=F) 3946 { 3947 if(!is.element(plt,1:8)) 3948 { 3949

Page 51:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

u=paste("plt must be 1, 2, 3, 4, 5, 6, 7 or 8.\nTry again.\n\n",sep=""); 3950 cat(u); 3951 return() 3952 } 3953 if(plt < 4) 3954 { 3955 if(is.null(dat$tmu)) 3956 { 3957 if(plt == 1) {{if(!notitle)pdat1(dat) else pdat1(dat,notitle=T)}; return();} 3958 if(plt == 2) {{if(!notitle)v=pdat2(dat) else v=pdat2(dat,notitle=T)}; return(v);} 3959 if(plt == 3) {{if(!notitle)v=pdat3(dat) else v=pdat3(dat,notitle=T)}; return(v);} 3960 } else 3961 { 3962 if(plt == 1) {{if(!notitle)pSdat1(dat) else pSdat1(dat,notitle=T)}; return();} 3963 if(plt == 2) {{if(!notitle)v=pSdat2(dat) else v=pSdat2(dat,notitle=T)}; return(v);} 3964 if(plt == 3) {{if(!notitle)v=pSdat3(dat) else v=pSdat3(dat,notitle=T)}; return(v);} 3965 } 3966 } else 3967 { 3968 if(plt == 4) {picdat(dat); return();} 3969 if(plt == 5) {{if(!notitle)v=jlrcb(dat) else v=jlrcb(dat,notitle=T)}; return(v);} 3970 if(plt == 6) {{if(!notitle)v=lrcb(dat) else v=lrcb(dat,notitle=T)}; return(v);} 3971 if(plt == 7) {{if(!notitle)v=cbs(dat,plt) else v=cbs(dat,plt,notitle=T)}; return(v);} 3972 if(plt == 8) {{if(!notitle)v=cbs(dat,plt) else v=cbs(dat,plt,notitle=T)}; return(v);} 3973 } 3974 } 3975 3976 # Reset some par() values that may have been changed while graphing 3977 3978 reset=function() 3979 { 3980 par(mar=c(5,4,4,2)+.1, oma=c(0,0,0,0), mgp=c(3,1,0)); 3981 return() 3982 } 3983 3984 # two handy alpha vectors (of length 15 and 49). useful to get confidence 3985 # interval table outputs from the lims function (with P=al15, or P=al49). 3986 3987 al15=c(1,10,100,1000,10000,100000,250000)/1000000; al15=c(al15,.5,sort(1-al15)); 3988 al49=10^(6:2); al49=c(1/al49,1-1/al49); al49=c(al49,seq(25,975,by=25)/1000); al49=sort(al49); 3989 3990 lims=function(ctyp,dat,conf,P=numeric(0),Q=numeric(0)) 3991 { 3992 if(!is.element(ctyp,1:3))return() 3993 np=length(P); nq=length(Q); npq=np+nq; 3994 if(npq == 0 | any(P < 0 | P > 1)) return() 3995 switch(ctyp, 3996 { 3997 nam="FM"; z=fm.lims(dat,conf,P,Q); 3998 }, 3999 { 4000 nam="LR"; z=lrq.lims(dat,conf,P,Q); z=z$lrmat; 4001 }, 4002 { 4003 nam="GLM"; z=glm.lims(dat,conf,P,Q); 4004 } 4005 ); 4006 z=round(z,6); 4007 return(z); 4008 } 4009 4010 cpq=function(P,Q,mu,sig,gt) 4011 { 4012 k=10; 4013 n=1000000.0; 4014 p0=1/(k*n); 4015 p1=1-p0; 4016 q0=mu+qnorm(p0)*sig; 4017 q1=mu+qnorm(p1)*sig; 4018 val=c(p0,p1,q0,q1); 4019 ok=T; 4020 # The 1st line was operative in the simulation version 4021 # Let's use the 2nd line that's used in the console version 4022 if(is.null(gt)){if(any(P < p0) | any(P > p1)) ok=F;} else 4023 {if(any(P < p0) | any(P > p1) | any(Q < q0) | any(Q > q1)) ok=F;} 4024 if(!ok) 4025 { 4026 v=round(val,10); 4027 l7=paste("\nAll P's must be in [",v[1],", ",v[2],"]\n",sep=""); 4028

Page 52:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

v=round(v,4); 4029 l8=paste("All Q's must be in [",v[3],", ",v[4],"]\n",sep=""); 4030 cat(l7); 4031 cat(l8); 4032 cat("Try again\n\n"); 4033 } 4034 return(ok) 4035 } 4036 4037 fm.lims=function(dat,conf,P=numeric(0),Q=numeric(0)) 4038 { 4039 # Calculates qlo, qhi, plo & phi as in ml2002 4040 np=length(P); nq=length(Q); npq=np+nq; 4041 if(npq == 0 | any(P < 0 | P > 1)) return(); 4042 x=rep(dat$X,dat$COUNT); y=rep(dat$Y,dat$COUNT); gt=dat$tmu; 4043 r0=x[y==0]; r1=x[y==1]; 4044 M0=max(r0); m1=min(r1); del=m1-M0; one23=2+sign(del); 4045 # overlap: one23=1 (interval); one23=2 (point); one23=3 (none); 4046 if(one23 > 1) 4047 { 4048 cat("\nFM confidence intervals exist only if there's interval overlap\n\n"); 4049 return() 4050 } 4051 xglm=glm(y ~ x, family = binomial(link = probit)); 4052 ab=as.vector(xglm$coef); 4053 muhat=-ab[1]/ab[2]; 4054 sighat=1/ab[2]; 4055 chk=cpq(P,Q,muhat,sighat,gt); 4056 if(!chk) return(); 4057 al=c(P,pnorm((Q-muhat)/sighat)) 4058 w0=which(al == 0) 4059 w1=which(al == 1) 4060 if(length(w0) > 0) al[w0]=1e-6 4061 if(length(w1) > 0) al[w1]=1-1e-6 4062 # CI's for Normal 4063 qp=qnorm(al); 4064 vcov1=yinfomat(dat,muhat,sighat)$vcov1*sighat^2; 4065 varq=vcov1[1,1]+qp*(qp*vcov1[2,2]+2*vcov1[1,2]); 4066 zscore=qnorm((1+conf)/2) 4067 # With this zscore, get GLM limits ql & qu (essentially same as mdose.p) 4068 # However, with this zscore, you don't get a match with GLM's pl & pu 4069 # zscore=qt((1+conf)/2,xglm$df.residual) 4070 zdel=zscore*sqrt(varq); 4071 q0=muhat+qnorm(al)*sighat; 4072 if(nq > 0) {iq=c(nq:1) - 1; q0[npq-iq]=Q;} 4073 qlo=muhat+qp*sighat-zdel; 4074 qhi=muhat+qp*sighat+zdel; 4075 dpda=1/sqrt(2*pi)*exp(-0.5*qp^2)/sighat; 4076 zdel=dpda*zdel; 4077 plo=al-zdel; plo[which(plo<0)]=0; 4078 phi=al+zdel; phi[which(phi>1)]=1; 4079 rd=6; 4080 qlo=round(qlo,rd); q0=round(q0,rd); qhi=round(qhi,rd); 4081 plo=round(plo,rd); phi=round(phi,rd); 4082 return(matrix(c(qlo,q0,qhi,plo,al,phi),ncol=6)); 4083 } 4084 4085 glm.lims=function(dat,conf,P=numeric(0),Q=numeric(0)) 4086 { 4087 # Calculates qlo & qhi (GLM) and plo & phi (mdose.p) 4088 np=length(P); nq=length(Q); npq=np+nq; 4089 if(npq == 0 | any(P < 0 | P > 1)) return(); 4090 x=rep(dat$X,dat$COUNT); y=rep(dat$Y,dat$COUNT); gt=dat$tmu; 4091 r0=x[y==0]; r1=x[y==1]; 4092 M0=max(r0); m1=min(r1); del=m1-M0; one23=2+sign(del); 4093 4094 # overlap: one23=1 (interval); one23=2 (point); one23=3 (none); 4095 4096 xglm=glm(y ~ x, family = binomial(link = probit)); 4097 ab=as.vector(xglm$coef); 4098 muhat=-ab[1]/ab[2]; 4099 sighat=1/ab[2]; 4100 4101 chk=cpq(P,Q,muhat,sighat,gt); 4102 if(!chk) return(); 4103 al=c(P,pnorm((Q-muhat)/sighat)); 4104 q0=muhat+qnorm(al)*sighat; 4105 if(nq > 0) {iq=c(nq:1) - 1; q0[npq-iq]=Q;} 4106 yy=predict(xglm, list(x = q0), se.fit = T); 4107

Page 53:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

df=sum(dat$COUNT)-2; 4108 conf=(1+conf)/2; 4109 k=qt(conf,df); 4110 yu=yy$fit+k*yy$se.fit; 4111 yl=yy$fit-k*yy$se.fit; 4112 rd=6 4113 plo=round(pnorm(yl),rd);phi=round(pnorm(yu),rd); 4114 p0=pnorm(yy$fit); 4115 ug=mdose.p(xglm,al); 4116 ssee=ug$se; 4117 qlo=round(q0-qt(conf,xglm$df.residual)*ssee,rd); 4118 qhi=round(q0+qt(conf,xglm$df.residual)*ssee,rd); 4119 q0=round(q0,rd); 4120 return(matrix(c(qlo,q0,qhi,plo,al,phi),ncol=6)); 4121 } 4122 4123 lrq.lims=function(dat,conf1,P=numeric(0),Q=numeric(0)) 4124 { 4125 # Check if there's a ZMR, and calculate muhat, sighat, and llik 4126 # If No ZMR, muhat=mid point, sighat=.0001 4127 np=length(P); nq=length(Q); npq=np+nq; 4128 chk=mixed(dat); 4129 dif=chk$dif; muhat=chk$summ/2; sighat=0.0001; min1=chk$min1; max0=chk$max0; con=chk$con; 4130 if(npq == 0 | any(P < 0 | P > 1)) return() else al=c(P,pnorm((Q-muhat)/sighat)); 4131 conf2=pchisq(qchisq(conf1,1),2); 4132 if(dif >= 0) conf2=(conf2+3)/4; 4133 4134 if(dif < 0) 4135 { 4136 rx=rep(dat$X,dat$COUNT); ry=rep(dat$Y,dat$COUNT); 4137 xglm=glm(ry~rx,family=binomial(link=probit)); 4138 ab=as.vector(xglm$coef); 4139 muhat=-ab[1]/ab[2]; 4140 sighat=1/ab[2]; 4141 } 4142 4143 uu=llik(dat,muhat,sighat); 4144 4145 levs0=uu+log(1-conf2); levs1=levs2=uu-qnorm((1-conf1)/2)^2/2; 4146 4147 options(warn=-1); # SUPPRESSES OUT OF BOUNDS WARNINGS (AND OTHERS) 4148 4149 # Contour (cx,cy): llik=levs0 needed for Graphs 1, 2 & 3 4150 degs=180; 4151 if(dif > 0)degs=360; 4152 st=ct=cx=cy=tr=(0:360)*pi/degs; 4153 4154 x0=as.vector(muhat); 4155 y0=ru=as.vector(sighat); 4156 eps=0.000001; eps4=.0001; 4157 ibot=2; itop=361; 4158 if(dif > 0){cy[1]=cy[361]=0;cx[1]=min1;cx[361]=max0;ibot=2;itop=360;ru=1;} 4159 4160 for(i in 0:361) {st[i]=sin(tr[i]); ct[i]=cos(tr[i]);} 4161 4162 for(i in 1:181) 4163 { 4164 xl=x0; yl=y0; 4165 xu=x0+ru*ct[i]; yu=y0+ru*st[i]; 4166 while(llik(dat,xu,yu)>levs0){xl=xu; yl=yu; xu=xu+ct[i];yu=yu+st[i];} 4167 x=(xl+xu)/2; y=(yl+yu)/2; 4168 4169 lval=llik(dat,x,y); 4170 zz=abs(lval-levs0) 4171 4172 while(zz>eps) 4173 { 4174 if(lval>levs0){xl=x;yl=y;} else {xu=x;yu=y;} 4175 x=(xl+xu)/2; y=(yl+yu)/2 4176 lval=llik(dat,x,y); 4177 zz=abs(lval-levs0) 4178 } 4179 cx[i]=(xl+xu)/2;cy[i]=(yl+yu)/2; 4180 } 4181 4182 for(i in 182:360) 4183 { 4184 dm=ct[i]*y0/st[i]; i2=25; i1=i2-1; 4185 xu=x0+dm*(1-i1/i2); yu=y0*i1/i2; 4186

Page 54:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

while(llik(dat,xu,yu)>levs0){i2=i2+1; xl=xu; yl=yu; xu=x0+dm*(1-i1/i2); yu=y0*i1/i2;} 4187 4188 x=(xl+xu)/2; y=(yl+yu)/2; 4189 4190 lval=llik(dat,x,y); 4191 zz=abs(lval-levs0) 4192 4193 while(zz>eps) 4194 { 4195 if(lval>levs0){xl=x;yl=y;} else {xu=x;yu=y;} 4196 x=(xl+xu)/2; y=(yl+yu)/2 4197 lval=llik(dat,x,y); 4198 zz=abs(lval-levs0) 4199 } 4200 cx[i]=(xl+xu)/2;cy[i]=(yl+yu)/2; 4201 } 4202 cx=c(cx[1:181],cx[360:182]); 4203 cy=c(cy[1:181],cy[360:182]); 4204 cx[361]=cx[1]; cy[361]=cy[1]; 4205 4206 lrmat=matrix(rep(0,6*npq),ncol=6);lrmat[,5]=c(P,pnorm((Q-muhat)/sighat)) 4207 4208 lrmat[,2]=muhat+qnorm(lrmat[,5])*sighat; 4209 for(i in 1:npq) 4210 { 4211 lrmat[i,1]=min(cx+qnorm(lrmat[i,5])*cy,na.rm=T); 4212 lrmat[i,3]=max(cx+qnorm(lrmat[i,5])*cy,na.rm=T); 4213 lrmat[i,4]=min(pnorm((lrmat[i,2]-cx)/cy),na.rm=T); 4214 lrmat[i,6]=max(pnorm((lrmat[i,2]-cx)/cy),na.rm=T); 4215 } 4216 ret=list(cx,cy,lrmat,muhat,sighat,dif,con); 4217 names(ret)=c("cx","cy","lrmat","muhat","sighat","dif","con"); 4218 4219 return(ret); 4220 } 4221 4222 qrda = function(dat, conf=.9, J=2, ln = F, labx = "", laby = "Probability of Response", zee = 0) 4223 { 4224 c1sided=(1+conf)/2; 4225 ldot=3.; 4226 x = xsav=rep(dat$X, dat$COUNT); 4227 y = ysav=rep(dat$Y, dat$COUNT); 4228 xglm = glm(y ~ x, family = binomial(link = probit)) 4229 ab = as.vector(xglm$coef); 4230 a=ab[1] 4231 b=ab[2] 4232 mu= -a/b 4233 sig=1/b 4234 if(ln) k=2.5 else k=3.5; 4235 pm=c(-1,1); pee=pnorm(pm*k); 4236 if(!ln) a1=pretty(mu+k*sig*pm) else a1=pretty(qlnorm(pee,meanlog=mu,sdlog=sig)) 4237 if(!ln) a2 = range(c(a1,range(x))) else a2=range(c(a1,range(dat$RX))); 4238 if(ln) a2[2]=min(a2[2],1.5*max(exp(x))); 4239 xs = seq(a2[1], a2[2], length = 100.); 4240 if(ln) {if(xs[1] == 0) xs[1]=xs[2]/100; xs=log(xs);} 4241 yy = predict(xglm, list(x = xs), se.fit = T); 4242 yn = pnorm(yy$fit); 4243 ys=1:99/100; ys=c(.001,.005,ys,.995,.999); 4244 4245 if(ln) xs = exp(xs) 4246 plot(xs, yn, ylim = c(0,1), type = "n", las = 1., cex=.6, xlab = "", ylab = "",xaxt="n",yaxt="n") 4247 axis(1,at=pretty(xs),labels=T,tck=-.01,cex.axis=.9,mgp=c(3,.4,0)); 4248 axis(2,at=pretty(yn),labels=T,tck=-.01,cex.axis=.9,mgp=c(3,.4,0),las=1); 4249 mtext(expression(paste("Probability ( ",italic(p),")",sep="")),side=2,line=2.8,cex=1); 4250 if(labx == "")x123=expression(paste("Quantile (",italic(q),")",sep="")) else 4251 x123=substitute(paste("Quantile (",italic(q),", in units ",labx,")",sep=""),list(labx=labx)); 4252 mtext(x123,side=1,line=2,cex=1); 4253 rd=4; uvw=round(100*conf,rd); ax="p"; 4254 abline(h = 0.1 * c(0.:10.), lty = ldot) 4255 4256 if(!ln) {abline(v = pretty(a2), lty = ldot); dpts=dnorm(xs,mean=mu,sd=sig);} else 4257 {abline(v=pretty(range(xs)),lty=ldot); dpts=dlnorm(xs,meanlog=mu,sdlog=sig);} 4258 em=max(dpts); 4259 lines(xs,dpts/em,type="l",col=8,lwd=2); 4260 4261 pavdf(dat, ln, plotit = T, lineit = T) 4262 nxv=length(xsav); 4263 if(!ln) {for(i in 1:nxv) points(xsav[i],ysav[i]+(ysav[i]-.5)/25,pch=4,lwd=1.5,cex=.5);} else 4264 {for(i in 1:nxv) points(exp(xsav[i]),ysav[i]+(ysav[i]-.5)/25,pch=4,lwd=1.5,cex=.5);} 4265

Page 55:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

4266 cl=list(1,1,1,2,3,3,3,c(1,2),c(1,2),c(1,3),c(1,3),c(2,3),c(2,3),c(1,2,3),c(1,2,3)); 4267 qpl=list(1,2,c(1,2),c(1,2),1,2,c(1,2),1,2,1,2,1,2,1,2); 4268 4269 colo=c(4,1,2); lin=c(1,1,1); 4270 si=c(2,1,3,3,2,1,3,2,1,2,1,2,1,2,1); 4271 4272 x35=substitute(paste(uvw,"% Confidence Interval about ",italic(p),sep=""),list(uvw=uvw)); 4273 x46=substitute(paste(uvw,"% Confidence Interval about ",italic(q),sep=""),list(uvw=uvw)); 4274 4275 ct=cl[[J]]; qpt=qpl[[J]]; 4276 n1=length(ct); n2=length(qpt); 4277 LJ=vector("list",n1*n2); 4278 if(si[J] == 1 | si[J] == 3) mtext(x46,side=1,line=3.3,cex=1); 4279 if(si[J] == 2 | si[J] == 3) mtext(x35,side=2,line=1.5,cex=1); 4280 4281 ij=0; 4282 if(ln) xs=log(xs); 4283 4284 for(i in 1:n1) 4285 { 4286 for(j in 1:n2) 4287 { 4288 ij=ij+1; 4289 cti=ct[i]; qpi=qpt[j]; 4290 if(qpi == 1) yyy=lims(cti,dat,conf,Q=xs) else yyy=lims(cti,dat,conf,P=ys); 4291 if(ln) { yyy[,1:3] = exp(yyy[,1:3]); } 4292 if(ij==1) lines(yyy[,2],yyy[,5],lwd=2); 4293 LJ[[ij]]=yyy; 4294 if(qpi == 1) { lines(yyy[,2],yyy[,4],col=colo[cti]); lines(yyy[,2],yyy[,6],col=colo[cti]); } else 4295 { lines(yyy[,1],yyy[,5],col=colo[cti],lty=4); 4296 lines(yyy[,3],yyy[,5],col=colo[cti],lty=4); } 4297 } 4298 } 4299 if(ln) xs=exp(xs); 4300 dx=xs[1]+diff(range(xs))/25; 4301 leg=c("FM","LR","GLM"); pq=c("p","q"); 4302 legend(dx,.93,legend=leg[ct],lty=lin[ct],col=colo[ct],lwd=3,cex=.6,bg="white"); 4303 nlj=paste(leg[ct],pq[qpt],sep=""); 4304 names(LJ)=nlj; 4305 xx=list(xglm=xglm, a=a, b=b, mu=mu, sig=sig, J=J, LJ=LJ); 4306 reset() 4307 return(xx) 4308 } 4309 4310 prtrans=function(i) 4311 { 4312 # i is a vector of length 2 4313 dud=lev=numeric(0); 4314 for(j in 1:length(i)) 4315 { 4316 v=i[j]; 4317 if(v > 0) 4318 { 4319 nSeq=1+(v-v%%2)/2; 4320 nAdd=1-v%%2; 4321 L=udli(v) 4322 nL=bintodec(L); 4323 if(j==1) GE5=T else GE5=F 4324 if(GE5) {au="U = {"; ad="D = {";} else {au="D = {"; ad="U = {";} 4325 if(GE5) d9=unlist(lapply(L,"fofL")) else d9=unlist(lapply(lapply(L,"iofL"),"fofL")) 4326 du=paste(au,paste(d9[1:nSeq],collapse=", "),"}",sep=""); 4327 dd=paste(ad,paste(d9[(nSeq+1):(nSeq+nAdd+1)],collapse=", "),"}",sep=""); 4328 zv=zpfun(v); 4329 if(!GE5) zv=1-zv; 4330 lev=c(lev,zv); 4331 dud=c(dud,paste(du,", ",dd,", Lev = ",round(zv,6),sep="")); 4332 } 4333 } 4334 return(list(dud=dud,lev=lev)) 4335 } 4336 4337 fofL=function(L) return(paste(L,collapse="")) 4338 iofL=function(L) return(1-L) 4339 4340 bintodec = function(y) 4341 { 4342 # y is now a LIST of vectors consisting of 0's and 1's 4343 # find the decimal number corresponding to binary sequence 'y' 4344

Page 56:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

# L is not a list, L is a vector of integers 4345 ny=length(y) 4346 L=numeric(0) 4347 for(i in 1:ny) 4348 { 4349 yi=y[[i]] 4350 if (! (all(yi %in% c(0,1)))) stop("not a binary sequence") 4351 res = sum(yi*2^((length(yi):1) - 1)) 4352 L[[i]]=res 4353 } 4354 return(L) 4355 } 4356 4357 udli=function(i) 4358 { 4359 iadd=1-i%%2; 4360 n=(i+iadd+1)/2; 4361 L=vector("list",n+1) 4362 for(j in 0:(n-1))L[[j+1]]=bintodec(c(rep(1,j),0)) 4363 L[[n+1]]=bintodec(rep(1,n)) 4364 if(iadd==1) 4365 { 4366 L[[n+2]]=L[[n+1]] 4367 L[[n+1]]=c(L[[n]],1) 4368 L[[n]]=c(L[[n]],0) 4369 } 4370 return(L) 4371 } 4372 4373 pfun=function(pee,n) 4374 { 4375 # pfun(0) < 0, pfun(1) > 0 4376 return(4*pee^n-2*pee^(n+1)-1) 4377 } 4378 4379 4380 zpfun=function(i) 4381 { 4382 em=numeric(0); 4383 for(j in 1:length(i)) 4384 { 4385 if(i[j]%%2 == 1) mm=.5^(2/(i[j]+1)) else 4386 { 4387 eps=.000001; 4388 ll=0 4389 ul=1 4390 w=10; 4391 m=1/2; 4392 while(abs(w) > eps) 4393 { 4394 w=pfun(m,1+i[j]/2); 4395 if(w < 0) ll=m else ul=m; 4396 m=(ll+ul)/2; 4397 } 4398 mm=m 4399 } 4400 em=c(em,mm); 4401 } 4402 return(em); 4403 } 4404 4405 xlead0=function(num,dig) 4406 { 4407 n=round(num,dig) 4408 nc=as.character(n); 4409 wh=which(abs(n) < 1); 4410 nw=n[wh]; 4411 nwc=gsub("0.",".",nw,fixed=T) 4412 nc[wh]=nwc; 4413 return(nc) 4414 } 4415 4416 # INDEX 97 through 108, XjlrcbS3.R (12 functions) 4417 4418 xyllik = function(rx,ry,m,s) 4419 { 4420 kx=rx-m; 4421 ns=length(s); 4422 ll=numeric(0); 4423

Page 57:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

for(i in 1:ns) 4424 { 4425 pms=(2*ry-1)*s; 4426 ll=c(ll,sum(log(pnorm(kx/pms)))); 4427 } 4428 return(ll); 4429 } 4430 4431 stopQuietly = function(...) 4432 { 4433 blankMsg = sprintf("\r%s\r", paste(rep(" ", getOption("width")-1L), collapse=" ")); 4434 stop(simpleError(blankMsg)); 4435 } 4436 4437 # reset is used in this suite of functions; it's defined just once in gonogo.R 4438 4439 calcblim=function(bl,ul) 4440 { 4441 # Calculate limits on plot 1 based on just bounded (or combined) regions 4442 mlim=slim=numeric(0); 4443 num=length(bl); 4444 if(length(bl[[1]][[1]]) != 1) 4445 { 4446 for(k in 1:num){ 4447 bk=bl[[k]]; mlim=range(c(mlim,bk[[1]])); slim=range(c(slim,bk[[2]])); 4448 } 4449 } 4450 num=length(ul); 4451 if(length(ul[[1]][[1]]) != 1){ 4452 for(k in 1:num){ 4453 bk=ul[[k]]; mlim=range(c(mlim,bk[[1]],bk[[3]])); slim=range(c(slim,bk[[2]],bk[[4]])); 4454 } 4455 } 4456 a=list(mlim,slim); 4457 names(a)=c("mlim","slim"); 4458 return(a) 4459 } 4460 4461 mkb0=function(confv) 4462 { 4463 # adapted from llik1.R 4464 ncl=length(confv); 4465 b0=round(confv,3); 4466 b0=paste(b0,collapse=",") 4467 b0=gsub(",0.",",.",b0,fixed=T); 4468 b0=gsub("0.",".",b0,fixed=T); 4469 w1=w2=""; 4470 if(ncl > 1) {w1="("; w2=")";} 4471 b0=substitute(paste(w1,b0,w2,sep="")); 4472 return(b0) 4473 } 4474 4475 unbd=function(rx,ry,levs,mh1,mh2,es,mlim) 4476 { 4477 mh=(mh1+mh2)/2; 4478 if(length(mlim) == 2){L=mlim[1]; U=mlim[2];} else 4479 { 4480 pm=c(-1,1); I=c(mh1,mh2)+0.5*mh*pm; L=I[1]; U=I[2]; 4481 } 4482 if(es > 0) S0=ST1=ulik(rx,ry,levs,mh1,es) else S0=ST1=0; 4483 num=51; 4484 J1=seq(mh1,L,length=num); 4485 for(i in 2:num) 4486 { 4487 S1=uliknext(rx,ry,levs,J1[i-1],S0,J1[i]); 4488 ST1=c(S1,ST1); 4489 S0=S1; 4490 } 4491 if(es > 0) S0=ST2=ulik(rx,ry,levs,mh2,es) else S0=ST2=0; 4492 J2=seq(mh2,U,length=num); 4493 for(i in 2:num) 4494 { 4495 S1=uliknext(rx,ry,levs,J2[i-1],S0,J2[i]); 4496 ST2=c(ST2,S1); 4497 S0=S1; 4498 } 4499 mt1=J1[num:1]; mt2=J2; 4500 return(list(mt1,ST1,mt2,ST2)); 4501 } 4502

Page 58:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

4503 uliknext=function(rx,ry,levs0,em1,es,em2) 4504 { 4505 if(es == 0) es=.1; 4506 shi=es; slo=es/2; 4507 val1=rem1=xyllik(rx,ry,em2,slo); 4508 val2=rem2=xyllik(rx,ry,em2,shi); 4509 4510 # val may at first decrease (good) but then increase (bad) 4511 while(val1 > levs0) 4512 { 4513 shi=slo; slo=slo/2; val1=xyllik(rx,ry,em2,slo); 4514 if(val1 > rem1) 4515 { 4516 cat(paste("Message from uliknext: conf1 is LARGER & TOO NEAR c1max.\n",sep="")) 4517 cat(paste("The specific problem is: for m = ",round(em2,4),", val1(s) > levs0 for all s.\n",sep="")); 4518 cat(paste("Increasing conf1 can produce a more clearly defined UNBOUNDED region.\n",sep="")); 4519 stopQuietly(); 4520 } else rem1=val1; 4521 } 4522 4523 # val2 may at first increase (good) but then decrease (bad) 4524 while(val2 < levs0) 4525 { 4526 slo=shi; shi=2*shi; val2=xyllik(rx,ry,em2,shi); 4527 if(val2 < rem2) 4528 { 4529 cat(paste("Message from uliknext: conf1 is LARGER & TOO NEAR c1max.\n",sep="")) 4530 cat(paste("The specific problem is: for m = ",round(em2,4),", val2(s) < levs0 for all s.\n",sep="")); 4531 cat(paste("Increasing conf1 can produce a more clearly defined UNBOUNDED region.\n",sep="")); 4532 stopQuietly(); 4533 } else rem2=val2; 4534 } 4535 4536 eps=.0001; delt=1; 4537 while(delt > eps) 4538 { 4539 s=(slo+shi)/2; 4540 val=xyllik(rx,ry,em2,s); 4541 if(val > levs0) shi=s else slo=s; 4542 delt=abs(val-levs0); 4543 } 4544 s=(slo+shi)/2; 4545 return(s); 4546 } 4547 4548 ulik=function(rx,ry,levs0,em,es) 4549 { 4550 shi=es; slo=es/2; val1=val2=xyllik(rx,ry,em,slo); 4551 while(val1 > levs0) {shi=slo; slo=slo/2; val1=xyllik(rx,ry,em,slo);} 4552 while(val2 < levs0) {slo=shi; shi=2*shi; val2=xyllik(rx,ry,em,shi);} 4553 eps=.00001; delt=1; 4554 while(delt > eps) 4555 { 4556 s=(slo+shi)/2; 4557 val=xyllik(rx,ry,em,s); 4558 if(val > levs0) shi=s else slo=s; 4559 delt=abs(val-levs0); 4560 } 4561 s=(slo+shi)/2; 4562 return(s); 4563 } 4564 4565 otherpoint=function(rx,ry,muhat,levs0,con) 4566 { 4567 k=1.5; slo=Inf; shi=-Inf; 4568 s=1; 4569 while(slo > shi) 4570 { 4571 m=muhat-qnorm(con)*s; 4572 val=xyllik(rx,ry,m,s); 4573 if(val > levs0) {slo=s; s=k*s;} else {shi=s; s=s/k;} 4574 } 4575 eps=.00001; 4576 delt=1; 4577 while(delt > eps) 4578 { 4579 s=(slo+shi)/2; 4580 m=muhat-qnorm(con)*s; 4581

Page 59:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

val=xyllik(rx,ry,m,s); 4582 if(val > levs0) slo=s else shi=s; 4583 delt=abs(val-levs0); 4584 } 4585 s=(slo+shi)/2; 4586 m=muhat-qnorm(con)*s; 4587 return(c(m,s)); 4588 } 4589 4590 jlik=function(rx,ry,levs0,ms,op,one23) 4591 { 4592 # Contour (cx,cy): llik=levs0 needed for Graphs 1, 2 & 3 4593 4594 ndeg=361; ang=0; h=1; 4595 if(one23 == 2) {d=op-ms; d7=(op+ms)/2; ang=atan(d[1]/d[2])+pi/2;} 4596 if(one23 == 3) h=2; 4597 cx=cy=tr=2*(0:(ndeg-1))*pi/(h*(ndeg-1))-ang; 4598 4599 rl=0; 4600 if(one23 == 1) 4601 { 4602 ibot=1; itop=ndeg; 4603 x0=as.vector(ms[1]); y0=ru=as.vector(ms[2]); 4604 } 4605 if(one23 == 2) 4606 { 4607 ibot=2; itop=ndeg-1; 4608 x0=as.vector(d7[1]); y0=ru=as.vector(d7[2]); 4609 cx[1]=cx[ndeg]=ms[1]; 4610 cy[1]=cy[ndeg]=ms[2]; 4611 } 4612 if(one23 == 3) 4613 { 4614 ibot=2; itop=ndeg-1; 4615 x0=ms[1]; y0=0; ru=1; 4616 cx[1]=op[1]; cx[ndeg]=op[2]; 4617 cy[1]=cy[ndeg]=0; 4618 } 4619 4620 eps=0.000001; 4621 4622 for(i in ibot:itop) 4623 { 4624 st=sin(tr[i]); 4625 ct=cos(tr[i]); 4626 4627 xl=x0+rl*ct; 4628 yl=y0+rl*ct; 4629 4630 xu=x0+ru*ct; yu=y0+ru*st; 4631 while(xyllik(rx,ry,xu,yu)>levs0){xu=xu+ct;yu=yu+st;} 4632 x=(xl+xu)/2; y=(yl+yu)/2; 4633 lval=xyllik(rx,ry,x,y); 4634 zz=abs(lval-levs0) 4635 4636 while(zz>eps) 4637 { 4638 if(lval>levs0){xl=x;yl=y;} else {xu=x;yu=y;} 4639 x=(xl+xu)/2; y=(yl+yu)/2 4640 lval=xyllik(rx,ry,x,y); 4641 zz=abs(lval-levs0) 4642 } 4643 cx[i]=(xl+xu)/2;cy[i]=(yl+yu)/2; 4644 } 4645 return(list(cx,cy)) 4646 } 4647 4648 jlrcb=function(dat,notitle=F) 4649 { 4650 # c2max = function of uu(muhat,sighat,rx,ry) and llc(con(rx,ry)) 4651 # AN IDENTITY: levs = uu+log(1-conf2) = 1-qchisq(conf1,1)/(2*uu); 4652 4653 dt=dat$d0; titl1=dat$title; test=dat$test; about=dat$about; 4654 ttl0=dat$ttl0; ttl1=dat$ttl1; ttl2=dat$ttl2; tmu=dat$tmu; 4655 tnam=c("3pod","Neyer"); 4656 4657 xx="Enter conf1's (separated by blanks): "; 4658 xx=readline(xx); cat("\n"); 4659 xx=as.numeric(unlist(strsplit(xx," "))); 4660

Page 60:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

vconf1=sort(unique(xx)); 4661 vconf2=pchisq(qchisq(vconf1,1),2); 4662 nc1=length(vconf1); 4663 rx=dt$X; ry=dt$Y; nc=dt$COUNT; 4664 rx=rep(rx,nc); ry=rep(ry,nc); 4665 nt=sum(nc); 4666 con=sum(ry)/length(ry); 4667 llc=sum(log(con^ry*(1-con)^(1-ry))); 4668 4669 r0=rx[ry==0]; r1=rx[ry==1]; 4670 mix=length(r0)*length(r1); 4671 lux=length(unique(rx)); 4672 if(mix == 0 | lux == 1) 4673 { 4674 cat(paste("Need to do more testing\n",sep="")); 4675 stopQuietly(); 4676 } 4677 M0=max(r0); m1=min(r1); del=m1-M0; one23=2+sign(del); 4678 4679 bl=ul=list(1) # placeholder for bounded & unbounded lists 4680 numb=numu=0; # eventual number of bounded & unbounded plots 4681 mlim=0; # default value to pass into unbd (if all are unbounded) 4682 icbl=T; 4683 for(i in 1:nc1) 4684 { 4685 conf2=pchisq(qchisq(vconf1[i],1),2); 4686 4687 switch(one23, 4688 { # OVERLAP (Interval) (use log lik) 4689 4690 xglm=glm(ry~rx,family=binomial(link=probit)); 4691 ab=as.vector(xglm$coef); 4692 muhat=-ab[1]/ab[2]; sighat=1/ab[2]; 4693 uu=xyllik(rx,ry,muhat,sighat); 4694 levs=uu+log(1-conf2); 4695 c2max=pchisq(2*(uu-llc),2); 4696 bnd=T; if(conf2 > c2max) bnd=F; 4697 if(bnd) 4698 { 4699 ms=op=c(muhat,sighat); numb=numb+1; 4700 bl[[numb]]=jlik(rx,ry,levs,ms,op,one23); 4701 } else { 4702 if(icbl & numb > 0) {cbl=calcblim(bl,ul); mlim=cbl$mlim; icbl=F;} 4703 numu=numu+1; 4704 ul[[numu]]=unbd(rx,ry,levs,muhat,muhat,sighat,mlim);} 4705 }, 4706 { # OVERLAP (Point) (use lik) 4707 4708 muhat=(m1+M0)/2; sighat=0; 4709 mx=ry[rx == m1]; s1=sum(mx); s2=length(mx)-s1; 4710 uu=s1*log(s1) + s2*log(s2) - (s1+s2)*log(s1+s2); 4711 levs=uu+log(1-conf2); 4712 c2max=pchisq(2*(uu-llc),2); 4713 bnd=T; if(conf2 > c2max) bnd=F; 4714 if(bnd){ 4715 op=otherpoint(rx,ry,muhat,levs,con); 4716 ms=c(muhat,sighat); numb=numb+1; 4717 bl[[numb]]=jlik(rx,ry,levs,ms,op,one23); 4718 } else { 4719 if(icbl & numb > 0) {cbl=calcblim(bl,ul); mlim=cbl$mlim; icbl=F;} 4720 numu=numu+1; 4721 ul[[numu]]=unbd(rx,ry,levs,muhat,muhat,sighat,mlim);} 4722 }, 4723 { # NO OVERLAP (use lik) 4724 4725 muhat=(m1+M0)/2; sighat=0; 4726 uu=0; 4727 4728 ig=2; 4729 if(ig == 1) {conf2=(3+conf2)/4; levs=log(1-conf2);} else 4730 {c3=(3+conf2)/4; levs=log(1-c3);} 4731 4732 c2max=pchisq(2*(uu-llc),2); 4733 c2max=1-4*exp(llc); 4734 bnd=T; if(conf2 > c2max) bnd=F; 4735 if(bnd){ 4736 op=c(m1,M0); 4737 ms=c(muhat,sighat); numb=numb+1; 4738 bl[[numb]]=jlik(rx,ry,levs,ms,op,one23); 4739

Page 61:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

} else { 4740 if(icbl & numb > 0) {cbl=calcblim(bl,ul); mlim=cbl$mlim; icbl=F;} 4741 numu=numu+1; 4742 ul[[numu]]=unbd(rx,ry,levs,M0,m1,sighat,mlim);} 4743 } 4744 ); 4745 4746 } 4747 c1max=pchisq(qchisq(c2max,2),1); 4748 4749 cbl=calcblim(bl,ul); 4750 g=list(bl,ul,cbl); 4751 b=g[[1]]; u=g[[2]]; mlim=g[[3]]$mlim; slim=g[[3]]$slim; 4752 plot(1,1,type="n",xlim=mlim,ylim=slim,xlab="mean (m)",ylab="standard deviation (s)"); 4753 4754 abc=" (JLRCB)"; lin=2.7; 4755 if(is.null(dat$tmu)) {abc=" Joint LR CB's"; lin=2.9;} 4756 rc1=round(c1max,5); rc1=as.character(rc1); rc1=gsub("0.",".",rc1,fixed=T); 4757 rc2=round(c2max,5); rc2=as.character(rc2); rc2=gsub("0.",".",rc2,fixed=T); 4758 rc=rc1; irc=1; if(c1max > .99999) {rc=rc2; irc=2;} 4759 titl1=substitute(paste(ttl0," (c1max =",rc1,")",abc,sep="")); 4760 titl1=substitute(paste(ttl0," (max(",c[1]," = ",rc1,"): ",abc,sep="")); 4761 titl1=substitute(paste(ttl0," ",abc,sep="")) 4762 4763 if(!notitle) 4764 { 4765 mtext(titl1,side=3,line=lin,cex=1); 4766 if(test > 2){ 4767 mtext(ttl1,side=3,line=1.5,cex=1.1,adj=0); 4768 mtext(ttl2,side=3,line=.2,cex=1.1,adj=0); 4769 } else mtext(tnam[test],side=3,line=.3,cex=1.1,adj=0); 4770 } 4771 4772 pxl=pretty(mlim); pyl=pretty(slim); ilt=3; 4773 abline(v=pxl,lty=ilt); abline(h=pyl,lty=ilt); 4774 m0=-1/qnorm(con); 4775 if(con == .5) abline(v=muhat,col=1,lty=2) else 4776 abline(sighat-m0*muhat,m0,col=1,lty=2); 4777 points(muhat,sighat,pch=16,cex=.7,col=2); 4778 if(numb > 0) {for(k in 1:numb){bk=b[[k]]; 4779 lines(bk[[1]],bk[[2]],type="l");}} 4780 if(numu > 0) {for(k in 1:numu){ uk=u[[k]]; 4781 lines(uk[[1]],uk[[2]],type="l",col=2); 4782 lines(uk[[3]],uk[[4]],type="l",col=2);}} 4783 print(vconf1) 4784 b0=mkb0(vconf1); 4785 b0=substitute(paste(c[1]," = ",x,", ",c["1max"]," = ",y,sep=""),list(x=b0,y=rc1)); 4786 dj=1; if(test == 1 | test == 2 | test == 5) dj=.5; 4787 if(!notitle) 4788 { 4789 mtext(b0,side=3,line=1.5,cex=1,adj=dj); 4790 mtext(about,side=3,line=.4,cex=1,adj=1); 4791 } 4792 return(g); 4793 } 4794 4795 picdat=function(dat) 4796 { 4797 titl=dat$title; dat=dat$d0; 4798 # put dat$d0 into simplified form (n may not be all 1's) 4799 dat=simp(dat); 4800 xx=dat$X; yy=dat$Y; n=dat$COUNT; 4801 4802 l0=l1=numeric(0); 4803 if(any(yy==1)){m1=min(xx[yy==1]);l1=1;} 4804 if(any(yy==0)){M0=max(xx[yy==0]);l0=1;} 4805 4806 del=.025; xr=range(xx); pm=c(-1,1); xl=xr+diff(xr)*pm/100; 4807 del=.03; 4808 yl=c(0,1); 4809 par(mar=c(0,0,0,0),pin=c(2.4,1.6)); 4810 plot(xx,yy,type="n",axes=F,ylim=yl,xlim=xr,xlab="",ylab="") 4811 lines(c(xl[1],xl[2]),c(0,0),lty=3); lines(c(xl[1],xl[2]),c(1,1),lty=3); 4812 cx=.6; 4813 points(xx,yy,pch=16,cex=cx) 4814 points(m1,1,pch=16,col=2,cex=cx); points(M0,0,pch=16,col=2,cex=cx); 4815 4816 for(i in 1:length(xx)) 4817 { 4818

Page 62:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

for(j in 1:n[i]) points(xx[i],yy[i]-sign(yy[i]-.5)*(j-1)*del,pch=16,cex=cx) 4819 } 4820 if(l0*l1 > 0 & m1 <= M0){lines(c(m1,m1),c(0,1),lty=3); lines(c(M0,M0),c(0,1),lty=3);} 4821 reset(); 4822 return(); 4823 } 4824 4825 simp=function(dat) 4826 { 4827 xx=dat$X; yy=dat$Y; n=dat$COUNT; 4828 xx=rep(xx,n); yy=rep(yy,n); 4829 sux=sort(unique(xx)); lsx=length(sux); 4830 xxx=yyy=nnn=numeric(0); 4831 for(i in 1:lsx) 4832 { 4833 i1=sum(yy[xx==sux[i]]); if(i1 > 0){xxx=c(xxx,sux[i]); yyy=c(yyy,1); nnn=c(nnn,i1);} 4834 i0=sum(1-yy[xx==sux[i]]); if(i0 > 0){xxx=c(xxx,sux[i]); yyy=c(yyy,0); nnn=c(nnn,i0);} 4835 } 4836 dat=matrix(c(xxx,yyy,nnn),ncol=3); 4837 dat=data.frame(dat); 4838 names(dat)=c("X","Y","COUNT"); 4839 4840 return(dat) 4841 } 4842 4843 #INDEX 109 through 113, Xlrcb1.R (5 functions) 4844 4845 grafl=function(limx) 4846 { 4847 lw=3; 4848 titl="Liklihood Ratio CL's" 4849 qtic=pretty(limx); qtr=range(qtic); 4850 pr=c(1,10,100,1000,5000,9000,9900,9990,9999)/10000; q=qnorm(pr); 4851 xl=range(limx); yl=c(-3.8,3.8); 4852 plot(xl,yl,type="n",xlim=xl,ylim=yl,xaxt="n",yaxt="n",xlab="",ylab="",cex=.8); 4853 xl1=expression(paste("quantile (",italic(q),")",sep="")); 4854 yl1=expression(paste("Probability of Response (",italic(p),")",sep="")); 4855 mtext(xl1,side=1,line=1.4,cex=.9); mtext(yl1,side=2,line=2.3,cex=.8); 4856 mtext(titl,side=3,line=.6,cex=.8); 4857 isiz1=.7; 4858 axis(1,at=qtic,labels=T,tck=.01,cex=isiz1,mgp=c(3,.2,0)); 4859 axis(2,at=q,labels=paste(100*pr," ",sep=""),tck=.01,cex.axis=.8,mgp=c(3,0,0),las=2); 4860 axis(3,at=qtic,labels=F,tck=.01,cex=isiz1); 4861 # Horizontal Grid Lines 4862 delx=.75; delx=0; 4863 ilt=3 4864 for(i in 1:length(pr)) lines(qtr,c(q[i],q[i]),lty=ilt); 4865 # Verticle Grid Lines 4866 abline(v=qtic,lty=ilt); 4867 del1=diff(range(limx))/20; 4868 return() 4869 } 4870 4871 clim0=function(rx,ry,m,s,levb) 4872 { 4873 done=0; 4874 sigmax=0; 4875 len=50; 4876 k=5; 4877 xll=c(-1,1)*k; 4878 m1=min(rx[ry==1]);M0=max(rx[ry==0]); 4879 yll=k*(m1-M0); 4880 if(yll == 0) yll=1; 4881 4882 z0=matrix(rep(0,len^2),ncol=len); 4883 4884 while(done == 0) 4885 { 4886 xl=m+xll*s; 4887 yl=c(sigmax,yll*s); 4888 x0=seq(xl[1],xl[2],length=len); y0=seq(yl[1],yl[2],length=len); 4889 for(i in 1:len)for(j in 1:len) z0[i,j]=xyllik(rx,ry,x0[i],y0[j]); 4890 z0=exp(z0); 4891 cl=contourLines(x0,y0,z0,levels=levb); 4892 ncl=length(cl); 4893 iplot=0; 4894 if(ncl > 0) 4895 { 4896 rxcl=rycl=numeric(0); 4897

Page 63:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

for(i in 1:ncl) {rxcl=range(c(rxcl,cl[[i]]$x));rycl=range(c(rycl,cl[[i]]$y));} 4898 if(iplot == 1) 4899 { 4900 plot(rxcl,rycl,type="n") 4901 for(i in 1:ncl) points(cl[[i]]$x,cl[[i]]$y,type="l"); 4902 } 4903 } 4904 4905 if(ncl == 0 | ncl == 4) 4906 { 4907 done=0; 4908 xll=1.5*xll; 4909 yll=1.5*yll; 4910 } 4911 4912 if(ncl == 1) 4913 { 4914 done=1; 4915 x=cl[[1]]$x; y=cl[[1]]$y; en=length(x); 4916 if(y[1] != y[en] & x[1] == xl[1]) {xll[1]=1.5*xll[1]; done=0;} 4917 if(y[1] != y[en] & x[1] == xl[2]) {xll[2]=1.5*xll[2]; done=0;} 4918 } 4919 4920 if(ncl == 2) 4921 { 4922 done=0; 4923 if(rxcl[1] == xl[1]) xll[1]=1.5*xll[1]; 4924 if(rxcl[2] == xl[2]) xll[2]=1.5*xll[2]; 4925 if(rycl[2] == yl[2]) yll=1.5*yll; 4926 } 4927 4928 if(ncl == 3) 4929 { 4930 done=0; 4931 yll=1.5*yll; 4932 if(rxcl[1] == xl[1]) xll[1]=1.5*xll[1]; 4933 if(rxcl[2] == xl[2]) xll[2]=1.5*xll[2]; 4934 } 4935 } 4936 return(c(xl,yl)) 4937 } 4938 4939 clim=function(rx,ry,m,s,uu,levb) 4940 { 4941 done=0; 4942 sigmax=.001; 4943 xll=c(-5,5); yll=10; 4944 len=50; 4945 z0=matrix(rep(0,len^2),ncol=len); 4946 4947 while(done == 0) 4948 { 4949 xl=m+xll*s; yl=c(sigmax,yll*s); 4950 x0=seq(xl[1],xl[2],length=len); y0=seq(yl[1],yl[2],length=len); 4951 for(i in 1:len)for(j in 1:len) z0[i,j]=xyllik(rx,ry,x0[i],y0[j])/uu; 4952 cl=contourLines(x0,y0,z0,levels=levb); 4953 ncl=length(cl); 4954 if(ncl > 0) 4955 { 4956 nxl=nyl=numeric(0); 4957 for(i in 1:ncl){g=cl[[i]];nxl=range(c(nxl,g$x));nyl=range(c(nyl,g$y));} 4958 done=1; 4959 if(nxl[1] == x0[1]) {xll[1]=1.5*xll[1]; done=0;} 4960 if(nxl[2] == x0[len]) {xll[2]=1.5*xll[2]; done=0;} 4961 if(nyl[1] == y0[1]) {sigmax=sigmax/1.5; done=0;} 4962 if(nyl[2] == y0[len]) {yll=1.5*yll; done=0;} 4963 } else 4964 { 4965 done=0; 4966 xll=1.5*xll; 4967 yll=yll*1.5; 4968 sigmax=sigmax/1.5; 4969 } 4970 } 4971 return(c(nxl,nyl)) 4972 } 4973 4974 abllik=function(data,mu,sig) 4975 { 4976

Page 64:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

x=data$X;y=data$Y;n=data$COUNT; 4977 x=rep(x,n); y=rep(y,n); 4978 i1=which(y==1); 4979 ll=log(n[i1]*pnorm((x[i1]-mu)/sig)); 4980 ll=c(ll,log(n[-i1]*pnorm((mu-x[-i1])/sig))); 4981 return(sum(ll)); 4982 } 4983 4984 lrcb=function(dat,notitle=F) 4985 { 4986 ncl=nclu=0; 4987 4988 # Compute muhat & sighat if there's overlap 4989 tit1=dat$title; dat=dat$d0; 4990 test=dat$test; ttl0=dat$ttl0; ttl1=dat$ttl1; ttl2=dat$ttl2; 4991 tnam=c("3pod","Neyer"); 4992 rx=rep(dat$X,dat$COUNT); ry=rep(dat$Y,dat$COUNT); ny=length(ry); 4993 m1=min(rx[ry==1]);M0=max(rx[ry==0]); delq=m1-M0; 4994 one23=2+sign(delq); 4995 4996 xx="Enter conf1's (separated by blanks): "; 4997 xx=readline(xx); cat("\n"); 4998 xx=as.numeric(unlist(strsplit(xx," "))); 4999 conf1=sort(unique(xx)); 5000 conf2=pchisq(qchisq(conf1,1),2); 5001 if(any(conf1 <= 0) | any(conf1 >= 1)) {cat("All conf1's must be between 0 & 1\n"); return();} 5002 5003 if(one23 ==1) 5004 { 5005 xx="Enter p and q (one must be 0): "; 5006 xx=readline(xx); cat("\n"); 5007 xx=as.numeric(unlist(strsplit(xx," "))); 5008 } else 5009 { 5010 xx="Enter p: "; 5011 xx=readline(xx); cat("\n"); 5012 xx=as.numeric(unlist(strsplit(xx," "))); 5013 if(xx[1] <= 0 | xx[1] >= 1) {cat("p must be between 0 and 1, try again\n\n");return();} 5014 } 5015 5016 # Prepare (len) X (len) Grids (z's) for Response Surface 5017 len=401; 5018 z0=matrix(rep(0,len*len),ncol=len); 5019 siglow=.001; 5020 meth=1; 5021 5022 # Compute muhat & sighat if there's overlap 5023 5024 rx=rep(dat$X,dat$COUNT); ry=rep(dat$Y,dat$COUNT); ny=length(ry); 5025 m1=min(rx[ry==1]);M0=max(rx[ry==0]); delq=m1-M0; 5026 one23=2+sign(delq); 5027 5028 if(m1 == M0 & ny == 2){cat("More data is needed to compute valid confidence regions\n\n");return();} 5029 if(m1 <= M0)overlap=T else overlap=F; 5030 sigmin=.001; 5031 if(overlap) 5032 { 5033 if(m1 < M0) 5034 { 5035 xglm=glm(ry~rx,family=binomial(link=probit)); 5036 ab=xglm$coef; 5037 sighat=1/ab[2]; 5038 muhat=-ab[1]*sighat; 5039 uu=xyllik(rx,ry,muhat,sighat) 5040 } else 5041 { 5042 muhat=m1; sighat=sigmin; mx=ry[rx == m1]; s1=sum(mx); l1=length(mx); 5043 uu=s1*log(s1)+(l1-s1)*log(l1-s1)-l1*log(l1); 5044 } 5045 } else 5046 { 5047 denom=2; 5048 muhat=(m1+M0)/2; sighat=(m1-M0)/denom; 5049 nconf2=(3+pchisq(qchisq(conf1,1),2))/4; 5050 uu=1; 5051 } 5052 5053 #(qq,pp) is a point on MLE RESPONSE CURVE 5054 if(xx[1] > 0 & xx[1] < 1) {pp=xx[1]; qq=muhat+qnorm(pp)*sighat;} 5055

Page 65:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(one23 == 2) qq=muhat; 5056 if(xx[1] == 0 & one23 == 1) {qq=xx[2]; pp=pnorm((qq-muhat)/sighat);} 5057 5058 nobo=F; pcl=T; 5059 # Rough calculation of limits 5060 if(overlap) 5061 { 5062 levs=1-qchisq(conf1,1)/(2*uu); 5063 con=sum(ry)/length(ry); 5064 llc=sum(log(con^ry*(1-con)^(1-ry))); 5065 c1max=pchisq(2*(uu-llc),1); 5066 bcon1=conf1[conf1 < c1max]; 5067 ucon1=conf1[conf1 >= c1max]; 5068 nu1=length(ucon1); 5069 endpr=paste("Overlap: All conf1's are > c1max (",round(c1max,5),")\n\n",sep=""); 5070 # Address all unbounded contours 5071 if(length(bcon1) == 0) 5072 { 5073 cat(endpr); 5074 nobo=T; 5075 } 5076 if(!nobo) bconm=max(bcon1,na.rm=T) else bconm=c1max/2;; 5077 levm=1-qchisq(bconm,1)/(2*uu); 5078 a=clim(rx,ry,muhat,sighat,uu,levm); 5079 } else 5080 { 5081 uu=1; 5082 levs=(1-conf2)/4; 5083 con=sum(ry)/length(ry); 5084 lc=prod(con^ry*(1-con)^(1-ry)); 5085 c2max=1-4*lc; 5086 c1max=pchisq(qchisq(c2max,2),1); 5087 bcon2=conf2[conf2 < c2max]; 5088 ucon2=conf2[conf2 >= c2max]; 5089 nu1=length(ucon2); 5090 endpr=paste("No Overlap: All conf1's are > c1max (",round(c1max,5),")\n\n",sep=""); 5091 # Address all unbounded contours 5092 if(length(bcon2) == 0) 5093 { 5094 cat(endpr); 5095 nobo=T; pcl=F; 5096 } 5097 if(!nobo) bconm=max(bcon2,na.rm=T) else bconm=c2max/2; 5098 levm=(1-bconm)/4; 5099 a=clim0(rx,ry,muhat,sighat,levm); 5100 } 5101 5102 # Expand limits a tad 5103 sigmax=0; 5104 a1=c(floor(a[1]), ceiling(a[2]), min(sigmax, .1*a[3]), ceiling(a[4]))+c(-1,1,0,1); 5105 x0=seq(a1[1],a1[2],length=len); y0=seq(a1[3],a1[4],length=len); 5106 if(meth == 1){for(i in 1:len)for(j in 1:len) z0[i,j]=xyllik(rx,ry,x0[i],y0[j])/uu;} 5107 if(meth==2){for(i in 1:len)for(j in 1:len) z0[i,j]=uu-xyllik(rx,ry,x0[i],y0[j]);} 5108 if(!overlap)z0=exp(z0); 5109 5110 # Neyer CL's provided on his (Mu,Sig) contour plot 5111 # Levels of z0 relate to conf by: -2 * log( exp(xyllik)/exp(uu) ) >= qchisq(conf,2) 5112 # levs=1-qchisq(conf2,2)/(2*uu); cl=contourLines(x0,y0,z0,levels=levs); 5113 5114 if(!nobo) {if(overlap)levb=1-qchisq(bcon1,1)/(2*uu) else levb=(1-bcon2)/4;} 5115 if(nobo) {if(overlap)levb=1-qchisq(bconm,1)/(2*uu) else levb=(1-bconm)/4;} 5116 5117 cl=contourLines(x0,y0,z0,levels=levb); ncl=length(cl); 5118 5119 nxl=nyl=numeric(0); 5120 5121 if(!nobo) {for(i in 1:ncl){g=cl[[i]];nxl=range(c(nxl,g$x));nyl=range(c(nyl,g$y));}} 5122 5123 if(nu1 > 0) 5124 { 5125 if(overlap) levu=1-qchisq(ucon1,1)/(2*uu) else levu=(1-ucon2)/4 5126 clu=contourLines(x0,y0,z0,levels=levu); 5127 nclu=length(clu); 5128 if(nclu > 0)for(i in 1:nclu){g=clu[[i]];nxl=range(c(nxl,g$x));nyl=range(c(nyl,g$y));} 5129 } 5130 5131 nco=length(conf1); 5132 #----------------------------------------------------------------------------- 5133 # Limits for plot 5134

Page 66:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

xl=yl=numeric(0); 5135 if(!nobo)for(i in 1:ncl){g=cl[[i]];xl=range(c(xl,g$x));yl=range(c(yl,g$y));} 5136 5137 if(nclu > 0) {for(i in 1:nclu){g=clu[[i]]; 5138 xl=range(c(xl,g$x)); 5139 yl=range(c(yl,g$y)); 5140 }} 5141 5142 if(!pcl & nclu > 0) 5143 { 5144 xl=yl=numeric(0); 5145 for(i in 1:nclu){g=clu[[i]];xl=range(c(xl,g$x));yl=range(c(yl,g$y));} 5146 } 5147 5148 xll=c(floor(xl[1]),ceiling(xl[2])); 5149 yll=c(floor(yl[1]),ceiling(yl[2])); 5150 pxl=pretty(xl); pyl=pretty(yl); 5151 5152 par(mfrow = c(2, 2), oma = c(0,.4,2,0), mar = c(3,3,2,1)); 5153 #----------------------------------------------------------------------------- 5154 ex=cl[[1]]$x; ey=cl[[1]]$y; 5155 5156 dtp="l"; if(nobo) dtp="n"; 5157 plot(ex,ey,type=dtp,xlim=xl[1:2],ylim=yl[1:2],xlab="",ylab="",xaxt="n",yaxt="n"); 5158 ilt=3; abline(v=pxl,lty=ilt); abline(h=pyl,lty=ilt); 5159 points(muhat,sighat,pch=16,cex=.7,col=2); 5160 if(nu1 > 0) 5161 { 5162 for(i in 1:length(clu)){exx=clu[[i]]$x; eyy=clu[[i]]$y; points(exx,eyy,type="l",col=2);} 5163 } 5164 5165 axis(1,at=pxl,labels=T,tck=.01,cex=.8,mgp=c(3,.2,0)); 5166 axis(2,at=pyl,labels=T,tck=.01,mgp=c(3,.2,0),las=2); 5167 mtext("mean (m)",side=1,line=1.3,cex=.9); 5168 mtext("standard deviation (s)",side=2,line=2.5,cex=.9); 5169 5170 if(ncl > 1 & !nobo)for(i in 1:ncl){ex=cl[[i]]$x; ey=cl[[i]]$y; points(ex,ey,type="l");} 5171 5172 b0=mkb0(conf2); 5173 mtext(substitute(paste(c[2],"=",x,sep=""),list(x=b0)),side=3,line=.6,cex=.8); 5174 5175 con=sum(ry)/length(ry); llc=sum(log(con^ry*(1-con)^(1-ry))); 5176 m0=-1/qnorm(con); 5177 if(con == .5) abline(v=muhat,col=1,lty=2) else abline(sighat-m0*muhat,m0,col=1,lty=2); 5178 rngx=xl; rngy=yl; 5179 5180 #----------------------------------------------------------------------------- 5181 # Limits for plot 2 5182 xl=numeric(0); 5183 for(i in 1:ncl){g=cl[[i]];xl=range(c(xl,g$x+qnorm(pp)*g$y),finite=T);} 5184 5185 if(!pcl & nclu > 0) 5186 { 5187 xl=numeric(0); 5188 for(i in 1:nclu){g=clu[[i]];xl=range(c(xl,g$x+qnorm(pp)*g$y));} 5189 } 5190 5191 xll=c(floor(xl[1]),ceiling(xl[2])); 5192 pxl2=pretty(xl); 5193 #----------------------------------------------------------------------------- 5194 ex=cl[[1]]$x+qnorm(pp)*cl[[1]]$y; 5195 ey=cl[[1]]$y; 5196 5197 rng2=range(ex,finite=T); 5198 5199 plot(ex,ey,type=dtp,xlim=xl,ylim=yl[1:2],xlab="",ylab="",xaxt="n",yaxt="n"); 5200 ilt=3; abline(v=pxl2,lty=ilt); abline(h=pyl,lty=ilt); 5201 points(qq,sighat,pch=16,cex=.7,col=2); 5202 5203 axis(1,at=pxl2,labels=T,tck=.01,cex=.8,mgp=c(3,.2,0)); 5204 axis(2,at=pyl,labels=T,tck=.01,mgp=c(3,.2,0),las=2); 5205 mtext(expression(paste("quantile (",italic(q),")",sep="")),side=1,line=1.4,cex=.9); 5206 5207 if(ncl > 1 & pcl)for(i in 1:ncl){ex=cl[[i]]$x+qnorm(pp)*cl[[i]]$y;; ey=cl[[i]]$y; points(ex,ey,type="l");} 5208 if(nu1 > 0)for(i in 1:length(clu)){exx=clu[[i]]$x+qnorm(pp)*clu[[i]]$y;; eyy=clu[[i]]$y; 5209 points(exx,eyy,type="l",col=2);} 5210 5211 b1=mkb0(conf1); 5212 rpp=xlead0(pp,3); 5213

Page 67:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

5214 b2=substitute(paste(italic(p),"=",x,", ",c[1],"=",y,sep=""), list(x=rpp,y=b1)) 5215 mtext(b2,side=3,line=.6,cex=.8); 5216 5217 if(pp == con) abline(v=muhat+qnorm(pp)*sighat,col=1,lty=2) else 5218 { 5219 m3=1/(qnorm(pp)+1/m0); 5220 abline(sighat-m3*(muhat+qnorm(pp)*sighat),m3,col=1,lty=2); 5221 } 5222 5223 #----------------------------------------------------------------------------- 5224 #Limits for plot 3 5225 xl=numeric(0); 5226 5227 for(i in 1:ncl){g=cl[[i]];xl=range(c(xl,pp,pnorm((qq-g$x)/g$y)));} 5228 if(nclu > 0) {for(i in 1:nclu){g=clu[[i]];xl=range(c(xl,pp,pnorm((qq-g$x)/g$y)));}} 5229 5230 xll=c(floor(xl[1]),ceiling(xl[2])); 5231 pxl3=pretty(xl); 5232 #----------------------------------------------------------------------------- 5233 ex=pnorm((qq-cl[[1]]$x)/cl[[1]]$y); 5234 ey=cl[[1]]$y; 5235 5236 plot(ex,ey,type=dtp,xlim=xl,ylim=yl[1:2],xlab="",ylab="",xaxt="n",yaxt="n"); 5237 points(pp,sighat,pch=16,cex=.7,col=2); 5238 ilt=3; abline(v=pxl3,lty=ilt); abline(h=pyl,lty=ilt); 5239 5240 axis(1,at=pxl3,labels=T,tck=.01,cex=.8,mgp=c(3,.2,0)); 5241 axis(2,at=pyl,labels=T,tck=.01,mgp=c(3,.2,0),las=2); 5242 mtext(expression(paste("probability (",italic(p),")",sep="")),side=1,line=1.4,cex=.9); 5243 mtext("standard deviation (s)",side=2,line=2.5,cex=.9); 5244 5245 if(ncl > 1 & pcl)for(i in 1:ncl){ex=pnorm((qq-cl[[i]]$x)/cl[[i]]$y); ey=cl[[i]]$y; points(ex,ey,type="l");} 5246 if(nu1 > 0)for(i in 1:length(clu)){exx=pnorm((qq-clu[[i]]$x)/clu[[i]]$y); eyy=clu[[i]]$y; 5247 points(exx,eyy,type="l",col=2);} 5248 5249 rmu=xlead0(muhat,3); rqq=xlead0(qq,3); 5250 if(overlap) b2=substitute(paste("q=",rqq,", ",c[1],"=",b1,sep="")) else 5251 b2=substitute(paste("q=",rmu,", ",c[1],"=",b1,sep="")) 5252 5253 mtext(b2,side=3,line=.6,cex=.8); 5254 abline(v=con,col=1,lty=2); 5255 #----------------------------------------------------------------------------- 5256 # linearized probability plot (for a single contour cl[[icl]]) 5257 { 5258 al=10^(6:2); al=c(1/al,1-1/al); al=c(al,seq(25,975,by=25)/1000); al=sort(al); 5259 nal=length(al); 5260 lrmat1=matrix(rep(0,6*nal),ncol=6); 5261 lrmat1[,5]=al; 5262 lrmat1[,2]=muhat+qnorm(al)*sighat; 5263 lra=list(1); 5264 limx=numeric(0); 5265 if(nobo) ncl=0; 5266 for(j in 1:(ncl+nclu)) 5267 { 5268 if(j > ncl) {x=clu[[j-ncl]]$x; y=clu[[j-ncl]]$y;} else {x=cl[[j]]$x; y=cl[[j]]$y;} 5269 for(i in 1:nal) 5270 { 5271 lrmat1[i,c(1,3)]=lim=range(x+qnorm(lrmat1[i,5])*y,finite=T); 5272 if(i > 2 & i < 48) limx=range(c(limx,lim)); 5273 lrmat1[i,c(4,6)]=range(pnorm((lrmat1[i,2]-x)/y),finite=T); 5274 } 5275 lra[[j]]=lrmat1 5276 } 5277 5278 abc=" LR CB's"; 5279 if(c1max > 0) c2max=pchisq(qchisq(c1max,1),2) else c2max = 0; 5280 rc1=xlead0(c1max,5); rc2=xlead0(c2max,5); 5281 5282 if(ncl > 0) grafl(limx) else 5283 { 5284 # Null Plot Just for Text 5285 plot(c(0,1),c(0,1),type="n",xaxt="n",yaxt="n",xlab="",ylab="",bty="n") 5286 titt1="LR CL's Do Not Exist"; 5287 titt2="Requirements Are:"; 5288 titt3="Overlap, and" 5289 mtext(titt1,side=3,line=-4.6,cex=.9); 5290 mtext(titt2,side=3,line=-6.6,cex=.9); 5291 mtext(titt3,side=3,line=-8.6,cex=.9); 5292

Page 68:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

titt4=substitute(paste(c[1]," < max(",c[1],") = ",rc1,sep="")) 5293 mtext(titt4,side=3,line=-10.6,cex=.9); 5294 } 5295 5296 if(ncl > 0) 5297 { 5298 if(one23 > 1) abline(v=muhat,col=8) 5299 5300 for(j in (ncl):1) 5301 { 5302 u=lra[[j]]; 5303 if(j > ncl) pcol=2 else pcol=1; 5304 if(j <= ncl | (j-ncl)%%2 ==1)lines(u[,1],qnorm(u[,5]),type="l",col=pcol); 5305 if(j <= ncl | (j-ncl)%%2 ==0)lines(u[,3],qnorm(u[,5]),type="l",col=pcol); 5306 } 5307 5308 if(one23==1) lines(u[,2],qnorm(u[,5]),type="l",col=8) 5309 5310 } 5311 5312 cn=c("ql","q","qh","pl","p","pu"); 5313 options(scipen=999); 5314 write.table(round(lra[[1]],6),file="lrcb.txt",quote=F,sep=",",na="i", 5315 col.names=cn,row.names=F); 5316 if(ncl > 1)for(j in 2:ncl) 5317 { 5318 suppressWarnings(write.table(round(lra[[j]],6),file="lrcb.txt",quote=F,sep=",",na="i",append=T, 5319 col.names=cn,row.names=F)); 5320 } 5321 options(scipen=0); 5322 } 5323 # main title 5324 par(mfrow=c(1,1)); 5325 par(oma = c(0,0,1,0), mar = c(5,4,4,2)+.1); 5326 if(c1max < .999995) tit1=substitute(paste(tit1," ",abc,", ",c["1max"]," = ",rc1,sep="")) else 5327 tit1=substitute(paste(tit1," ",abc,", ",c["2max"]," = ",rc2,sep="")) 5328 5329 if(!notitle) mtext(tit1,side=3,line=-.6,outer=T); 5330 return(); 5331 } 5332 5333 #INDEX 114 through 118 Xcbs2.R (5 functions) 5334 5335 mdose.p=function(obj,p) 5336 { 5337 np=length(p) 5338 se=rep(0,np) 5339 b=as.vector(obj$coef) 5340 x.p=(qnorm(p)-b[1])/b[2] 5341 for(i in 1:np) 5342 { 5343 pd= -c(1,x.p[i])/b[2] 5344 se[i]=sqrt((t(pd)%*%vcov(obj))%*%pd) 5345 } 5346 a=matrix(c(x.p,se),ncol=2) 5347 a=data.frame(a) 5348 names(a)=c("dose","se") 5349 return(a) 5350 } 5351 5352 mixed=function(dat) 5353 { 5354 min1=min(dat$X[which(dat$Y==1)]); 5355 max0=max(dat$X[which(dat$Y==0)]); 5356 dif=min1-max0; # dif < 0 <=> OVERLAP or ZONE OF MIXED RESULTS 5357 summ=min1+max0; 5358 con=sum(dat$Y)/length(dat$Y); 5359 result=list(min1,max0,summ,dif,con) 5360 names(result)=c("min1","max0","summ","dif","con"); 5361 return(result); 5362 } 5363 5364 graf1=function(limx,t1,k,big,legnd) 5365 { 5366 lw=3; 5367 spl="SPlus (dose.p)"; if(k!=1)spl="SPlus (GLM)"; if(big==0)sp1="SP"; 5368 leg=c("FM","LR","GLM"); if(big!=0)leg=c("Fisher Matrix","Likelihood Ratio",spl); 5369 qtic=pretty(limx); 5370 pr=c(1,10,100,1000,5000,9000,9900,9990,9999)/10000; q=qnorm(pr); 5371

Page 69:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

xl=range(limx); yl=c(-3.8,3.8); 5372 plot(xl,yl,type="n",xlim=xl,ylim=yl,xaxt="n",yaxt="n",xlab="",ylab="",cex=.8); 5373 xl1=expression(paste("quantile (",italic(q),")",sep="")); 5374 yl1=expression(paste("Probability of Response (",italic(p),"%)",sep="")); 5375 mtext(xl1,side=1,line=1.6,cex=.8); mtext(yl1,side=2,line=2.3,cex=.8); 5376 mtext(t1,side=3,line=.6,cex=.9); 5377 isiz1=.7;if(big==0)isiz1=.4; 5378 axis(1,at=qtic,labels=T,tck=.01,cex=isiz1,mgp=c(3,.5,0)); 5379 axis(2,at=q,labels=paste(100*pr," ",sep=""),tck=.01,cex.axis=.8,mgp=c(3,0,0),las=2); 5380 axis(3,at=qtic,labels=F,tck=.01,cex=isiz1); 5381 # Horizontal Grid Lines 5382 delx=.75 5383 ilt=3 5384 for(i in 1:length(pr)) lines(xl+c(-delx,delx),c(q[i],q[i]),lty=ilt); 5385 # Verticle Grid Lines 5386 abline(v=qtic,lty=ilt); 5387 del1=diff(range(limx))/20; 5388 if(legnd>0)legend(xl[1]+del1,qnorm(.997),legend=leg,lty=c(1,1,1),col=c(4,1,2),lwd=lw,cex=.6,bg="white")5389 ; 5390 return() 5391 } 5392 5393 lrmax=function(w,plt=F) 5394 { 5395 dat=w$d0; title=w$title; 5396 5397 rx=dat$X; ry=dat$Y; nc=dat$COUNT; 5398 rx=rep(rx,nc); ry=rep(ry,nc); 5399 nt=sum(nc); 5400 con=sum(ry)/length(ry); 5401 llc=sum(log(con^ry*(1-con)^(1-ry))); 5402 r0=rx[ry==0]; r1=rx[ry==1]; 5403 mix=length(r0)*length(r1); 5404 lux=length(unique(rx)); 5405 flg=0; 5406 if(mix == 0 | lux == 1) flg=1; 5407 M0=max(r0); m1=min(r1); del=m1-M0; one23=2+sign(del); 5408 5409 switch(one23, 5410 { # OVERLAP (Interval) (use log lik) 5411 xglm=glm(ry~rx,family=binomial(link=probit)); 5412 ab=as.vector(xglm$coef); 5413 muhat=-ab[1]/ab[2]; sighat=1/ab[2]; 5414 uu=xyllik(rx,ry,muhat,sighat); 5415 }, 5416 { # OVERLAP (Point) (use lik) 5417 muhat=(m1+M0)/2; sighat=0; 5418 mx=ry[rx == m1]; s1=sum(mx); s2=length(mx)-s1; 5419 uu=s1*log(s1) + s2*log(s2) - (s1+s2)*log(s1+s2); 5420 }, 5421 { # NO OVERLAP (use lik) 5422 muhat=(m1+M0)/2; sighat=0; uu=0; 5423 } 5424 ); 5425 5426 c2max=pchisq(2*(uu-llc),2); 5427 c1max=pchisq(qchisq(c2max,2),1); 5428 a=c(con,llc,c1max,c2max); 5429 5430 con=round(con,5); llc=round(llc,5); 5431 c1max=round(c1max,5); c2max=round(c2max,5); 5432 wx=list(dat,title,one23,con,llc,c1max,c2max,flg); 5433 names(wx)=c("d0","title","one23","con","llc","c1max","c2max","flg") 5434 if(plt) picdat(wx); 5435 return(wx) 5436 } 5437 5438 cbs=function(w,plt,notitle=F) 5439 { 5440 # gs for graph sheet 1 or 2 5441 # gs = 1 with neither pp nor qq ==> jms = 1 for (mu sig contour plot) 5442 # gs = 1 with a valid pp or qq ==> jms = 3 for 3 plots on one 5443 # gs = 2 5444 5445 fmmat=spmat=lrmat=matrix(rep(NA,6*15),ncol=6); 5446 mat=matrix(rep(NA,3*11*6),ncol=6); 5447 5448 a1=c(1,10,100,1000,10000,100000,250000)/1000000; al=c(a1,.5,sort(1-a1)); 5449 5450

Page 70:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

gs=0; 5451 if(plt == 1 | plt == 7) gs=1; 5452 if(plt == 2 | plt == 8) gs=2; 5453 if(gs == 0) return(); 5454 5455 if(gs == 1) 5456 { 5457 cflag=0; 5458 xx="Enter conf1 and conf2 (one must be 0): "; 5459 xx=readline(xx); cat("\n"); 5460 xx=as.numeric(unlist(strsplit(xx," "))); 5461 if(length(xx) != 2) cflag=-1; 5462 if(cflag == 0) 5463 { 5464 if(xx[1]>0 & xx[1]<1){cflag=1; conf1=xx[1];} 5465 if(cflag == 0 & xx[2]>0 & xx[2]<1){cflag=2; conf2=xx[2];} 5466 if(cflag == 1) {conf2=pchisq(qchisq(conf1,1),2); cn="c1";} 5467 if(cflag == 2) {conf1=pchisq(qchisq(conf2,2),1); cn="c2";} 5468 } 5469 if(cflag <= 0) return() 5470 5471 pflag=0; q0=.001; 5472 xx="Enter p and q (at least one must be 0): "; 5473 xx=readline(xx); cat("\n"); 5474 xx=as.numeric(unlist(strsplit(xx," "))); 5475 if(length(xx) != 2) return(); 5476 if(pflag == 0) 5477 { 5478 if(xx[1]>0 & xx[1]<1) {pflag = 1; pp=xx[1];} 5479 if(pflag == 0 & xx[1] == 0 & xx[2] != 0) {qq=xx[2]; pflag = 2;} 5480 if(pflag == 2 & xx[2] == q0) xx[2]=0; 5481 } 5482 if(pflag == 0) jms=1 else jms=3; 5483 } else 5484 { 5485 # jms must be defined here, as it's used in an if test later 5486 cflag=0; jms=0; 5487 xx="Enter conf1: "; 5488 xx=readline(xx); cat("\n"); 5489 xx=as.numeric(unlist(strsplit(xx," "))); 5490 if(length(xx) != 1 | xx[1] <= 0 | xx[1] >= 1) return(); 5491 conf1=xx[1]; conf2=pchisq(qchisq(conf1,1),2); 5492 } 5493 g=lrmax(w); c1max=g$c1max; c2max=g$c2max; one23=g$one23; flg=g$flg; 5494 if(flg == 1) {cat(paste("Need to do more testing\n",sep="")); return();} 5495 if(one23 > 1) {cat(paste("Need interval overlap for this particular plot.\n\n",sep="")); return(); } 5496 else 5497 if(conf1 >= c1max & (gs < 3)) {cat(paste("Need conf1 < ",round(c1max,4),", for this particular plot: 5498 Try again.\n\n",sep="")); return();} 5499 see1=xlead0(conf1,3); 5500 dat=w$d0; tit0=w$titl; ttl0=w$ttl0; ttl1=w$ttl1; ttl2=w$ttl2; 5501 5502 # do LR (needed if gs = 1 or 2) if conf1 < c1max and FM & SP (if gs = 2 and dif < 0) 5503 5504 if(conf1 < c1max) 5505 { 5506 a=lrq.lims(dat,conf1,P=al); 5507 cx=a$cx; cy=a$cy; lrmat=a$lrmat; dif=a$dif; con=a$con; 5508 muhat=a$muhat; sighat=a$sighat; ab=c(muhat,sighat); 5509 if(dif >= 0) {conf2=(conf2+3)/4; ab=c(muhat,Inf);} 5510 } 5511 5512 if(gs == 1 & jms == 3) 5513 { 5514 if(pflag == 1) qq=muhat+qnorm(pp)*sighat else pp=pnorm((qq-muhat)/sighat); 5515 } 5516 5517 if(dif<0)fmmat= fm.lims(dat,conf1,P=al); 5518 if(dif<0)spmat=glm.lims(dat,conf1,P=al); 5519 cf=xlead0(c(conf1,conf2),4); 5520 rc=xlead0(c(c1max,c2max),4); 5521 titt3=substitute(paste(c[1]," = ",u,", ",c["1max"]," = ",v,sep=""),list(u=cf[1],v=rc[1])); 5522 titt4=substitute(paste(c[2]," = ",u,", ",c["2max"]," = ",v,sep=""),list(u=cf[2],v=rc[2])); 5523 5524 #===========================Graph Sheet 1 (Graphs 1, 2 and 3)============================= 5525 # To get: just graphsheet 1, set gs=1; just graphsheet 2, set gs=2. 5526 options(warn=-1); # SUPPRESSES OUT OF BOUNDS WARNINGS (AND OTHERS) 5527 isiz=0.9; rd=6; 5528 #=========================================Graph 1======================================== 5529

Page 71:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

5530 rd=4; 5531 ilt=3; 5532 5533 rx=range(cx); ry=range(cy); prx=pretty(rx); pry=pretty(ry); 5534 5535 if(gs == 1) 5536 { 5537 if(jms == 3) {par(mfrow = c(2, 2), oma = c(0,.4,1.5,0), mar = c(3,3,3,1)); isiz=0.9;} 5538 plot(cx,cy,type="l",xlim=rx,ylim=ry,xlab="",ylab="",xaxt="n",yaxt="n"); 5539 axis(1,at=prx,labels=T,tck=.01,cex=.8,mgp=c(3,.2,0)); 5540 axis(2,at=pry,labels=T,tck=.01,mgp=c(3,.2,0),las=2); 5541 mtext("mean (m)",side=1,line=1.3,cex=.9); 5542 mtext("standard deviation (s)",side=2,line=2.5,cex=.9); 5543 abline(v=prx,lty=ilt); abline(h=pry,lty=ilt); 5544 points(muhat,sighat,pch=16,cex=.7,col=2); 5545 cf=xlead0(rx,4); tit2a=paste(cf[1]," < m < ",cf[2],sep=""); 5546 cf=xlead0(ry,4); tit2b=paste(cf[1]," < s < ",cf[2],sep=""); 5547 ndj=.5; if(jms == 1) ndj=0; 5548 mtext(tit2a,side=3,line=1.4,cex=.9,adj=ndj); 5549 mtext(tit2b,side=3,line=0.2,cex=.9,adj=ndj); 5550 m0=-1/qnorm(con); 5551 if(con == .5) abline(v=muhat,col=1,lty=2) else abline(sighat-m0*muhat,m0,col=1,lty=2); 5552 5553 #========================================================================================= 5554 5555 if(jms == 3) 5556 { 5557 #=========================================Graph 2======================================== 5558 rx=range(cx+qnorm(pp)*cy); prx=pretty(rx); 5559 plot(cx+qnorm(pp)*cy,cy,type="l",xlim=rx,ylim=ry,xlab="",ylab="",xaxt="n",yaxt="n"); 5560 axis(1,at=prx,labels=T,tck=.01,cex=.8,mgp=c(3,.2,0)); 5561 axis(2,at=pry,labels=T,tck=.01,mgp=c(3,.2,0),las=2); 5562 mtext(expression(paste("quantile (",italic(q),")",sep="")),side=1,line=1.3,cex=.9); 5563 points(qq,sighat,pch=16,cex=.7,col=2); 5564 abline(v=pretty(rx),lty=ilt); abline(h=pretty(ry),lty=ilt); 5565 cf=xlead0(pp,4); 5566 tit1=substitute(paste(italic(p)," = ",cf, sep="")) 5567 tit2=substitute(paste(x," < ",italic(q)," < ", y, sep=""), list(x=round(rx[1],rd),y=round(rx[2],rd))) 5568 mtext(tit1,side=3,line=1.4,cex=.9); 5569 mtext(tit2,side=3,line=0.2,cex=.9); 5570 if(pp == con) abline(v=muhat+qnorm(pp)*sighat,col=1,lty=2) else 5571 { 5572 m3=1/(qnorm(pp)+1/m0); 5573 abline(sighat-m3*(muhat+qnorm(pp)*sighat),m3,col=1,lty=2); 5574 } 5575 #==========================Graph 3 (Null Plot Just for Text)============================ 5576 5577 plot(c(0,1),c(0,1),type="n",xaxt="n",yaxt="n",xlab="",ylab="",bty="n") 5578 mtext(titt3,side=3,line=-4,cex=.9,adj=0); 5579 mtext(titt4,side=3,line=-7,cex=.9,adj=0); 5580 5581 #=========================================Graph 4======================================== 5582 5583 rx=range(pnorm((qq-cx)/cy)); prx=pretty(rx); 5584 plot(pnorm((qq-cx)/cy),cy,xlab="",ylab="",type="l",xlim=rx,ylim=ry,xaxt="n",yaxt="n"); 5585 axis(1,at=prx,labels=T,tck=.01,cex=.8,mgp=c(3,.2,0)); 5586 axis(2,at=pry,labels=T,tck=.01,mgp=c(3,.2,0),las=2); 5587 mtext(expression(paste(italic(p),sep="")),side=1,line=1.3,cex=.9); 5588 mtext("standard deviation (s)",side=2,line=2.5,cex=.9); 5589 points(pp,sighat,pch=16,cex=.7,col=2); 5590 abline(v=pretty(rx),lty=ilt); abline(h=pretty(ry),lty=ilt); 5591 abline(v=con,col=1,lty=2); 5592 cf=xlead0(qq,4); tit1=substitute(paste(italic(q)," = ",cf, sep="")); 5593 cf=xlead0(rx,4); 5594 tit2=substitute(paste(x," < ",italic(p)," < ", y, sep=""), list(x=cf[1],y=cf[2])) 5595 mtext(tit1,side=3,line=1.4,cex=.9); 5596 ds=0; 5597 mtext(tit2,side=3,line=0.2-ds,cex=.9); 5598 } 5599 5600 par(mfrow=c(1,1));par(oma = c(0,0,1,0), mar = c(5,4,4,2)+.1); 5601 if(jms != 3) 5602 { 5603 mtext(titt3,side=3,line=2.2,cex=.9,adj=1); 5604 mtext(titt4,side=3,line=1,cex=.9,adj=1); 5605 } 5606 if(!notitle) mtext(substitute(paste(ttl1," ",ttl2,", ",ttl0,", LR CB's",sep="")),side=3,line=-5607 .5,cex=1,outer=T); 5608

Page 72:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

5609 } 5610 5611 # Done with graph sheet 1 (gs = 1) containing either graph 1 or graphs 1, 2 3 and 4 5612 5613 #=======Define stuff needed for Graph Sheet 2 (next 4 plots) define lrmat,fmmat,spmat======= 5614 5615 if(gs == 2) 5616 { 5617 par(mfrow = c(2, 2), oma = c(0,0,1,0), mar = c(3,4,3,1)); 5618 tq2="(qlo,qhi) about q (given p)"; tp2="(plo,phi) about p (given q)"; 5619 tq1="(qlo,qhi) about q (supressing p)"; tp1="(plo,phi) about p (supressing q)"; 5620 5621 tq2=expression(paste("(",italic(q)[lo],",",italic(q)[hi],") about ",italic(q)," (given 5622 ",italic(p),")",sep="")); 5623 tp2=expression(paste("(",italic(p)[lo],",",italic(p)[hi],") about ",italic(p)," (given 5624 ",italic(q),")",sep="")); 5625 tq1=expression(paste("(",italic(q)[lo],",",italic(q)[hi],") about ",italic(q)," (supressing 5626 ",italic(p),")",sep="")); 5627 tp1=expression(paste("(",italic(p)[lo],",",italic(p)[hi],") about ",italic(p)," (supressing 5628 ",italic(q),")",sep="")); 5629 5630 # To plot Linearized Response, and CL's versus q 5631 # For Graph Sheet 2, need Range & delta on q-axis (qmin,qmax,bi) to cover FM, LR, and dose.p qlo's and qhi's 5632 5633 # Limits for the q axis for the two graphs using the function graf1 5634 big=0; 5635 isiz=.8; 5636 legq=c("Likelihood Ratio","Fisher Matrix","SPlus (dose.p)"); 5637 legp=c("Likelihood Ratio","Fisher Matrix","SPlus (GLM)"); 5638 if(big==0){par(mfrow=c(2,2));isiz=.5; legq=legp=c("LR","FM","GLM")}; 5639 if(big!=0) par(mfrow=c(1,1)); 5640 5641 # pr (graf1) is of length 15. For purposes of graphs 4 & 6, 5642 # Skip 1st two & last 2 two - corresponding to 1/million, 1/100000, 99999/10000, 999999/1000000 5643 5644 ih=3:13; 5645 5646 if(dif < 0) 5647 { 5648 if(conf1 < c1max) {mat[1:11,]=lrmat[ih,]; mat[12:22,]=fmmat[ih,]; mat[23:33,]=spmat[ih,]; i3=3;} else 5649 {mat[12:22,]=fmmat[ih,]; mat[23:33,]=spmat[ih,]; i3=2;} 5650 } else 5651 { 5652 if(conf1 < c1max) {mat[1:11,]=lrmat[ih,]; i3=1;} 5653 } 5654 jj4=range(c(mat[,1],mat[,3]),na.rm=T); 5655 5656 #======================Graph 5 (Linearized Response with (qlo,qhi))======================= 5657 # FM Color = 4 (Blue); LR Color = 1 (Black); SP Color = 2 (RED) 5658 fmc=4; lrc=1; spc=2; 5659 5660 graf1(jj4,tq2,1,big,1); 5661 lw=1.9; 5662 # LCL Curves and UCL Curves about q(p) 5663 if(i3 == 1 | i3 == 3) 5664 { 5665 w=lrmat;cl=lrc; 5666 lines(w[,1],qnorm(w[,5]),type="l",col=cl,cex=2,lwd=lw); 5667 lines(w[,3],qnorm(w[,5]),type="l",col=cl,cex=2,lwd=lw); 5668 lines(w[,2],qnorm(w[,5]),type="l",col=8,cex=2,lwd=lw); 5669 } 5670 if(i3 == 2 | i3 == 3) 5671 { 5672 w=fmmat;cl=fmc; 5673 lines(w[,1],qnorm(w[,5]),type="l",col=cl,cex=2,lwd=lw); 5674 lines(w[,3],qnorm(w[,5]),type="l",col=cl,cex=2,lwd=lw); 5675 w=spmat;cl=spc; 5676 lines(w[,1],qnorm(w[,5]),type="l",col=cl,cex=2,lwd=lw); 5677 lines(w[,3],qnorm(w[,5]),type="l",col=cl,cex=2,lwd=lw); 5678 lines(w[,2],qnorm(w[,5]),type="l",col=8,cex=2,lwd=lw); 5679 } 5680 5681 #==========================Graph 6 (qlo & qhi versus q Plots)============================ 5682 5683 ih=1:15 5684 if(i3 == 2 | i3 == 3) jj5=range(c(lrmat[ih,2],fmmat[ih,2],spmat[ih,2]),na.rm=T) else jj5=muhat+c(-1,1); 5685 plot(lrmat[,2],lrmat[,3],xlim=range(jj5),ylim=range(pretty(jj4)),type="n",xlab="",ylab="",xaxt="n",yaxt="n"); 5686 5687

Page 73:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

mtext(expression(paste("quantile (",italic(q),")",sep="")),side=1,line=1.6,cex=.8); 5688 mtext(expression(paste(italic(q[lo])," & ",italic(q[hi]),sep="")),side=2,line=2,cex=.8); 5689 qtic=pretty(jj5); 5690 axis(1,at=qtic,labels=T,tck=.01,cex=.8,mgp=c(3,.5,0)); 5691 qtic=pretty(jj4); 5692 axis(2,at=qtic,labels=T,tck=.01,cex=.8,mgp=c(3,.5,0)); 5693 5694 box(); 5695 abline(v=pretty(jj5),lty=ilt); 5696 abline(h=pretty(jj4),lty=ilt); 5697 5698 if(i3 == 2 | i3 == 3) 5699 { 5700 lines(fmmat[,2],fmmat[,3],col=fmc,lwd=lw);lines(lrmat[,2],lrmat[,3],col=lrc,lwd=lw);lines(spmat[,2],spmat[,3],5701 col=spc,lwd=lw); 5702 lines(fmmat[,2],fmmat[,1],col=fmc,lwd=lw);lines(lrmat[,2],lrmat[,1],col=lrc,lwd=lw);lines(spmat[,2],spmat[,1],5703 col=spc,lwd=lw); 5704 lines(lrmat[,2],lrmat[,2],col=8,lwd=lw); 5705 } 5706 5707 if(i3 == 1 | i3 == 3) 5708 { 5709 lines(lrmat[,2],lrmat[,3],col=lrc,lwd=lw); 5710 lines(lrmat[,2],lrmat[,1],col=lrc,lwd=lw); 5711 lines(lrmat[,2],lrmat[,2],col=8,lwd=lw); 5712 } 5713 mtext(tq1,side=3,line=.6,cex=.9); 5714 5715 #=====================Graph 7 (Linearized Response with (plo,phi))======================== 5716 5717 graf1(jj5,tp2,2,big,0); 5718 5719 # LCL Curves and UCL Curves about p(q) 5720 ep0=0.000001; ep1=1-ep0; 5721 5722 if(i3 == 1 | i3 == 3) 5723 { 5724 w=lrmat;cl=lrc; 5725 lines(w[,2],qnorm(w[,4]+ep0),type="l",col=cl,cex=2,lwd=lw); 5726 lines(w[,2],qnorm(w[,6]-ep0),type="l",col=cl,cex=2,lwd=lw); 5727 lines(w[,2],qnorm(w[,5]),type="l",col=8,cex=2,lwd=lw); 5728 } 5729 if(i3 == 2 | i3 == 3) 5730 { 5731 w=fmmat;cl=fmc; 5732 lines(w[,2],qnorm(w[,4]+ep0),type="l",col=cl,cex=2,lwd=lw); 5733 lines(w[,2],qnorm(w[,6]-ep0),type="l",col=cl,cex=2,lwd=lw); 5734 5735 w=spmat;cl=spc; 5736 lines(w[,2],qnorm(w[,4]+ep0),type="l",col=cl,cex=2,lwd=lw); 5737 lines(w[,2],qnorm(w[,6]-ep0),type="l",col=cl,cex=2,lwd=lw); 5738 lines(w[,2],qnorm(w[,5]),type="l",col=8,cex=2,lwd=lw); 5739 } 5740 5741 #==========================Graph 8 (plo & phi versus p Plots)============================ 5742 5743 h=100; 5744 plot(h*lrmat[,5],h*lrmat[,6],xlim=h*c(0,1),ylim=h*c(0,1),type="n",xlab="",ylab="",xaxt="n",yaxt="n"); 5745 mtext(expression(paste("probability ",italic(p)," (in %)",sep="")),side=1,line=1.6,cex=.8); 5746 mtext(expression(paste(italic(p)[lo]," & ",italic(p)[hi]," (in %)",sep="")),side=2,line=2,cex=.8); 5747 qtic=pretty(c(0,100)); 5748 axis(1,at=qtic,labels=T,tck=.01,cex=.8,mgp=c(3,.5,0)); 5749 axis(2,at=qtic,labels=T,tck=.01,cex=.8,mgp=c(3,.5,0)); 5750 5751 abline(v=pretty(h*c(0,1)),lty=ilt);abline(h=pretty(c(0,100)),lty=ilt); 5752 5753 if(i3 == 2 | i3 == 3) 5754 { 5755 lines(h*fmmat[,5],h*fmmat[,6],col=fmc,lwd=lw);lines(h*spmat[,5],h*spmat[,6],col=spc,lwd=lw); 5756 lines(h*fmmat[,5],h*fmmat[,4],col=fmc,lwd=lw);lines(h*spmat[,5],h*spmat[,4],col=spc,lwd=lw); 5757 } 5758 if(i3 == 1 | i3 == 3) 5759 { 5760 lines(h*lrmat[,5],h*lrmat[,6],col=lrc,lwd=lw); 5761 lines(h*lrmat[,5],h*lrmat[,4],col=lrc,lwd=lw); 5762 } 5763 box(); 5764 lines(c(0,100),c(0,100),lwd=lw,col=8); 5765 mtext(tp1,side=3,line=.6,cex=.9); 5766

Page 74:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

par(mfrow=c(1,1)); 5767 par(oma = c(0,0,1,0), mar = c(5,4,4,2)+.1); 5768 c1=round(100*conf1,2); 5769 if(!notitle)mtext(substitute(paste(ttl1," ",ttl2,", ",ttl0,", ",c[1],"=",see1,sep="")),side=3,line=-5770 .5,cex=1,outer=T); 5771 #========================================================================================== 5772 } 5773 5774 matt=rbind(fmmat,lrmat,spmat); 5775 cn=c("ql","q","qh","pl","p","pu"); 5776 options(scipen=999); 5777 rmatt=round(matt,6); 5778 write.table(rmatt,file="cbs.txt",quote=F,sep=",",na="i",col.names=cn,row.names=F) 5779 reset(); 5780 return(rmatt) 5781 } 5782 5783 #INDEX 119, wxdat (1 function) 5784 5785 wxdat=function(ic) 5786 { 5787 ad=""; 5788 5789 if(ic > 26) {cat(paste("\nArgument to wxdat must be between 1 and 26 inclusive\n")); return();} 5790 5791 switch(ic, 5792 { # 1 5793 titl1="My SenTest Ex."; 5794 xx=c(13,15,14,15.814,14.5,13.2197,15.0273,13.6665); 5795 yy=c(0,1,0,1,1,0,1,1); 5796 n=rep(1,length(xx)); 5797 }, 5798 { # 2 5799 titl1="MIL-STD-331 Ex."; 5800 xx=c(1.00,1.20,1.40,1.80,2.60,4.20,3.40,3.80,4.00,4.10, 5801 4.28,4.52,5.55,5.24,6.37,6.08,7.38,7.09,6.89,6.74); 5802 yy=c(0,0,0,0,0,1,0,0,0,0,0,0,1,0,1,0,1,1,1,1); 5803 n=rep(1,length(xx)); 5804 }, 5805 { # 3 5806 titl1="No Overlap Ex."; 5807 xx=c(14,16,15,16.814,15.5,16.8058,14.9669,16.3314); 5808 yy=c(0,1,0,1,0,1,0,1); 5809 n=rep(1,length(xx)); 5810 }, 5811 { # 4 5812 titl1="Neyer Data, n=30"; 5813 xx=c(60,70,65,68,64,60,60,68,61,67,62,70,62,69, 5814 63,69,63,63,69,71,70,70,62,62,70,62,70,61,60,58); 5815 yy=c(0,1,0,1,1,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,1,1,0,0,1,1,1,1,1,0); 5816 n=rep(1,length(xx)); 5817 }, 5818 { # 5 5819 titl1="No ZMR, n=17"; 5820 5821 xx=c(23,17,14,12.5,9.75,11.13,12.57,11.85,12.21,14.61,13.41,12.63,11.19,11.91,12.66,12.4,12.3); 5822 yy=c(1,1,1,1,0,0,1,0,0,1,1,1,0,0,1,0,0); 5823 n=rep(1,length(xx)); 5824 }, 5825 { # 6 5826 titl1="Infinite Sigma Case"; 5827 # When the S >= 7, that's when Sigma=Infinity, and Response Prob is Constant (3/4) 5828 S=8; 5829 xx=c(10,12,11,S); 5830 yy=c(0,1,1,1); 5831 n=rep(1,length(xx)); 5832 }, 5833 { # 7 5834 titl1="Velocity, n=15"; 5835 xx=c(656,900,950,984,1000,1022,1145,1164,1305,1313,1450,1457,1500,1625,1750)/1000; 5836 yy=c(0,0,0,0,0,0,1,0,1,1,1,1,0,1,1); 5837 n=c(1,1,4,1,1,1,1,1,1,1,3,1,1,1,1); 5838 xx=rep(xx,n); yy=rep(yy,n); 5839 n=rep(1,length(xx)); 5840 }, 5841 { # 8 5842 titl1="VariDensity, n=24"; 5843 xx=c(1.8510,1.8505,1.8505,1.5530,1.6590,1.7580,1.7040,1.7560,1.8000,1.6590,1.7090, 5844

Page 75:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

5845 1.7570,1.8020,1.7040,1.7580,1.7266,1.7400,1.7472,1.7450,1.7540,1.8010,1.7241,1.7080,1.7311); 5846 yy=c(1,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,1,0,1); 5847 n=rep(1,length(xx)); 5848 }, 5849 { # 9 5850 titl1="VariGap, n=21"; 5851 5852 xx=c(4975,6260,5850,5310,6080,5950,5775,5910,5740,5970,5890,5800,5730,5630,5420,5470,5500,5535,5495,5515853 0,5610)/10000; 5854 yy=c(0,1,0,0,1,1,0,1,0,1,1,1,1,1,0,0,0,0,0,0,0); 5855 n=rep(1,length(xx)); 5856 }, 5857 { # 10 5858 titl1="NO ZMR Example"; 5859 5860 xx=c(45,23,34,29,26,31.5,27.5,23.5,29.1,25,26.8,24.9,27.6,26.4,25.3,26.9,25.6,25.8,26.2); 5861 yy=c(1,0,1,1,0,1,1,0,1,0,1,0,1,1,0,1,0,0,0); 5862 n=rep(1,length(xx)); 5863 }, 5864 { # 11 5865 titl1="Dror & Steinberg (n=40)"; 5866 5867 xx=c(18.00,19.00,20.00,21.00,20.00,19.00,18.00,19.00,18.00,18.00,18.25,18.50,18.75,19.00,19.25,19.00, 5868 5869 18.75,19.00,18.75,19.00,19.25,19.00,19.25,19.00,18.75,19.00,18.75,19.00,19.25,19.50,19.25,19.00, 5870 18.75,18.50,18.75,19.00,18.75,18.50,18.75,18.50); 5871 yy=c(0,0,0,1,1,1,0,1,0,0,0,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0); 5872 n=rep(1,length(xx)); 5873 #xx=c(18.0,18.25,18.5,18.75,18.75,19.0,19.0,19.25,19.25,19.5,20.0,20.0,21.0); 5874 #yy=c(0,0,0,0,1,0,1,0,1,1,0,1,1); n=c(4,1,4,8,1,6,7,1,4,1,1,1,1); 5875 }, 5876 { # 12 5877 titl1="Eli data (n=73)"; 5878 xx=c(3.5,4.0,4.0,4.5,4.5,5.0,5.0,5.5,5.5,6.0); 5879 fac=1; xx=fac*xx; 5880 yy=c(0,0,1,0,1,0,1,0,1,1); 5881 n=c(5,23,1,6,5,2,6,3,7,15); 5882 }, 5883 { # 13 5884 titl1="A Neyer Test"; 5885 xx=c(800,807,884,900,910,913,923,961,968,969,972,993,1000, 5886 1012,1013,1015,1025,1033,1038,1051,1060,1072,1129,1150,1219); 5887 yy=c(0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,0,1,1,0,1,1,1,1,1,1); 5888 n=rep(1,length(xx)); 5889 }, 5890 { #14 5891 titl1="JF's Data"; 5892 xx=c(1.375,1.53,1.275,1.32,1.351,1.334,1.32,1.34,1.349,1.327,1.315,1.344,1.318,1.337, 5893 5894 1.322,1.336,1.324,1.345,1.344,1.348,1.32,1.376,1.373,1.371,1.369,1.387,1.384,1.382,1.302, 5895 1.379,1.376,1.307,1.309,1.285,1.399,1.289) 5896 yy=c(1,1,0,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1,1); 5897 n=rep(1,length(xx)); 5898 }, 5899 { #15 5900 titl1="An n=3 Ex." 5901 xx=c(1,3,4,5); yy=c(0,1,1,0); n=rep(1,length(xx)); 5902 xx=c(1,3,4); yy=c(0,1,0); n=rep(1,length(xx)); 5903 }, 5904 { #16 5905 titl1="An n=4, con=.5 Ex." 5906 xx=c(1,3,4,5); yy=c(0,1,1,0); n=rep(1,length(xx)); 5907 }, 5908 { # 17 5909 titl1="No overlap (A)"; 5910 xx=c(14,15,16); yy=c(0,1,1); tit1="No Overlap (n=3) Ex."; 5911 n=rep(1,length(xx)); 5912 5913 }, 5914 { # 18 5915 titl1="No overlap (B)"; 5916 xx=c(14,16); yy=c(0,1); tit1="No Overlap (n=2) Ex."; 5917 n=rep(1,length(xx)); 5918 5919 }, 5920 { # 19 5921 titl1="No overlap (C)"; 5922 xx=c(13,14,15,16); yy=c(0,0,1,1); tit1="No Overlap (n=4) Ex."; 5923

Page 76:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

n=rep(1,length(xx)); 5924 5925 }, 5926 { # 20 5927 titl1="One point overlap (A)"; 5928 xx=c(14,14); yy=c(0,1); #Need to do more testing 5929 n=rep(1,length(xx)); 5930 }, 5931 { # 21 5932 titl1="One point overlap (B)"; 5933 xx=c(14,16,16); yy=c(0,0,1); 5934 n=rep(1,length(xx)); 5935 }, 5936 { # 22 5937 titl1="One point overlap (C)"; 5938 xx=c(14,16,16,16); yy=c(0,0,1,1); 5939 n=rep(1,length(xx)); 5940 }, 5941 { # 23 5942 titl1="One point overlap (D)"; 5943 xx=c(14,16,16,18); yy=c(0,0,1,1); 5944 n=rep(1,length(xx)); 5945 }, 5946 { # 24 5947 titl1="One point overlap (E)"; 5948 xx=c(14,16,16,16,16); yy=c(0,0,0,1,1); 5949 n=rep(1,length(xx)); 5950 }, 5951 { # 25 5952 titl1="A Simulated Test"; 5953 xx=c(5.50000,16.50000,9.52628,7.23841,6.58790,10.46693,6.79797,10.14349, 5954 8.30392,6.94172,8.65883,7.03924,7.47790,6.81379,8.16104,8.86730, 5955 9.73525,9.57780,10.63076,10.45669,11.68522,23.80358,19.33242,17.14054, 5956 15.87435,15.04495,14.45109,17.11908,16.67776,16.31401,16.00650,15.74132, 5957 15.50899,15.30279,15.11780); 5958 yy=c(0,1,1,0,0,1,0,1,1,0,1,1,0,0,0,0,1,0,1,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1); 5959 n=rep(1,length(xx)); 5960 }, 5961 { # 26 5962 titl1="A 2 pointer, n=4 (overlap)"; 5963 xx=c(1,1,2,2); 5964 yy=c(0,1,1,0); 5965 n=rep(1,length(xx)); 5966 }, 5967 5968 ); 5969 5970 titl1=paste(ic,ad,". ",titl1,sep=""); 5971 dat=matrix(c(xx,yy,n),ncol=3); 5972 dat=data.frame(dat); 5973 names(dat)=c("X","Y","COUNT"); 5974 5975 w=list(dat,titl1); 5976 names(w)=c("d0","title"); 5977 g=lrmax(w,plt=T); 5978 g=c(g,test=5,ttl0=titl1,ttl1=NULL,ttl2="wxdat",ttl3=NULL,ln=F) 5979 5980 return(g) 5981 } 5982 5983 #INDEX 120 through 130, last11.R (11 functions) 5984 5985 # this version of emplik (emplik0) comments out the print mu - as it's always the 0 vector for our purpose 5986 5987 emplik0 = function( 5988 z, # matrix with one data vector per row, a column vector is ok when d=1 5989 mu, # hypothesized mean, default (0 ... 0) in R^d 5990 lam, # starting lambda, default (0 ... 0) 5991 eps, # lower cutoff for -log( ), default 1/nrow(z) 5992 M, # upper cutoff for -log( ), default Inf 5993 thresh=1e-30, # convergence threshold for log likelihood (default is aggressive) 5994 itermax=100, # upper bound on number of Newton steps (seems ample) 5995 verbose=FALSE)# controls printed output 5996 { 5997 # empirical likelihood test for whether 5998 # mean of (rows of) z is mu 5999 6000 6001 # Internal function mllog, modified -log( ) with derivatives 6002

Page 77:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

6003 mllog = function( x, eps, M, der=0 ){ 6004 # minus log and its first der derivatives, on eps < x < M 6005 # 4th order Taylor approx to left of eps and right of M 6006 # der = 0 or 1 or 2 6007 # 4th order is lowest that gives self concordance 6008 6009 if( missing(M) ) 6010 M = Inf 6011 if( eps>M ) 6012 stop("Thresholds out of order") 6013 6014 lo = x < eps 6015 hi = x > M 6016 md = (!lo) & (!hi) 6017 6018 # Coefficients for 4th order Taylor approx below eps 6019 coefs = rep(0,5) 6020 coefs[1] = -log(eps) 6021 coefs[2:5] = (-eps)^-(1:4)/(1:4) 6022 6023 # Coefficients for 4th order Taylor approx above M 6024 Coefs = rep(0,5) 6025 Coefs[1] = -log(M) 6026 Coefs[2:5] = (-M)^-(1:4)/(1:4) 6027 6028 # degree 4 polynomial approx to log 6029 h = function(y,cvals){ # cvals are coefs at eps, Coefs at M 6030 # sum c[t+1] y^t 6031 tee = 1:4 6032 ans = y*0 6033 ans = ans + cvals[1] 6034 for( j in tee ) 6035 ans = ans + y^j*cvals[j+1] 6036 ans 6037 } 6038 6039 # first derivative of h at y, from approx at pt 6040 hp = function(y,pt){ 6041 tee = 0:3 6042 ans = y*0 6043 for( j in tee ) 6044 ans = ans + (-y/pt)^j 6045 ans = ans * (-pt)^-1 6046 ans 6047 } 6048 6049 # second derivative of h at y, from approx at pt 6050 hpp = function(y,pt){ 6051 tee = 0:2 6052 ans = y*0 6053 for( j in tee ) 6054 ans = ans + (-y/pt)^j 6055 ans = ans *(-pt)^-2 6056 ans 6057 } 6058 6059 # function value 6060 f = x*0 6061 f[lo] = h( x[lo]-eps, coefs ) 6062 f[hi] = h( x[hi]-M, Coefs ) 6063 f[md] = -log(x[md]) 6064 6065 if( der<1 )return(cbind(f)) 6066 6067 # first derivative 6068 fp = x*0 6069 fp[lo] = hp( x[lo]-eps, eps ) 6070 fp[hi] = hp( x[hi]-M, M ) 6071 fp[md] = -1/x[md] 6072 6073 if( der<2 )return(cbind(f,fp)) 6074 6075 # second derivative 6076 fpp = x*0 6077 fpp[lo] = hpp( x[lo]-eps, eps ) 6078 fpp[hi] = hpp( x[hi]-M, M ) 6079 fpp[md] = 1/x[md]^2 6080 6081

Page 78:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

return( cbind(f,fp,fpp) ) 6082 # End of mllog() 6083 } 6084 6085 # Internal function to do a linear model via SVD 6086 # Empirical likelihood's Newton steps are of 6087 # least squares type. 6088 6089 svdlm = function(X,y){ 6090 # Linear model regression coefficient via SVD 6091 6092 # Tolerances for generalized inverse via SVD 6093 RELTOL = 1e-9 6094 ABSTOL = 1e-100 6095 6096 # Get Xplus = generalized inverse of X 6097 # If svd algorithm failures are encountered 6098 # it sometimes helps to try svd(t(X)) and 6099 # translate back. First check to ensure that 6100 # X does not contain NaN or Inf or -Inf. 6101 svdX = svd(X) 6102 d = svdX$d 6103 lo = d < (RELTOL * max(d) + ABSTOL) 6104 dinv = 1/d 6105 dinv[lo] = 0 6106 Xplus = svdX$v %*% diag(dinv,nrow=length(dinv)) %*% t(svdX$u) 6107 # taking care with diag when dinv is 1x1 6108 # to avoid getting the identity matrix of 6109 # size floor(dinv) 6110 6111 # Return X^+ y 6112 Xplus %*% matrix(y,ncol=1) 6113 } 6114 # end of svdlm 6115 6116 6117 # Backtracking line search parameters [Tweak only with extreme 6118 caution.] 6119 # See Boyd and Vandenberghe, pp464-466. 6120 ALPHA = 0.3 # seems better than 0.01 on some 2d test data (sometimes 6121 fewer iters) 6122 BETA = 0.8 6123 # We need 0 < ALPHA < 1/2 and 0 < BETA < 1 6124 6125 # Backtrack threshold: you can miss by this much. 6126 BACKEPS = 0 6127 # Consider replacing 0 by 1e-10 if backtracking seems to be 6128 # failing due to round off. 6129 6130 if( is.vector(z) ) 6131 z = matrix(z,ncol=1) 6132 6133 n = nrow(z) 6134 d = ncol(z) 6135 6136 if( missing(mu) ) 6137 mu = rep(0,d) 6138 z = t( t(z)-mu ) # subtract mu from each z[i,] 6139 6140 if( missing(eps) )eps = 1/n 6141 if( missing(M) )M = Inf 6142 6143 # 6144 # Use lam = 0 or initial lam, whichever is best 6145 # 6146 6147 init0 = mllog( rep(1,n), eps=eps, M=M, der=2 ) # i.e. lam = 0 6148 6149 if( missing(lam) ){ 6150 init = init0 6151 lam = rep(0,d) 6152 }else{ 6153 init = mllog( 1+z%*%lam, eps=eps, M=M, der=2 ) 6154 if( sum(init0[,1]) < sum(init[,1]) ){ 6155 lam = rep(0,d) 6156 init = init0 6157 } 6158 } 6159 6160

Page 79:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

# Initial f, g 6161 fold = sum(init[,1]) 6162 gold = apply( z * init[,2],2,sum ) 6163 6164 converged = FALSE 6165 iter = 0 6166 oldvals = init 6167 # print("mu") 6168 # print(mu) 6169 if(verbose) print("c(fold,gradnorm,ndec,lam)") 6170 while( !converged ){ 6171 iter = iter + 1 6172 6173 # Get Newton Step 6174 rootllpp = sqrt(oldvals[,3]) # sqrt 2nd deriv of -llog lik 6175 zt = z 6176 for( j in 1:d ) 6177 zt[,j] = zt[,j] * rootllpp 6178 yt = oldvals[,2] / rootllpp 6179 step = -svdlm(zt,yt) # more reliable than step = -lm( yt~zt-1 )$coef 6180 6181 backtrack = FALSE 6182 s = 1 # usually called t, but R uses t for transpose 6183 while( !backtrack ){ 6184 newvals = mllog( 1+z%*%(lam+s*step),eps=eps,M=M,der=2 ) 6185 fnew = sum(newvals[,1]) 6186 targ = fold + ALPHA * s * sum( gold*step ) + BACKEPS # (BACKEPS for roundoff, should not be 6187 needed) 6188 if( fnew <= targ ){ 6189 # backtracking has converged 6190 backtrack = TRUE 6191 oldvals = newvals 6192 fold = fnew 6193 gold = apply( z * oldvals[,2],2,sum ) 6194 # take the step 6195 lam = lam + s*step 6196 }else{ 6197 s = s * BETA 6198 } 6199 } 6200 6201 ## print(paste("iter", iter)) 6202 ## print("fold") 6203 ## print(fold) 6204 # Newton decrement and gradient norm 6205 ndec = sqrt( sum( (step*gold)^2 ) ) 6206 gradnorm = sqrt( sum(gold^2)) 6207 6208 if(verbose)print(c(fold,gradnorm,ndec,lam)) 6209 6210 converged = ( ndec^2 <= thresh) 6211 if( iter > itermax )break 6212 } 6213 6214 wts = (1/n)/(1+z%*%lam) 6215 logelr = sum( mllog(1+z%*%lam,eps=eps,M=M,der=0) ) 6216 6217 list(logelr=logelr,lam=lam, wts=wts, 6218 converged=converged,iter=iter,ndec=ndec,gradnorm=gradnorm) 6219 } 6220 6221 vdif=function(x,y,rid,r=0) 6222 { 6223 # x = vector of rows, each of length nc. y=vector of responses. 6224 # default r=0: returns x1, x0, d , & overlap (T or F) 6225 # for 1 <= r <= length(y) 6226 ny=length(y); 6227 nc=length(x)/ny; 6228 6229 x=matrix(x,ncol=nc,byrow=T); 6230 if(r < 0 | r > ny) {cat(paste("r = ",r," is out of bounds\n\n")); return();} 6231 n0=length(which(y==0)); 6232 n1=length(which(y==1)); 6233 if(r != 0) {x=x[-r,]; y=y[-r]; ny=length(y);} 6234 n0=length(which(y==0)); 6235 n1=length(which(y==1)); 6236 6237 if(nc == 1) {x0=x[y==0]; x1=x[y==1]; x0=as.matrix(t(x0)); x1=as.matrix(t(x1));} else 6238 {x0=x[y==0,]; x1=x[y==1,];} 6239

Page 80:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

if(n1 == 1) x1=as.matrix(t(x1)); 6240 if(n0 == 1) x0=as.matrix(t(x0)); 6241 dX=matrix(rep(0,n0*n1*nc),ncol=nc); 6242 ii=0 6243 6244 if(n0*n1 > 0) 6245 { 6246 if(nc > 1) 6247 { 6248 for(i in 1:n1) 6249 { 6250 for(j in 1:n0) 6251 { 6252 ii=ii+1; 6253 dX[ii,]=x1[i,]-x0[j,]; 6254 } 6255 } 6256 } else 6257 { 6258 for(i in 1:n1) 6259 { 6260 for(j in 1:n0) 6261 { 6262 ii=ii+1; 6263 dX[ii,]=x1[i]-x0[j]; 6264 } 6265 } 6266 } 6267 } 6268 epsi=.000001; 6269 # don't call h=emplik if prd == 0, else get svd(X) error: a dimension is zero 6270 # initially, set htf=FALSE, sm=0, hsm=1. If prd != 0, emplik will define them 6271 htf=F 6272 sm=0 6273 hsm=1 6274 prd=prod(dim(dX)) 6275 if(prd != 0) 6276 { 6277 h=emplik0(dX) 6278 htf=h$converged; 6279 sm=sum(h$wts); 6280 hsm=abs(1-sm) 6281 } 6282 rnk=qr(dX)$rank 6283 6284 if(rnk != nc | !htf | hsm > epsi) ovr=F else ovr=T 6285 return(list(x=x,y=y,x1=x1,x0=x0,dX=dX,rank=rnk,sum=sm,overlap=ovr)) 6286 } 6287 6288 vdeflate=function(x,y,rid) 6289 { 6290 ny=length(y); 6291 rowID=1:ny; 6292 nc=length(x)/ny; 6293 oh=vdif(x,y,rid) 6294 ov=ovi=oh$ov 6295 if(!ov) return(oh); 6296 if(ny < nc+2) return(oh); 6297 xmat=matrix(x,byrow=T,ncol=nc) 6298 l1=l2=0; 6299 while(1) 6300 { 6301 while(1) 6302 { 6303 ohi=vdif(x,y,rid,1); 6304 ovi=ohi$ov; 6305 if(!ovi) {l1=l1+1; break;} else {oh=ohi; x=x[-(1:nc)]; y=y[-1]; rowID=rowID[-1];} 6306 } 6307 # can't remove 1st row of x and 1st y 6308 # oh should still be T 6309 oh=vdif(x,y,rid)$overlap 6310 6311 remo=NULL 6312 if(oh) 6313 { 6314 ny=length(y) 6315 for(i in 1:ny) remo=c(remo,vdif(x,y,rid,i)$overlap) 6316 l2=l2+1 6317 } 6318

Page 81:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

# remo[1] should be F, followed by a mix of F's & T's 6319 6320 if(any(remo)) 6321 { 6322 gg=c(which(remo),which(!remo)) 6323 ng=length(gg) 6324 a=rep(gg,rep(nc,ng)) 6325 aa=rep(1:nc,ng) 6326 s=aa+(a-1)*nc; 6327 # Reorder x so that First nc x's wi y[1] have a chance to be removed 6328 x=x[s]; 6329 y=y[gg]; 6330 rowID=rowID[gg]; 6331 } else break 6332 } 6333 vdf=vdif(x,y,rid) 6334 overlap=vdf$overlap 6335 dX=vdf$dX 6336 x=matrix(x,byrow=T,ncol=nc); 6337 loop=c(l1,l2); 6338 ysplit=.5-sum(y-.5); 6339 return(list(x=x,y=y,rowID=rowID,dX=dX,loop=loop,removable=remo,overlap=overlap,ysplit=ysplit)) 6340 } 6341 6342 overlap=function(w,ipr=T) 6343 { 6344 if(ipr)cat("\n mdif(w) output\n--------------------\n") 6345 b=mdif(w) 6346 if(ipr)print(b) 6347 if(b$overlap) 6348 { 6349 if(ipr)cat("\ndeflate(w) output\n-------------------\n") 6350 bb=mdeflate(w) 6351 if(ipr)print(bb) 6352 } 6353 if(ipr)cat("-------------------\n") 6354 if(!b$overlap) return(list(orig=b)) else return(list(orig=b,defl=bb)) 6355 } 6356 6357 mdif=function(w,r=0) 6358 { 6359 x=w$x 6360 y=w$y 6361 rid=w$rid 6362 x=as.vector(t(x)); 6363 b=vdif(x,y,rid,r) 6364 return(b) 6365 } 6366 6367 mdeflate=function(w) 6368 { 6369 x=w$x 6370 y=w$y 6371 rid=w$rid 6372 x=as.vector(t(x)); 6373 b=vdeflate(x,y,rid) 6374 return(b) 6375 } 6376 6377 SintF=function(w) 6378 { 6379 h1=overlap(w,ipr=F) 6380 if(h1$orig$overlap) 6381 { 6382 # x1 is nr0 by d, x0 is nr0 by d, dX is nt by d and wts is nt by 1 6383 x0=h1$orig$x0 6384 x1=h1$orig$x1 6385 if(nrow(x0)==1 & nrow(x1) == 1) {x0=t(x0); x1=t(x1);} 6386 nr0=nrow(x0); nr1=nrow(x1); 6387 nt=nr0*nr1 6388 6389 dX1=h1$orig$dX 6390 e0=emplik0(dX1) 6391 wts1=e0$wts 6392 # cast weights as a matrix 6393 wts=matrix(wts1,ncol=nr0,byrow=T) 6394 # sum(k1*x1) == sum(k0*x0) 6395 k1=rowSums(wts) 6396 k0=colSums(wts) 6397

Page 82:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

ess=eff=0 6398 for(i in 1:nr1)ess=ess+k1[i]*x1[i,] 6399 for(i in 1:nr0)eff=eff+k0[i]*x0[i,] 6400 6401 return(list(x1=x1,x0=x0,wts=wts,k1=k1,k0=k0,ess=ess,eff=eff)) 6402 } else {cat("This is not an overlapping data set\n"); return();} 6403 } 6404 6405 testdat=function(ic,remo=0) 6406 { 6407 x12 = c( 6408 6.7, 5.8, 4.0, 6409 8.7, 4.6, 7.0, 6410 11.9, 4.1, 6.0, 6411 10.1, 2.6, 3.0, 6412 11.2, 4.7, 8.0, 6413 9.0, 5.0, 5.0, 6414 10.0, 4.4, 9.0, 6415 9.0, 4.8, 10.0, 6416 7.5, 4.2, 2.5, 6417 10.3, 4.5, 6.5, 6418 9.5, 4.1, 3.5, 6419 10.9, 4.9, 4.5, 6420 7.0, 3.8, 1.0, 6421 8.5, 4.6, 2.0, 6422 7.3, 5.1, 2.1, 6423 10.0, 4.0, 11.0); 6424 y12 = c(0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0); 6425 6426 switch(ic, 6427 { # 1 d=3 case I know well. No overlap. 6428 x = x12; y=y12; 6429 }, 6430 { # 2 CASE 1 repeat last 5 x's, reverse last 5 y's, so dX has 5 rows of 0's. Overlap. 6431 x=c(x12,x12[34:48]); y=c(y12,0,1,1,1,1); 6432 }, 6433 { # 3 Case 1 with 13th y reversed. Overlap. 6434 x=x12; y=y12; y[13]=1; 6435 }, 6436 { # 4 Case 3 repeat last 5 x's, reverse last 5 y's, so dX has 5 rows of 0's. Overlap. 6437 x=x12; y=y12; y[13]=1; 6438 x=c(x12,x12[34:48]); y=c(y,c(0,0,1,1,1)) 6439 }, 6440 { # 5 d=1 Overlap 6441 x=c(1,3,4); y=c(0,1,0); 6442 }, 6443 { # 6 d=1 No overlap. ** OUR PAPER SUGGESTS THIS IS AN OVERLAP CONFIGURATION! ** 6444 x=c(1,3,3); y=c(0,0,1); 6445 }, 6446 { # 7 Case 5 d=1, with an extra 0 at x=4.2. Overlap. 6447 x=c(1,3,4,4.2); y=c(0,1,0,0); 6448 }, 6449 { # 8 Case 6 d=1, with an extra 1 at x=3.5. No overlap. 6450 x=c(1,3,3,3.5); y=c(0,0,1,1); 6451 }, 6452 { # 9 A d=7 Simulated case (n=40). Overlap. 6453 library(MASS) 6454 set.seed(123) 6455 nc=7 6456 mn=8*1:nc; 6457 Sigma=diag(2*(1:nc)) 6458 x=as.vector(t(mvrnorm(n=40, mn, Sigma))) 6459 y=rbinom(40,1,.4) 6460 }, 6461 { # 10 A d=4 Simulated case (n=32). Overlap. 6462 library(MASS) 6463 set.seed(567) 6464 nc=4 6465 mn=8*1:nc; 6466 Sigma=diag(2*(1:nc)) 6467 x=as.vector(t(mvrnorm(n=32, mn, Sigma))) 6468 y=rbinom(32,1,.4) 6469 }, 6470 { # 11 Case 3 with y=1-y. Overlap 6471 x=x12; y=y12; y[13]=1; y=1-y; 6472 }, 6473 { # 12 Case 3 with 1 more pair(x[17],y[17]=1) 6474 # such that mean(x1)=mean(x0)=c(8.5375,4.3750,4.3875). Overlap. 6475 x=x12; y=y12; y[13]=1; x=c(x,-2.4625,3.1750,-10.5125); y=c(y,1); 6476

Page 83:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

}, 6477 { # 13 Case 3 plus 6478 6479 x12 = c( 6480 6.7, 5.8, 4.0,-1, 6481 8.7, 4.6, 7.0,-1, 6482 10.1, 2.6, 3.0,-1, 6483 7.5, 4.2, 2.5,-1, 6484 9.5, 4.1, 3.5,-1, 6485 8.5, 4.6, 2.0,-1, 6486 7.3, 5.1, 2.1,-1, 6487 10.0, 4.0, 11.0,-1, 6488 7.0, 3.8, 1.0,0, 6489 11.9, 4.1, 6.0,0, 6490 11.2, 4.7, 8.0,0, 6491 9.0, 5.0, 5.0,0, 6492 10.0, 4.4, 9.0,0, 6493 9.0, 4.8, 10.0,0, 6494 10.3, 4.5, 6.5,0, 6495 10.9, 4.9, 4.5,0 6496 ); 6497 y12=c(rep(0,8),rep(1,8)); 6498 m1=mean(c(6.7,8.7,10.1,7.5,9.5,8.5,7.3,10.0)); 6499 m2=mean(c(5.8,4.6,2.6,4.2,4.1,4.6,5.1,4.0)); 6500 m3=mean(c(4.0,7.0,3.0,2.5,3.5,2.0,2.1,11.0)); 6501 x12=c(x12,c(m1,m2,m3,1)); 6502 y12=c(y12,0); 6503 6504 x=x12; y=y12; 6505 }, 6506 { # 14 Case 13 plus 6507 x12=c( 6508 6.7,5.8,4,-1,-1, 6509 8.7,4.6,7,-1,-1, 6510 10.1,2.6,3,-1,-1, 6511 7.5,4.2,2.5,-1,-1, 6512 9.5,4.1,3.5,-1,-1, 6513 8.5,4.6,2,-1,-1, 6514 7.3,5.1,2.1,-1,-1, 6515 10,4,11,-1,-1, 6516 8.5375,4.375,4.3875,1,-1, 6517 7,3.8,1,0,0, 6518 11.9,4.1,6,0,0, 6519 11.2,4.7,8,0,0, 6520 9,5,5,0,0, 6521 10,4.4,9,0,0, 6522 9,4.8,10,0,0, 6523 10.3,4.5,6.5,0,0, 6524 10.9,4.9,4.5,0,0); 6525 y12=c(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1); 6526 6527 m1=mean(c(6.7,8.7,10.1,7.5,9.5,8.5,7.3,10.0,8.5375)); 6528 m2=mean(c(5.8,4.6,2.6,4.2,4.1,4.6,5.1,4.0,4.375)); 6529 m3=mean(c(4.0,7.0,3.0,2.5,3.5,2.0,2.1,11.0,4.3875)); 6530 m4=mean(c(rep(-1,8),1)); 6531 x12=c(x12,c(m1,m2,m3,m4,1)); 6532 y12=c(y12,0); 6533 x=x12; y=y12; 6534 }, 6535 { #15 Cancer remission data 6536 # predictors = cell smear infil li blast temp 6537 x=c( 6538 .8,.83,.66,1.9,1.1,.996, 6539 .9,.36,.32,1.4,.74,.992, 6540 .8,.88,.7,.8,.176,.982, 6541 1,.87,.87,.7,1.053,.986, 6542 .9,.75,.68,1.3,.519,.98, 6543 1,.65,.65,.6,.519,.982, 6544 .95,.97,.92,1,1.23,.992, 6545 .95,.87,.83,1.9,1.354,1.02, 6546 1,.45,.45,.8,.322,.999, 6547 .95,.36,.34,.5,0,1.038, 6548 .85,.39,.33,.7,.279,.988, 6549 .7,.76,.53,1.2,.146,.982, 6550 .8,.46,.37,.4,.38,1.006, 6551 .2,.39,.08,.8,.114,.99, 6552 1,.9,.9,1.1,1.037,.99, 6553 1,.84,.84,1.9,2.064,1.02, 6554 .65,.42,.27,.5,.114,1.014, 6555

Page 84:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

1,.75,.75,1,1.322,1.004, 6556 .5,.44,.22,.6,.114,.99, 6557 1,.63,.63,1.1,1.072,.986, 6558 1,.33,.33,.4,.176,1.01, 6559 .9,.93,.84,.6,1.591,1.02, 6560 1,.58,.58,1,.531,1.002, 6561 .95,.32,.3,1.6,.886,.988, 6562 1,.6,.6,1.7,.964,.99, 6563 1,.69,.69,.9,.398,.986, 6564 1,.73,.73,.7,.398,.986); 6565 # response = remiss 6566 y=c(1,1,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1,0); 6567 }, 6568 { #16 Finney vasoconstriction 39X2 data 6569 #predictors = LogVolume, logRate (both - of air intake) 6570 x=c( 6571 3.70,0.825, 6572 3.50,1.09, 6573 1.25,2.50, 6574 0.75,1.50, 6575 0.80,3.20, 6576 0.70,3.50, 6577 0.60,0.75, 6578 1.10,1.70, 6579 0.90,0.75, 6580 0.90,0.45, 6581 0.80,0.57, 6582 0.55,2.75, 6583 0.60,3.00, 6584 1.40,2.33, 6585 0.75,3.75, 6586 2.30,1.64, 6587 3.20,1.60, 6588 0.85,1.415, 6589 1.70,1.06, 6590 1.80,1.80, 6591 0.40,2.00, 6592 0.95,1.36, 6593 1.35,1.35, 6594 1.50,1.36, 6595 1.60,1.78, 6596 0.60,1.50, 6597 1.80,1.50, 6598 0.95,1.90, 6599 1.90,0.95, 6600 1.60,0.40, 6601 2.70,0.75, 6602 2.35,0.03, 6603 1.10,1.83, 6604 1.10,2.20, 6605 1.20,2.00, 6606 0.80,3.33, 6607 0.95,1.90, 6608 0.75,1.90, 6609 1.30,1.625); 6610 6611 # response = constriction (1), no constriction (0) (both vaso) 6612 y=c(1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,1,1,1,0,0,1); 6613 }, 6614 { #17 Food Stamp Data 6615 # predictors = tenancy suppl.income income 6616 x=c(1,0,271, 6617 1,0,287, 6618 1,1,714, 6619 1,0,521, 6620 0,0,0, 6621 1,0,518, 6622 1,0,458, 6623 1,0,1266, 6624 0,0,350, 6625 1,0,168, 6626 1,0,235, 6627 0,0,450, 6628 1,0,683, 6629 1,0,519, 6630 1,0,477, 6631 1,0,2697, 6632 0,1,184, 6633 1,1,220, 6634

Page 85:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

0,0,581, 6635 1,0,212, 6636 0,0,285, 6637 1,1,188, 6638 0,1,264, 6639 0,1,169, 6640 0,1,198, 6641 0,0,196, 6642 1,1,797, 6643 1,0,435, 6644 1,0,1202, 6645 1,0,4533, 6646 0,1,356, 6647 0,0,372, 6648 0,1,453, 6649 0,0,1427, 6650 1,0,477, 6651 1,0,1980, 6652 1,0,1170, 6653 1,0,385, 6654 1,0,1661, 6655 0,0,885, 6656 1,0,379, 6657 0,0,735, 6658 1,0,580, 6659 0,0,201, 6660 1,0,500, 6661 1,0,449, 6662 1,1,373, 6663 1,0,607, 6664 1,0,211, 6665 1,0,235, 6666 0,1,386, 6667 0,0,176, 6668 1,0,233, 6669 1,1,1765, 6670 0,0,430, 6671 1,0,1061, 6672 0,1,534, 6673 0,1,540, 6674 0,1,200, 6675 1,0,3525, 6676 1,1,2165, 6677 0,1,177, 6678 1,0,465, 6679 1,1,476, 6680 1,0,589, 6681 1,0,1200, 6682 1,0,440, 6683 0,0,893, 6684 1,0,471, 6685 0,1,125, 6686 1,0,1251, 6687 1,0,2556, 6688 0,0,150, 6689 1,0,429, 6690 0,0,286, 6691 1,0,3556, 6692 0,0,893, 6693 1,1,230, 6694 0,0,586, 6695 1,0,307, 6696 1,0,482, 6697 1,0,1504, 6698 1,0,1680, 6699 1,1,354, 6700 1,0,1445, 6701 0,0,242, 6702 0,0,613, 6703 0,1,266, 6704 1,0,167, 6705 1,0,426, 6706 1,1,187, 6707 1,0,197, 6708 1,0,346, 6709 0,0,203, 6710 0,0,704, 6711 1,0,107, 6712 1,0,1578, 6713

Page 86:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

1,0,295, 6714 1,0,1653, 6715 1,0,523, 6716 1,0,1445, 6717 0,1,443, 6718 1,1,291, 6719 1,0,596, 6720 1,1,476, 6721 0,1,334, 6722 0,0,197, 6723 0,1,575, 6724 0,1,977, 6725 1,0,1410, 6726 1,0,943, 6727 1,0,697, 6728 0,1,221, 6729 1,1,296, 6730 1,1,489, 6731 0,1,274, 6732 1,0,233, 6733 1,0,992, 6734 1,0,444, 6735 1,1,250, 6736 1,0,260, 6737 1,0,460, 6738 1,0,495, 6739 1,0,260, 6740 1,1,517, 6741 0,0,520, 6742 0,0,512, 6743 1,1,285, 6744 1,0,664, 6745 0,0,462, 6746 0,0,685, 6747 0,0,452, 6748 1,0,1143, 6749 1,0,1715, 6750 0,1,248, 6751 1,0,459, 6752 1,0,499, 6753 1,1,273, 6754 0,0,611, 6755 1,0,84, 6756 0,0,205, 6757 1,0,2331, 6758 1,0,1228, 6759 1,1,1179, 6760 1,0,1170, 6761 1,0,2995, 6762 1,0,273, 6763 1,0,196, 6764 1,1,1644, 6765 0,0,214); 6766 6767 # response = participation 6768 y=c( 6769 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0, 6770 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0, 6771 1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0, 6772 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0, 6773 0,0,1,0,0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0, 6774 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1); 6775 }, 6776 { # 18 Hosmer & Lemeshaw low birth weight 189X8 6777 # predictors = 6778 # age: mother's age in years 6779 # lwt: mother's weight in pounds at last menstrual period 6780 # race: mothers race ("white=1", "black=2", "other=3") 6781 # smoke: smoking status during pregnancy 6782 # ht: history of hypertension 6783 # ui: presence of uterine irritability 6784 # ftv: number of physician visits during the first trimester 6785 # ptl: number of previous premature labours 6786 6787 x=c( 6788 19,182,2,0,0,1,0,0, 6789 33,155,3,0,0,0,1,0, 6790 20,105,1,1,0,0,1,0, 6791 21,108,1,1,0,1,1,0, 6792

Page 87:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

18,107,1,1,0,1,0,0, 6793 21,124,3,0,0,0,0,0, 6794 22,118,1,0,0,0,1,0, 6795 17,103,3,0,0,0,1,0, 6796 29,123,1,1,0,0,1,0, 6797 26,113,1,1,0,0,0,0, 6798 19,95,3,0,0,0,0,0, 6799 19,150,3,0,0,0,1,0, 6800 22,95,3,0,1,0,0,0, 6801 30,107,3,0,0,1,1,1, 6802 18,100,1,1,0,0,0,0, 6803 18,100,1,1,0,0,0,0, 6804 15,98,2,0,0,0,0,0, 6805 25,118,1,1,0,0,1,0, 6806 20,120,3,0,0,1,0,0, 6807 28,120,1,1,0,0,1,0, 6808 32,101,3,0,0,0,1,0, 6809 31,100,1,0,0,1,1,0, 6810 36,202,1,0,0,0,1,0, 6811 28,120,3,0,0,0,0,0, 6812 25,120,3,0,0,1,1,0, 6813 28,167,1,0,0,0,0,0, 6814 17,122,1,1,0,0,0,0, 6815 29,150,1,0,0,0,1,0, 6816 26,168,2,1,0,0,0,0, 6817 17,113,2,0,0,0,1,0, 6818 17,113,2,0,0,0,1,0, 6819 24,90,1,1,0,0,1,1, 6820 35,121,2,1,0,0,1,1, 6821 25,155,1,0,0,0,1,0, 6822 25,125,2,0,0,0,0,0, 6823 29,140,1,1,0,0,1,0, 6824 19,138,1,1,0,0,1,0, 6825 27,124,1,1,0,0,0,0, 6826 31,215,1,1,0,0,1,0, 6827 33,109,1,1,0,0,1,0, 6828 21,185,2,1,0,0,1,0, 6829 19,189,1,0,0,0,1,0, 6830 23,130,2,0,0,0,1,0, 6831 21,160,1,0,0,0,0,0, 6832 18,90,1,1,0,1,0,0, 6833 18,90,1,1,0,1,0,0, 6834 32,132,1,0,0,0,1,0, 6835 19,132,3,0,0,0,0,0, 6836 24,115,1,0,0,0,1,0, 6837 22,85,3,1,0,0,0,0, 6838 22,120,1,0,1,0,1,0, 6839 23,128,3,0,0,0,0,0, 6840 22,130,1,1,0,0,0,0, 6841 30,95,1,1,0,0,1,0, 6842 19,115,3,0,0,0,0,0, 6843 16,110,3,0,0,0,0,0, 6844 21,110,3,1,0,1,0,0, 6845 30,153,3,0,0,0,0,0, 6846 20,103,3,0,0,0,0,0, 6847 17,119,3,0,0,0,0,0, 6848 17,119,3,0,0,0,0,0, 6849 23,119,3,0,0,0,1,0, 6850 24,110,3,0,0,0,0,0, 6851 28,140,1,0,0,0,0,0, 6852 26,133,3,1,0,0,0,1, 6853 20,169,3,0,0,1,1,1, 6854 24,115,3,0,0,0,1,0, 6855 28,250,3,1,0,0,1,0, 6856 20,141,1,0,0,1,1,1, 6857 22,158,2,0,0,0,1,1, 6858 22,112,1,1,0,0,0,1, 6859 31,150,3,1,0,0,1,0, 6860 23,115,3,1,0,0,1,0, 6861 16,112,2,0,0,0,0,0, 6862 16,135,1,1,0,0,0,0, 6863 18,229,2,0,0,0,0,0, 6864 25,140,1,0,0,0,1,0, 6865 32,134,1,1,0,0,1,1, 6866 20,121,2,1,0,0,0,0, 6867 23,190,1,0,0,0,0,0, 6868 22,131,1,0,0,0,1,0, 6869 32,170,1,0,0,0,0,0, 6870 30,110,3,0,0,0,0,0, 6871

Page 88:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

20,127,3,0,0,0,0,0, 6872 23,123,3,0,0,0,0,0, 6873 17,120,3,1,0,0,0,0, 6874 19,105,3,0,0,0,0,0, 6875 23,130,1,0,0,0,0,0, 6876 36,175,1,0,0,0,0,0, 6877 22,125,1,0,0,0,1,0, 6878 24,133,1,0,0,0,0,0, 6879 21,134,3,0,0,0,1,0, 6880 19,235,1,1,1,0,0,0, 6881 25,95,1,1,0,1,0,1, 6882 16,135,1,1,0,0,0,0, 6883 29,135,1,0,0,0,1,0, 6884 29,154,1,0,0,0,1,0, 6885 19,147,1,1,0,0,0,0, 6886 19,147,1,1,0,0,0,0, 6887 30,137,1,0,0,0,1,0, 6888 24,110,1,0,0,0,1,0, 6889 19,184,1,1,1,0,0,0, 6890 24,110,3,0,0,0,0,1, 6891 23,110,1,0,0,0,1,0, 6892 20,120,3,0,0,0,0,0, 6893 25,241,2,0,1,0,0,0, 6894 30,112,1,0,0,0,1,0, 6895 22,169,1,0,0,0,0,0, 6896 18,120,1,1,0,0,1,0, 6897 16,170,2,0,0,0,1,0, 6898 32,186,1,0,0,0,1,0, 6899 18,120,3,0,0,0,1,0, 6900 29,130,1,1,0,0,1,0, 6901 33,117,1,0,0,1,1,0, 6902 20,170,1,1,0,0,0,0, 6903 28,134,3,0,0,0,1,0, 6904 14,135,1,0,0,0,0,0, 6905 28,130,3,0,0,0,0,0, 6906 25,120,1,0,0,0,1,0, 6907 16,95,3,0,0,0,1,0, 6908 20,158,1,0,0,0,1,0, 6909 26,160,3,0,0,0,0,0, 6910 21,115,1,0,0,0,1,0, 6911 22,129,1,0,0,0,0,0, 6912 25,130,1,0,0,0,1,0, 6913 31,120,1,0,0,0,1,0, 6914 35,170,1,0,0,0,1,1, 6915 19,120,1,1,0,0,0,0, 6916 24,116,1,0,0,0,1,0, 6917 45,123,1,0,0,0,1,0, 6918 28,120,3,1,0,1,0,1, 6919 29,130,1,0,0,1,1,0, 6920 34,187,2,1,1,0,0,0, 6921 25,105,3,0,1,0,0,1, 6922 25,85,3,0,0,1,0,0, 6923 27,150,3,0,0,0,0,0, 6924 23,97,3,0,0,1,1,0, 6925 24,124,2,0,0,0,1,1, 6926 24,132,3,0,1,0,0,0, 6927 21,165,1,1,1,0,1,0, 6928 32,105,1,1,0,0,0,0, 6929 19,91,1,1,0,1,0,1, 6930 25,115,3,0,0,0,0,0, 6931 16,130,3,0,0,0,1,0, 6932 25,92,1,1,0,0,0,0, 6933 20,150,1,1,0,0,1,0, 6934 21,200,2,0,0,1,1,0, 6935 24,155,1,1,0,0,0,1, 6936 21,103,3,0,0,0,0,0, 6937 20,125,3,0,0,1,0,0, 6938 25,89,3,0,0,0,1,1, 6939 19,102,1,0,0,0,1,0, 6940 19,112,1,1,0,1,0,0, 6941 26,117,1,1,0,0,0,1, 6942 24,138,1,0,0,0,0,0, 6943 17,130,3,1,0,1,0,1, 6944 20,120,2,1,0,0,1,0, 6945 22,130,1,1,0,1,1,1, 6946 27,130,2,0,0,1,0,0, 6947 20,80,3,1,0,1,0,0, 6948 17,110,1,1,0,0,0,0, 6949 25,105,3,0,0,0,1,1, 6950

Page 89:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

20,109,3,0,0,0,0,0, 6951 18,148,3,0,0,0,0,0, 6952 18,110,2,1,0,0,0,1, 6953 20,121,1,1,0,1,0,1, 6954 21,100,3,0,0,0,1,1, 6955 26,96,3,0,0,0,0,0, 6956 31,102,1,1,0,0,1,1, 6957 15,110,1,0,0,0,0,0, 6958 23,187,2,1,0,0,1,0, 6959 20,122,2,1,0,0,0,0, 6960 24,105,2,1,0,0,0,0, 6961 15,115,3,0,0,1,0,0, 6962 23,120,3,0,0,0,0,0, 6963 30,142,1,1,0,0,0,1, 6964 22,130,1,1,0,0,1,0, 6965 17,120,1,1,0,0,1,0, 6966 23,110,1,1,0,0,0,1, 6967 17,120,2,0,0,0,1,0, 6968 26,154,3,0,1,0,1,1, 6969 20,105,3,0,0,0,1,0, 6970 26,190,1,1,0,0,0,0, 6971 14,101,3,1,0,0,0,1, 6972 28,95,1,1,0,0,1,0, 6973 14,100,3,0,0,0,1,0, 6974 23,94,3,1,0,0,0,0, 6975 17,142,2,0,1,0,0,0, 6976 21,130,1,1,1,0,1,0); 6977 6978 y=c( 6979 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6980 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6981 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6982 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6983 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6984 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6985 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 6986 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 6987 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); 6988 6989 bt=c( 6990 2523,2551,2557,2594,2600,2622,2637,2637,2663,2665, 6991 2722,2733,2750,2750,2769,2769,2778,2782,2807,2821, 6992 2835,2835,2836,2863,2877,2877,2906,2920,2920,2920, 6993 2920,2948,2948,2977,2977,2977,2977,2992,3005,3033, 6994 3042,3062,3062,3062,3076,3076,3080,3090,3090,3090, 6995 3100,3104,3132,3147,3175,3175,3203,3203,3203,3225, 6996 3225,3232,3232,3234,3260,3274,3274,3303,3317,3317, 6997 3317,3321,3331,3374,3374,3402,3416,3430,3444,3459, 6998 3460,3473,3475,3487,3544,3572,3572,3586,3600,3614, 6999 3614,3629,3629,3637,3643,3651,3651,3651,3651,3699, 7000 3728,3756,3770,3770,3770,3790,3799,3827,3856,3860, 7001 3860,3884,3884,3912,3940,3941,3941,3969,3983,3997, 7002 3997,4054,4054,4111,4153,4167,4174,4238,4593,4990, 7003 709,1021,1135,1330,1474,1588,1588,1701,1729,1790, 7004 1818,1885,1893,1899,1928,1928,1928,1936,1970,2055, 7005 2055,2082,2084,2084,2100,2125,2126,2187,2187,2211, 7006 2225,2240,2240,2282,2296,2296,2301,2325,2353,2353, 7007 2367,2381,2381,2381,2395,2410,2410,2414,2424,2438, 7008 2442,2450,2466,2466,2466,2495,2495,2495,2495); 7009 }, 7010 { 7011 # 19, IVC data (orig had 3500 lines of data) This is just with no repeats 7012 x=c( 7013 1.5, 0, 0, 0, 7014 1.5, 0, 0, 0, 7015 1.5, 0, 0, 1, 7016 1.5, 0, 0, 1, 7017 1.5, 1, 0, 0, 7018 1.5, 1, 0, 0, 7019 1.5, 1, 0, 1, 7020 1.5, 1, 0, 1, 7021 1.5, 0, 1, 0, 7022 1.5, 0, 1, 0, 7023 1.5, 0, 1, 1, 7024 1.5, 0, 1, 1, 7025 2.5, 0, 0, 0, 7026 2.5, 0, 0, 0, 7027 2.5, 0, 0, 1, 7028 2.5, 0, 0, 1, 7029

Page 90:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

2.5, 1, 0, 0, 7030 2.5, 1, 0, 0, 7031 2.5, 1, 0, 1, 7032 2.5, 1, 0, 1, 7033 2.5, 0, 1, 0, 7034 2.5, 0, 1, 0, 7035 2.5, 0, 1, 1, 7036 2.5, 0, 1, 1, 7037 3.5, 0, 0, 0, 7038 3.5, 0, 0, 0, 7039 3.5, 0, 0, 1, 7040 3.5, 0, 0, 1, 7041 3.5, 1, 0, 0, 7042 3.5, 1, 0, 0, 7043 3.5, 1, 0, 1, 7044 3.5, 1, 0, 1, 7045 3.5, 0, 1, 0, 7046 3.5, 0, 1, 0, 7047 3.5, 0, 1, 1, 7048 3.5, 0, 1, 1, 7049 4.5, 0, 0, 0, 7050 4.5, 0, 0, 0, 7051 4.5, 0, 0, 1, 7052 4.5, 0, 0, 1, 7053 4.5, 1, 0, 0, 7054 4.5, 1, 0, 0, 7055 4.5, 1, 0, 1, 7056 4.5, 1, 0, 1, 7057 4.5, 0, 1, 0, 7058 4.5, 0, 1, 0, 7059 4.5, 0, 1, 1, 7060 4.5, 0, 1, 1, 7061 5.5, 0, 0, 0, 7062 5.5, 0, 0, 0, 7063 5.5, 0, 0, 1, 7064 5.5, 0, 0, 1, 7065 5.5, 1, 0, 0, 7066 5.5, 1, 0, 0, 7067 5.5, 1, 0, 1, 7068 5.5, 1, 0, 1, 7069 5.5, 0, 1, 0, 7070 5.5, 0, 1, 0, 7071 5.5, 0, 1, 1, 7072 5.5, 0, 1, 1, 7073 6.5, 0, 0, 0, 7074 6.5, 0, 0, 0, 7075 6.5, 0, 0, 1, 7076 6.5, 0, 0, 1, 7077 6.5, 1, 0, 0, 7078 6.5, 1, 0, 0, 7079 6.5, 1, 0, 1, 7080 6.5, 1, 0, 1, 7081 6.5, 0, 1, 0, 7082 6.5, 0, 1, 0, 7083 6.5, 0, 1, 1, 7084 6.5, 0, 1, 1, 7085 7.5, 0, 0, 0, 7086 7.5, 0, 0, 0, 7087 7.5, 0, 0, 1, 7088 7.5, 0, 0, 1, 7089 7.5, 1, 0, 0, 7090 7.5, 1, 0, 0, 7091 7.5, 1, 0, 1, 7092 7.5, 1, 0, 1, 7093 7.5, 0, 1, 0, 7094 7.5, 0, 1, 0, 7095 7.5, 0, 1, 1, 7096 7.5, 0, 1, 1, 7097 8.5, 0, 0, 0, 7098 8.5, 0, 0, 0, 7099 8.5, 0, 0, 1, 7100 8.5, 0, 0, 1, 7101 8.5, 1, 0, 0, 7102 8.5, 1, 0, 0, 7103 8.5, 1, 0, 1, 7104 8.5, 1, 0, 1, 7105 8.5, 0, 1, 0, 7106 8.5, 0, 1, 0, 7107 8.5, 0, 1, 1, 7108

Page 91:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

8.5, 0, 1, 1); 7109 # response = 7110 y=rep(c(0,1),48) 7111 }, 7112 { 7113 x=c(-1,0,-1,0,1,0,1,0,0,sqrt(3),0,sqrt(3)); 7114 y=c(0,1,0,1,0,1); 7115 } 7116 ) 7117 7118 ny=length(y) 7119 nc=length(x)/ny 7120 x=matrix(x,byrow=T,ncol=nc); 7121 7122 rid=1:length(y); 7123 if(all(remo > 0) & all(remo <= ny)) {x=x[-remo,]; y=y[-remo]; rid=rid[-remo];} 7124 return(list(x=x,y=y,rid=rid)) 7125 } 7126 7127 cnect=function(x1,y1,x2,y2,r) 7128 { 7129 m=(y2-y1)/(x2-x1); 7130 ang=atan(m) 7131 xx1=x1+r*sin(ang+pi/2) 7132 yy1=y1-r*cos(ang+pi/2) 7133 xx2=x2+r*sin(ang-pi/2) 7134 yy2=y2-r*cos(ang-pi/2) 7135 lines(c(xx1,xx2),c(yy1,yy2),type="l",lwd=2,col=8) 7136 } 7137 7138 ptty=function(x0,y0,typ,r=.05) 7139 { 7140 lw=1.6 7141 r2=2*r/3 7142 pm=c(-1,1) 7143 z=seq(0,2*pi,length=1000) 7144 x=sin(z) 7145 y=cos(z) 7146 lines(x0+r*x,y0+r*y,type="l",lwd=2,col=8) 7147 if(typ == 0 | typ == 2)lines(x0+r2*x,y0+r2*y,type="l",lwd=2) 7148 if(typ == 1 | typ == 2) 7149 { 7150 u=pi*pm/4; 7151 for(i in 1:2) 7152 { 7153 xx=x0+r2*sin(u[i])*pm 7154 yy=y0+r2*cos(u[i])*pm 7155 lines(xx,yy,type="l",lwd=2) 7156 } 7157 } 7158 7159 } 7160 7161 gridplot=function(ipl) 7162 { 7163 if(!is.element(ipl,c(1,2,3))){cat(paste("Arguments to gridplot can only be 1, 2 or 3 \n\n",sep="")); 7164 return();} 7165 del=.2; cx=1.5; 7166 plot(c(1,2,3),c(1,1,1),pch=c(1,4,13)) 7167 points(c(1,2,3,3),del+c(1,1,1,1),pch=c(1,4,1,4),cex=c(cx,cx,cx,cx),lwd=2) 7168 7169 z=seq(0,2*pi,length=1000) 7170 x=sin(z) 7171 y=cos(z) 7172 r=.2 7173 7174 par(pin=c(5,5)) 7175 7176 plot(c(-1,-1,1,1),c(-1,1,-1,1),type="n",xaxt="n",yaxt="n",bty="n") 7177 7178 if(ipl == 1) 7179 { 7180 mtext("Three Possible Single Point Outcomes",side=3,line=-1.8,cex=1.3) 7181 dy=.2 7182 l1=1-dy 7183 7184 ptty(.5,l1,0) 7185 text(-.9,l1," (a) All non-responses",adj=0) 7186 7187

Page 92:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

l2=.85-dy 7188 ptty(.5,l2,1) 7189 text(-.9,l2," (b) All responses",adj=0) 7190 7191 l3=.7-dy 7192 ptty(.5,l3,2) 7193 text(-.9,l3," (c) A Mix of non-responses & responses",adj=0) 7194 7195 7196 mtext("Six Primitive d = 1 Configurations",side=3,line=-11,cex=1.3) 7197 dy=1 7198 dx=.3 7199 l3=1-dy 7200 ptty(-.3+dx,l3,0) 7201 ptty(.5+dx,l3,0) 7202 cnect(-.3+dx,l3,.5+dx,l3,.05) 7203 text(-.9,l3," (d) no mixed results",adj=0) 7204 7205 l3=.85-dy 7206 ptty(-.3+dx,l3,0) 7207 ptty(.5+dx,l3,1) 7208 cnect(-.3+dx,l3,.5+dx,l3,.05) 7209 text(-.9,l3," (e) complete separation",adj=0) 7210 7211 l3=.7-dy 7212 ptty(-.3+dx,l3,0) 7213 ptty(.5+dx,l3,2) 7214 cnect(-.3+dx,l3,.5+dx,l3,.05) 7215 text(-.9,l3," (f) quasi separation",adj=0) 7216 7217 l3=.55-dy 7218 ptty(-.3+dx,l3,2) 7219 ptty(.5+dx,l3,0) 7220 cnect(-.3+dx,l3,.5+dx,l3,.05) 7221 text(-.9,l3," (g) quasi separation",adj=0) 7222 7223 l3=.40-dy 7224 ptty(-.3+dx,l3,0) 7225 ptty(0+dx,l3,1) 7226 ptty(.5+dx,l3,0) 7227 cnect(-.3+dx,l3,0+dx,l3,.05) 7228 cnect(0+dx,l3,.5+dx,l3,.05) 7229 text(-.9,l3," (h) overlap",adj=0) 7230 7231 l3=.25-dy 7232 ptty(-.3+dx,l3,2) 7233 ptty(.5+dx,l3,2) 7234 cnect(-.3+dx,l3,.5+dx,l3,.05) 7235 text(-.9,l3," (i) overlap",adj=0) 7236 d0=.1 7237 } 7238 7239 if(ipl == 2) 7240 { 7241 mtext("Overlap in Dimension 1 (per [27])",side=3,line=-1.8,cex=1.3) 7242 dx=0 7243 dy=.2 7244 l1=1-dy 7245 dl=.8/3 7246 7247 ptty(-.3+dx,l1,0) 7248 ptty(-.3+dx+dl,l1,1) 7249 ptty(-.3+dx+2*dl,l1,0) 7250 ptty(-.3+dx+3*dl,l1,1) 7251 7252 cnect(-.3+dx,l1,-.3+dx+dl,l1,.05) 7253 cnect(-.3+dx+dl,l1,-.3+dx+2*dl,l1,.05) 7254 cnect(-.3+dx+2*dl,l1,-.3+dx+3*dl,l1,.05) 7255 text(-.9,l1," equation (2)",adj=0) 7256 7257 l3=.85-dy 7258 7259 ptty(-.3+dx,l3,0) 7260 ptty(0+dx,l3,1) 7261 ptty(.5+dx,l3,0) 7262 cnect(-.3+dx,l3,0+dx,l3,.05) 7263 cnect(0+dx,l3,.5+dx,l3,.05) 7264 text(-.9,l3," text",adj=0) 7265 7266

Page 93:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

l3=.7-dy 7267 ptty(-.3+dx,l3,0) 7268 ptty(.5+dx,l3,2) 7269 cnect(-.3+dx,l3,.5+dx,l3,.05) 7270 text(-.9,l3," equation (3)",adj=0) 7271 7272 l3=.55-dy 7273 ptty(-.3+dx,l3,2) 7274 ptty(.5+dx,l3,0) 7275 cnect(-.3+dx,l3,.5+dx,l3,.05) 7276 text(-.9,l3," equation (3)",adj=0) 7277 } 7278 7279 if(ipl == 3) 7280 { 7281 # ------------------------------------------------------------------- 7282 dx=.1 7283 dx=0 7284 7285 d=0; u=.2; v=.3 7286 d=.1 7287 ptty(dx-2*u-v,u-d,0) 7288 ptty(dx-u-v,u*(1+sqrt(3))-d,0) 7289 ptty(dx+0-v,u-d,0) 7290 l3=u*(1+sqrt(3)/2)-d 7291 text(-1,l3," d = 2",cex=1.2) 7292 l3=l3-.05 7293 ptty(dx-u-v,l3,1) 7294 cnect(dx-2*u-v,u-d,dx-u-v,u*(1+sqrt(3))-d,.05) 7295 cnect(dx-u-v,u*(1+sqrt(3))-d,dx+0-v,u-d,.05) 7296 cnect(dx-2*u-v,u-d,dx+0-v,u-d,.05) 7297 7298 d=0; u=.2; v=.3-1.2 7299 d=.1 7300 ptty(dx-2*u-v,u-d,2) 7301 ptty(dx-u-v,u*(1+sqrt(3))-d,2) 7302 ptty(dx+0-v,u-d,2) 7303 l3=u*(1+sqrt(3)/2)-d 7304 cnect(dx-2*u-v,u-d,dx-u-v,u*(1+sqrt(3))-d,.05) 7305 cnect(dx-u-v,u*(1+sqrt(3))-d,dx+0-v,u-d,.05) 7306 cnect(dx-2*u-v,u-d,dx+0-v,u-d,.05) 7307 7308 d=0; u=.2; v=.3-.65+.25 7309 d=.1 7310 ptty(dx-u-v,u*(1+sqrt(3))-d,0) 7311 ptty(dx+0-v,u-d,0) 7312 l3=u*(1+sqrt(3)/2)-d 7313 l3=l3-.05 7314 ptty(dx-u-v,l3,1) 7315 ptty(dx-u-v+.45,u+.25,1) 7316 cnect(dx-u-v,u*(1+sqrt(3))-d,dx+0-v,u-d,.05) 7317 cnect(dx-u-v,l3,dx-u-v+.45,u+.25,.05) 7318 7319 # ------------------------------------------------------------------- 7320 7321 d=.8 7322 u=.2; v=.3 7323 7324 ptty(dx-2*u-v,u-d+.02,0) 7325 ptty(dx-u-v,u*(1+sqrt(3))-d,0) 7326 ptty(dx+0-v,u-d-.04,0) 7327 l3=u*(1+sqrt(3)/2)-d 7328 text(-1,l3," d = 3",cex=1.2) 7329 l3=l3-.05 7330 ptty(dx-u-v+.2,l3,0) 7331 cnect(dx-2*u-v,u-d+.02,dx-u-v,u*(1+sqrt(3))-d,.05) 7332 cnect(dx-u-v,u*(1+sqrt(3))-d,dx+0-v,u-d-.04,.05) 7333 cnect(dx-2*u-v,u-d+.02,dx+0-v,u-d-.04,.05) 7334 cnect(dx-2*u-v,u-d+.02,dx-u-v+.2,l3,.05) 7335 cnect(dx-u-v,u*(1+sqrt(3))-d,dx-u-v+.2,l3,.05) 7336 cnect(dx-u-v+.2,l3,dx+0-v,u-d-.04,.05) 7337 ptty(dx-u-v+.02,l3,1) 7338 7339 u=.2; v=.3-1.2 7340 7341 ptty(dx-2*u-v,u-d+.02,2) 7342 ptty(dx-u-v,u*(1+sqrt(3))-d,2) 7343 ptty(dx+0-v,u-d-.04,2) 7344 l3=u*(1+sqrt(3)/2)-d 7345

Page 94:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

l3=l3-.05 7346 ptty(dx-u-v+.2,l3,2) 7347 cnect(dx-2*u-v,u-d+.02,dx-u-v,u*(1+sqrt(3))-d,.05) 7348 cnect(dx-u-v,u*(1+sqrt(3))-d,dx+0-v,u-d-.04,.05) 7349 cnect(dx-2*u-v,u-d+.02,dx+0-v,u-d-.04,.05) 7350 cnect(dx-2*u-v,u-d+.02,dx-u-v+.2,l3,.05) 7351 cnect(dx-u-v,u*(1+sqrt(3))-d,dx-u-v+.2,l3,.05) 7352 cnect(dx+0-v,u-d-.04,dx-u-v+.2,l3,.05) 7353 7354 u=.2; v=.3-.65+.25 7355 7356 ptty(dx-u-v,u*(1+sqrt(3))-d,0) 7357 ptty(dx+0-v,u-d,0) 7358 l7=.18 7359 ptty(dx-u-v+.30,u*(1+sqrt(3))-d-l7,0) 7360 l3=u*(1+sqrt(3)/2)-d 7361 l3=l3-.05 7362 ptty(dx-u-v,l3,1) 7363 ptty(dx-u-v+.45,u+.25-d,1) 7364 cnect(dx-u-v,u*(1+sqrt(3))-d,dx+0-v,u-d,.05) 7365 cnect(dx-u-v,l3,dx-u-v+.45,u+.25-d,.05) 7366 cnect(dx-u-v,u*(1+sqrt(3))-d,dx-u-v+.30,u*(1+sqrt(3))-d-l7,.05) 7367 cnect(dx+0-v,u-d,dx-u-v+.30,u*(1+sqrt(3))-d-l7,.05) 7368 7369 xc=c(-.425,.225,.775,-.425,.225,.775); xc=xc-.1; 7370 yc=c(0,0,0,-.75,-.75,-.75); 7371 ge=c("(j)","(k)","(l)","(m)","(n)","(o)"); 7372 7373 for(i in 1:6) text(xc[i],yc[i],ge[i],adj=0) 7374 7375 lam=.6 7376 xm= .45*(1-lam)-u-v 7377 ym=lam*l3+(1-lam)*(u+.25-d) 7378 points(dx+xm,ym,pch=16,cex=.8,col=8) 7379 7380 a1=expression(paste( 7381 paste("Minimal Configurations: d+2 "<=" n",sep=""), 7382 paste(" "<=" 2(d+1)",sep=""),sep="") 7383 ) 7384 7385 a1=paste("Primitive Overlap Configurations",sep=""); 7386 7387 mtext(side=3,a1,line=-6.5,cex=1.3,outer=T) 7388 7389 } 7390 7391 par(pin=c(4.395417, 3.785000)) 7392 return() 7393 } 7394 7395 #INDEX 131 exes.R, (1 function) 7396 7397 otp=function(i) 7398 { 7399 if(!is.element(i,1:44)) cat(paste("otp function wants i between 1 and 44 \n\n",sep="")); 7400 7401 xWU <<- c(5.5,16.5,11,13.8,10.1,14.7,10.4,11.7,9.7,7.3,7.8,8.1,12.2,8.5,11.8, 7402 11.7106,11.4896,11.2980,12.3899,12.2393,12.1033,11.9796,11.8660,11.7612,11.6638,11.5730,11.4878, 7403 11.4077,11.3321,11.2605,11.1925); 7404 yWU <<- c(0,1,0,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0); 7405 yNY <<- c(rep(0,5),1,rep(0,6),1,0,1,0,1,1,1,1); 7406 ywLG1 <<- c(1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0); 7407 7408 exi=list( 7409 "w1 <<- gonogoSim(0,22,3,6,15,.9,1,plt=1,reso=.01,iseed=42983)", 7410 7411 "if(!exists(\"w1\")) w1 <<- gonogoSim(0,22,3,6,15,.9,1,plt=0,reso=.01,iseed=42983); w1$d0", 7412 7413 "if(!exists(\"w1\")) w1 <<- gonogoSim(0,22,3,6,15,.9,1,plt=0,reso=.01,iseed=42983); 7414 yW=w1$d0$Y; w2 <<- gonogo(0,22,3,test=1,reso=.01,Y=yW)", 7415 7416 "if(exists(\"wWU\")) {wWU$ttl0 <<- \"Wu & Tian Table 1 Example\"; ptest(wWU,1);} else wWU <<- 7417 gonogo(0,22,3,reso=.0001,Y=yWU)", 7418 7419 "if(!exists(\"wWU\")) wWU <<- gonogo(0,22,3,reso=.0001,Y=yWU) else {wWU$title=\"3pod: Wu & Tian Table 1 7420 Example\"; 7421 wWU$ttl0=\"Wu & Tian Table 1 Example\";wWU$units=\"in\"; wWU}", 7422 7423 "if(exists(\"wNY\"))wNY$d0 else wNY <<- gonogo(.6,1.4,.1,test=2,reso=.01,Y=yNY); wNY$d0;", 7424

Page 95:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

7425 "if(exists(\"wNY\")){wNY$title=\"Neyer: 1994 Table 1 Example\"; 7426 wNY$ttl0=\"1994 Table 1 Example\";wNY$units=\"in\"; ptest(wNY,1)} else 7427 wNY <<- gonogo(.6,1.4,.1,test=2,reso=.01,Y=yNY);", 7428 7429 "if(exists(\"wb\")) ptest(wb,1) else wb <<- gonogoSim(10,10,.25,6,6,.9,1,plt=1,test=3,reso=.01,iseed=62517)", 7430 "if(exists(\"ub\")) ptest(ub,1) else ub <<- 7431 gonogoSim(10,10,.25,6,6,.9,1,plt=1,test=3,reso=.01,BL=c(4,2,2),iseed=62517)", 7432 "if(!exists(\"ub\")) ub <<- gonogoSim(10,10,.25,6,6,.9,1,test=3,reso=.01,BL=c(4,2,2),iseed=62517); 7433 pSdat1(ub,ud=T);", 7434 7435 "if(!exists(\"wLG2\")) wLG2 <<- gonogo(0,5,0,test=4,Y=ywLG1) else ptest(wLG2,1);", 7436 "wLG2=gonogo(0,5,0,test=4,Y=ywLG1); wLG2$d0; ", 7437 "if(!exists(\"wWU\")) wWU <<- gonogo(0,22,3,reso=.0001,Y=yWU); wWU$jvec;", 7438 "if(!exists(\"wWU\")) wWU <<- gonogo(0,22,3,reso=.0001,Y=yWU); 7439 tbl=lims(1,wWU$d0,.95,Q=8.5); tbl;", 7440 "if(!exists(\"wWU\")) wWU <<- gonogo(0,22,3,reso=.0001,Y=yWU); 7441 tbl=lims(1,wWU$d0,.95,P=al15,Q=8.5); tbl;", 7442 "blrb5();", 7443 7444 "if(!exists(\"wWU\"))wWU <<- gonogo(0,22,3,reso=.0001,Y=yWU); ptest(wWU,3); 7445 tbl=lims(1,wWU$d0,.95,P=al15,Q=8.5); 7446 points(as.vector(tbl[c(7,9),c(1,3)]), rep(tbl[c(7,9),5],2),pch=16)", 7447 7448 "gonogo(0,22,3,reso=.0001,Y=yWU[-1])", 7449 7450 "w=gonogo(0,22,3,reso=.0001,Y=yWU); 7451 m=cbind(data.frame(matrix(c(yWU,w$d0$X),ncol=2),wWU$d0$ID)); 7452 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7453 7454 "w=gonogo(0,220,30,reso=.001,Y=yWU); 7455 m=cbind(data.frame(matrix(c(yWU,w$d0$X),ncol=2),wWU$d0$ID)); 7456 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7457 7458 "w=gonogoSim(0,22,3,6,15,.9,1,reso=.0001,iseed=10); 7459 m=cbind(data.frame(matrix(c(w$d0$Y,w$d0$X),ncol=2),wWU$d0$ID)); 7460 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7461 7462 "w=gonogoSim(0,22,3,6,15,.9,1,reso=.001,iseed=10,M=10); 7463 m=cbind(data.frame(matrix(c(w$d0$Y,w$d0$X),ncol=2),wWU$d0$ID)); 7464 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7465 7466 "w=gonogo(0,22,3,reso=.0001,Y=yWU); 7467 m=cbind(data.frame(matrix(c(yWU,w$d0$X),ncol=2),wWU$d0$ID)); 7468 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7469 7470 "w=gonogo(0,220,30,reso=.001,Y=yWU); 7471 m=cbind(data.frame(matrix(c(yWU,w$d0$X),ncol=2),wWU$d0$ID)); 7472 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7473 7474 "w=gonogoSim(0,22,3,6,15,.9,.8,reso=.0001,iseed=10); 7475 m=cbind(data.frame(matrix(c(w$d0$Y,w$d0$X),ncol=2),wWU$d0$ID)); 7476 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7477 7478 "w=gonogoSim(0,22,3,6,15,.9,.8,reso=.001,iseed=10,M=10); 7479 m=cbind(data.frame(matrix(c(w$d0$Y,w$d0$X),ncol=2),wWU$d0$ID)); 7480 names(m)=c(\"Y\",\"X\",\"ID\"); m;", 7481 7482 "if(!exists(\"wWUL\"))wWUL <<- gonogo(0,22,3,reso=.0001,Y=yWU,ln=T); ptest(wWUL,1);", 7483 "if(!exists(\"wWUL\"))wWUL <<- gonogo(0,22,3,reso=.0001,Y=yWU,ln=T); ptest(wWUL,3);", 7484 7485 "if(!exists(\"w1431\"))w1431 <<- gonogoSim(583.2,816.8,29.2,20,iseed=42983,plt=0); 7486 nmel3(70,2.92,.9,30,2000,83,icirc=1431)", 7487 7488 "if(!exists(\"un\"))un <<- gonogoSim(.6,1.4,.1,6,15,.9,1,plt=1,reso=.01,test=2,iseed=4257) else ptest(un,1)", 7489 "if(!exists(\"un\"))un <<- gonogoSim(.6,1.4,.1,6,15,.9,1,plt=1,reso=.01,test=2,iseed=4257) else ptest(un,2)", 7490 "if(!exists(\"un\"))un <<- gonogoSim(.6,1.4,.1,6,15,.9,1,plt=1,reso=.01,test=2,iseed=4257) else ptest(un,3)", 7491 "if(!exists(\"un\"))un <<- gonogoSim(.6,1.4,.1,6,15,.9,1,plt=1,reso=.01,test=2,iseed=4257) else ptest(un,4)", 7492 7493 "if(!exists(\"ul\"))ul <<- gonogoSim(10,20,0,3,4,.5,1,plt=0,test=4,reso=.01,iseed=217); ptest(ul,5)", 7494 "if(!exists(\"ul\"))ul <<- gonogoSim(10,20,0,3,4,.5,1,plt=0,test=4,reso=.01,iseed=217); ptest(ul,6)", 7495 "if(!exists(\"ul\"))ul <<- gonogoSim(10,20,0,3,4,.5,1,plt=0,test=4,reso=.01,iseed=217); ptest(ul,7)", 7496 "if(!exists(\"ul\"))ul <<- gonogoSim(10,20,0,3,4,.5,1,plt=0,test=4,reso=.01,iseed=217); ptest(ul,8)", 7497 7498 "gridplot(1)", 7499 "gridplot(2)", 7500 "testdat(3)", 7501 "testdat(1)", 7502 "d3 <<- testdat(3); s3 <<- SintF(d3); s3", 7503

Page 96:  · 1 # gonogo.R 5/16/2018 (from gonogo0.R from Xtogether.R) 2 . 3 . #INDEX 1 through 35, XComm.R (35 functions) 4 . 5 . gonogo=function(mlo=0,mhi=0,sg=0,newz=T,reso=0,ln=F,test=1,ter

"d3 <<- testdat(3); mdeflate(d3)", 7504 "gridplot(3)" 7505 ); 7506 7507 dt=exi[i]; 7508 eval(parse(text=dt)); 7509 7510 } 7511