path="c:/users/dre2/desktop/DRYGINresubmission/";

dim=17;

(* Go back from exponential binning to linear scale and plot: number of points, average deviation from the linear model, variance and standard deviation. Group ABC *)

npointstot=Table[0,{dim},{dim}];
delta1tot=Table[0,{dim},{dim}];
delta2tot=Table[0,{dim},{dim}];
binxtot=Table[0,{dim}];
nxtot=Table[0,{dim}];

npoints=Import[StringJoin[path,"FILES2012/h1d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h1d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h1d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h1d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h1d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h2d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h2d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h2d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h2d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h2d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h3d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h3d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h3d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h3d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h3d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h4d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h4d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h4d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h4d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h4d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h5d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h5d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h5d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h5d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h5d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h6d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h6d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h6d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h6d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h6d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h7d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h7d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h7d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h7d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h7d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h8d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h8d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h8d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h8d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h8d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

npoints=Import[StringJoin[path,"FILES2012/h9d_npointsABC_fake_studentt.dat"]];
delta1=Import[StringJoin[path,"FILES2012/h9d_delta1ABC_fake_studentt.dat"]];
delta2=Import[StringJoin[path,"FILES2012/h9d_delta2ABC_fake_studentt.dat"]];
binx=Flatten[Import[StringJoin[path,"FILES2012/h9d_binxABC_fake_studentt.dat"]]];
nx=Flatten[Import[StringJoin[path,"FILES2012/h9d_nxABC_fake_studentt.dat"]]];

For[i=1,i≤dim,i++,
nxtot[[i]]+=nx[[i]];
binxtot[[i]]+=binx[[i]];
]
For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,
npointstot[[i,j]]+=npoints[[i,j]];
delta1tot[[i,j]]+=delta1[[i,j]];
delta2tot[[i,j]]+=delta2[[i,j]];
];
]

(* end of file reading ; begin of plotting *)

npoints=npointstot;
delta1=delta1tot;
delta2=delta2tot;
binx=binxtot;
nx=nxtot;

meanx=Table[0,{dim}];
For[i=1,i≤dim,i++,
If[nx[[i]]≠0,meanx[[i]]=((binx[[i]])/(nx[[i]])),meanx[[i]]=Null];
]

nangrid={};
eps0={};
eps1={};
eps2={};
epssigma={};
epssigma2={};

For[i=1,i≤dim,i++,
For[j=1,j≤dim,j++,

x=meanx[[i]];
y=meanx[[j]];

If[npoints[[i,j]]>1,
AppendTo[eps0,{x,y,Log[10,npoints[[i,j]]]}];
AppendTo[eps1,{x,y,((delta1[[i,j]])/(npoints[[i,j]]))}];
AppendTo[eps2,{x,y,((delta2[[i,j]])/(npoints[[i,j]]))}];
AppendTo[epssigma,{x,y,Sqrt[((delta2[[i,j]])/(npoints[[i,j]]))-(((((delta1[[i,j]])/(npoints[[i,j]]))))^2)]}];
AppendTo[epssigma2,{x,y,((delta2[[i,j]])/(npoints[[i,j]]))-(((((delta1[[i,j]])/(npoints[[i,j]]))))^2)}];

];
];
];

ListPlot3D[eps0,PlotRange->All,AxesStyle->18]
ListPlot3D[eps1,PlotRange->All,AxesStyle->18]
ListPlot3D[eps2,PlotRange->All,AxesStyle->18]
prms=ListPlot3D[epssigma,PlotRange->All,AxesStyle->18,PlotStyle->Green]

meanxf= meanx;
eps2f=epssigma2;
(* eps2f=eps2; *)

eps2=epssigma2;

(* Execute the code in y5m2012_7b.nb before these two blocks of code. And do not execute the code above in h123 anymore. *)

eps2slice=Table[{},{dim}];
For[slice=1,slice≤Length[meanx],slice++,
For[i=1,i≤Length[eps2],i++,
If[eps2[[i,1]]>0||eps2[[i,2]]>0,Continue[]];
If[eps2[[i,1]]==meanx[[slice]],
AppendTo[eps2slice[[slice]],{eps2[[i,2]],eps2[[i,3]]}];
];
];
]

eps2diag={};
For[slice=1,slice≤Length[meanx],slice++,
For[i=1,i≤Length[eps2],i++,
If[eps2[[i,1]]>0||eps2[[i,2]]>0,Continue[]];
If[eps2[[i,1]]==meanx[[slice]]&&eps2[[i,2]]==meanx[[slice]],
AppendTo[eps2diag,{eps2[[i,2]],eps2[[i,3]]}];
];
];
]

eps2fslice=Table[{},{dim}];
For[slice=1,slice≤Length[meanxf],slice++,
For[i=1,i≤Length[eps2f],i++,
If[eps2f[[i,1]]>0||eps2f[[i,2]]>0,Continue[]];
If[eps2f[[i,1]]==meanxf[[slice]],
AppendTo[eps2fslice[[slice]],{eps2f[[i,2]],eps2f[[i,3]]}];
];
];
]

eps2fdiag={};
For[slice=1,slice≤Length[meanx],slice++,
For[i=1,i≤Length[eps2f],i++,
If[eps2f[[i,1]]>0||eps2f[[i,2]]>0,Continue[]];
If[eps2f[[i,1]]==meanxf[[slice]]&&eps2f[[i,2]]==meanxf[[slice]],
AppendTo[eps2fdiag,{eps2f[[i,2]],eps2f[[i,3]]}];
];
];
]

(* Plot raw data and noise *)

scale=Plot[0,{x,0,1.0},PlotRange->{0,0.11},Frame->True,FrameStyle->Directive[18,Thick],FrameTicks->{
{{0,"0",{0.015,0}},{0.5,"-0.5",{0.015,0}},{1.0,"-1.0",{0.015,0}},{1.5,"-1.5",{0.015,0}}},
{{0,"0",{0.015,0}},{0.03,"0.03",{0.015,0}},{0.06,"0.06",{0.015,0}},{0.09,"0.09",{0.015,0}},{0.12,"0.12",{0.015,0}},{0.15,"0.15",{0.015,0}},{0.18,"0.18",{0.015,0}},{0.21,"0.21",{0.015,0}}},
{{0,"",{0.015,0}},{0.5,"",{0.015,0}},{1.0,"",{0.015,0}},{1.5,"",{0.015,0}}},
{{0,"",{0.015,0}},{0.03,"",{0.015,0}},{0.06,"",{0.015,0}},{0.09,"",{0.015,0}},{0.12,"",{0.015,0}},{0.15,"",{0.015,0}},{0.18,"",{0.015,0}},{0.21,"",{0.015,0}}}}];

size=0.02;
(*p11=ListPlot[Abs[eps2slice[[1]]],PlotStyle->Directive[PointSize[size],Red]];
p12=ListPlot[Abs[eps2slice[[2]]],PlotStyle->Directive[PointSize[size],Red]];*)
p13=ListPlot[Abs[eps2slice[[3]]],PlotStyle->Directive[PointSize[size],Red]];
p14=ListPlot[Abs[eps2slice[[4]]],PlotStyle->Directive[PointSize[size],RGBColor[1.0,0.85,0.0]]];
p15=ListPlot[Abs[eps2slice[[5]]],PlotStyle->Directive[PointSize[size],Green]];
p16=ListPlot[Abs[eps2slice[[6]]],PlotStyle->Directive[PointSize[size],Blue]];
p17=ListPlot[Abs[eps2slice[[7]]],PlotStyle->Directive[PointSize[size],Purple]];
p18=ListPlot[Abs[eps2slice[[8]]],PlotStyle->Directive[PointSize[size],Gray]];
p110=ListPlot[Abs[eps2slice[[10]]],PlotStyle->Directive[PointSize[size],Black]];
Show[(*p11,p12,*)p13,p14,p15,p16,p17,p18,p110]

size=0.02;
(*p21=ListPlot[Abs[eps2fslice[[1]]],PlotStyle->Directive[PointSize[size],Red],PlotMarkers->{"*",30}];
p22=ListPlot[Abs[eps2fslice[[2]]],PlotStyle->Directive[PointSize[size],Red],PlotMarkers->{"*",30}];*)
p23=ListPlot[Abs[eps2fslice[[3]]],PlotStyle->Directive[PointSize[size],Red],PlotMarkers->{"*",30}];
p24=ListPlot[Abs[eps2fslice[[4]]],PlotStyle->Directive[PointSize[size],RGBColor[1.0,0.85,0.0]],PlotMarkers->{"*",30}];
p25=ListPlot[Abs[eps2fslice[[5]]],PlotStyle->Directive[PointSize[size],Green],PlotMarkers->{"*",30}];
p26=ListPlot[Abs[eps2fslice[[6]]],PlotStyle->Directive[PointSize[size],Blue],PlotMarkers->{"*",30}];
p27=ListPlot[Abs[eps2fslice[[7]]],PlotStyle->Directive[PointSize[size],Purple],PlotMarkers->{"*",30}];
p28=ListPlot[Abs[eps2fslice[[8]]],PlotStyle->Directive[PointSize[size],Gray],PlotMarkers->{"*",30}];
p210=ListPlot[Abs[eps2fslice[[10]]],PlotStyle->Directive[PointSize[size],Black],PlotMarkers->{"*",30}];
Show[scale,(*p21,p22,*)p23,p24,p25,p26,p27,p28,p210]

(*Show[scale,p11,p21]
Show[scale,p12,p22]*)
Show[scale,p13,p23]
Show[scale,p14,p24]
Show[scale,p15,p25]
Show[scale,p16,p26]
Show[scale,p17,p27]
Show[scale,p18,p28]
Show[scale,p110,p210]
Show[scale,p13,p23,p110,p210,AspectRatio->0.75,ImageSize->100]

Show[scale,p13,p23,p110,p210,AspectRatio->0.75,ImageSize->300]

Export[StringJoin[path,"FinalFIGS/4a.png"],,ImageResolution->600]

(* Plot subtracted data : variance *)

size=0.03;
(*scale=Plot[0,{x,0,1.0},PlotRange->{-0.01,0.07}];*)
scale=Plot[0,{x,0,1.0},PlotRange->{0,0.07},Frame->True,FrameStyle->Directive[18,Thick],FrameTicks->{
{{0,"0",{0.015,0}},{0.5,"-0.5",{0.015,0}},{1.0,"-1.0",{0.015,0}},{1.5,"-1.5",{0.015,0}}},
{{0,"0",{0.015,0}},{0.02,"0.02",{0.015,0}},{0.04,"0.04",{0.015,0}},{0.06,"0.06",{0.015,0}}},
{{0,"",{0.015,0}},{0.5,"",{0.015,0}},{1.0,"",{0.015,0}},{1.5,"",{0.015,0}}},
{{0,"",{0.015,0}},{0.02,"",{0.015,0}},{0.04,"",{0.015,0}},{0.06,"",{0.015,0}}}}];
(*p31=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[1]]][[1]],Transpose[eps2slice[[1]]][[1]]}]],Transpose[eps2slice[[1]]][[2]]-Transpose[eps2fslice[[1]]][[2]]}],PlotStyle->Directive[PointSize[size],Red]];
p32=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[2]]][[1]],Transpose[eps2slice[[2]]][[1]]}]],Transpose[eps2slice[[2]]][[2]]-Transpose[eps2fslice[[2]]][[2]]}],PlotStyle->Directive[PointSize[size],Red]];*)
p33=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[3]]][[1]],Transpose[eps2slice[[3]]][[1]]}]],Transpose[eps2slice[[3]]][[2]]-Transpose[eps2fslice[[3]]][[2]]}],PlotStyle->Directive[PointSize[size],Red]];
p34=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[4]]][[1]],Transpose[eps2slice[[4]]][[1]]}]],Transpose[eps2slice[[4]]][[2]]-Transpose[eps2fslice[[4]]][[2]]}],PlotStyle->Directive[PointSize[size],RGBColor[1.0,0.85,0.0]]];
p35=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[5]]][[1]],Transpose[eps2slice[[5]]][[1]]}]],Transpose[eps2slice[[5]]][[2]]-Transpose[eps2fslice[[5]]][[2]]}],PlotStyle->Directive[PointSize[size],Green]];
p36=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[6]]][[1]],Transpose[eps2slice[[6]]][[1]]}]],Transpose[eps2slice[[6]]][[2]]-Transpose[eps2fslice[[6]]][[2]]}],PlotStyle->Directive[PointSize[size],Blue]];
p37=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[7]]][[1]],Transpose[eps2slice[[7]]][[1]]}]],Transpose[eps2slice[[7]]][[2]]-Transpose[eps2fslice[[7]]][[2]]}],PlotStyle->Directive[PointSize[size],Purple]];
p38=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[8]]][[1]],Transpose[eps2slice[[8]]][[1]]}]],Transpose[eps2slice[[8]]][[2]]-Transpose[eps2fslice[[8]]][[2]]}],PlotStyle->Directive[PointSize[size],Gray]];
p310=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[10]]][[1]],Transpose[eps2slice[[10]]][[1]]}]],Transpose[eps2slice[[10]]][[2]]-Transpose[eps2fslice[[10]]][[2]]}],PlotStyle->Directive[PointSize[size],Black]];
Show[scale,(*p31,p32,*)p33,p34,p35,p36,p37,p38,p310]


(*p41=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[1]]][[1]],Transpose[eps2slice[[1]]][[1]]}]],Transpose[eps2slice[[1]]][[2]]-Transpose[eps2fslice[[1]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Red]];
p42=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[2]]][[1]],Transpose[eps2slice[[2]]][[1]]}]],Transpose[eps2slice[[2]]][[2]]-Transpose[eps2fslice[[2]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Red],PlotMarkers->"●"];*)
p43=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[3]]][[1]],Transpose[eps2slice[[3]]][[1]]}]],Transpose[eps2slice[[3]]][[2]]-Transpose[eps2fslice[[3]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Red],PlotMarkers->"●"];
p44=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[4]]][[1]],Transpose[eps2slice[[4]]][[1]]}]],Transpose[eps2slice[[4]]][[2]]-Transpose[eps2fslice[[4]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,RGBColor[1.0,0.85,0.0]],PlotMarkers->"●"];
p45=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[5]]][[1]],Transpose[eps2slice[[5]]][[1]]}]],Transpose[eps2slice[[5]]][[2]]-Transpose[eps2fslice[[5]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Green],PlotMarkers->"●"];
p46=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[6]]][[1]],Transpose[eps2slice[[6]]][[1]]}]],Transpose[eps2slice[[6]]][[2]]-Transpose[eps2fslice[[6]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Blue],PlotMarkers->"●"];
p47=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[7]]][[1]],Transpose[eps2slice[[7]]][[1]]}]],Transpose[eps2slice[[7]]][[2]]-Transpose[eps2fslice[[7]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Purple],PlotMarkers->"●"];
p48=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[8]]][[1]],Transpose[eps2slice[[8]]][[1]]}]],Transpose[eps2slice[[8]]][[2]]-Transpose[eps2fslice[[8]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Gray],PlotMarkers->"●"];
p410=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[10]]][[1]],Transpose[eps2slice[[10]]][[1]]}]],Transpose[eps2slice[[10]]][[2]]-Transpose[eps2fslice[[10]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Black],PlotMarkers->"●"];
Show[scale,(*p41,p42,*)p43,p44,p45,p46,p47,p48,p410]

(* Execute this *)

Clear[y]
ys=Abs[Mean[{Transpose[eps2fslice[[8]]][[1]],Transpose[eps2slice[[8]]][[1]]}]]

(* Random walk fit *)

(*p51=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[1]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.09}}];
p52=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[2]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.1}}];*)
p53=Plot[0.0828(2((x y)/(x+y)))/.y->ys[[3]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.08}}];
p54=Plot[0.0828(2((x y)/(x+y)))/.y->ys[[4]],{x,0,1.5},PlotStyle->Directive[RGBColor[1.0,0.85,0.0]],PlotRange->{{0,1.5},{0,0.08}}];
p55=Plot[0.0828(2((x y)/(x+y)))/.y->ys[[5]],{x,0,1.5},PlotStyle->Directive[Green],PlotRange->{{0,1.5},{0,0.08}}];
p56=Plot[0.0828(2((x y)/(x+y)))/.y->ys[[6]],{x,0,1.5},PlotStyle->Directive[Blue],PlotRange->{{0,1.5},{0,0.08}}];
p57=Plot[0.0828(2((x y)/(x+y)))/.y->ys[[7]],{x,0,1.5},PlotStyle->Directive[Purple],PlotRange->{{0,1.5},{0,0.08}}];
p58=Plot[0.0828(2((x y)/(x+y)))/.y->ys[[8]],{x,0,1.5},PlotStyle->Directive[Gray],PlotRange->{{0,1.5},{0,0.08}}];
p510=Plot[0.0828(2((x y)/(x+y)))/.y->ys[[10]],{x,0,1.5},PlotStyle->Directive[Black],PlotRange->{{0,1.5},{0,0.08}}];
(*p53=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[3]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.08}}];
p54=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[4]],{x,0,1.5},PlotStyle->Directive[RGBColor[1.0,0.85,0.0]],PlotRange->{{0,1.5},{0,0.08}}];
p55=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[5]],{x,0,1.5},PlotStyle->Directive[Green],PlotRange->{{0,1.5},{0,0.08}}];
p56=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[6]],{x,0,1.5},PlotStyle->Directive[Blue],PlotRange->{{0,1.5},{0,0.08}}];
p57=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[7]],{x,0,1.5},PlotStyle->Directive[Purple],PlotRange->{{0,1.5},{0,0.08}}];
p58=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[8]],{x,0,1.5},PlotStyle->Directive[Gray],PlotRange->{{0,1.5},{0,0.08}}];
p510=Plot[0.0693(2((x y)/(x+y)))/.y->ys[[10]],{x,0,1.5},PlotStyle->Directive[Black],PlotRange->{{0,1.5},{0,0.08}}];*)
Show[scale,(*p51,p52,*)p53,p54,p55,p56,p57,p58,p510,(*p41,p42,*)p43,p44,p45,p46,p47,p48,p410,(* p31,p32,*)p33,p34,p35,p36,p37,p38,p310,AspectRatio->0.75,ImageSize->300]
Show[scale,p53,p55,p57,p510,p43,p45,p47,p410,p33,p35,p37,p310,AspectRatio->0.75]
Show[scale,p54,p56,p58,p510,p44,p46,p48,p410,p34,p36,p38,p310,AspectRatio->0.75]

Export[StringJoin[path,"FinalFIGS/2b.pdf"],,ImageResolution->600]

(* FourthRoot fit *)

p61=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[1]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.1}}];
p62=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[2]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.1}}];
p63=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[3]],{x,0,1.5},PlotStyle->Directive[RGBColor[1.0,0.85,0.0]],PlotRange->{{0,1.5},{0,0.08}}];
p64=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[4]],{x,0,1.5},PlotStyle->Directive[Green],PlotRange->{{0,1.5},{0,0.08}}];
p65=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[5]],{x,0,1.5},PlotStyle->Directive[Blue],PlotRange->{{0,1.5},{0,0.08}}];
p66=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[6]],{x,0,1.5},PlotStyle->Directive[Purple],PlotRange->{{0,1.5},{0,0.08}}];
p67=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[7]],{x,0,1.5},PlotStyle->Directive[Gray],PlotRange->{{0,1.5},{0,0.08}}];
p68=Plot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[8]],{x,0,1.5},PlotStyle->Directive[Black],PlotRange->{{0,1.5},{0,0.08}}];
Show[scale,(*p61,*)p62,p63,p64,p65,p66,p67,p68,(*p41,*)p42,p43,p44,p45,p46,p47,p48,(* p31,*)p32,p33,p34,p35,p36,p37,p38,AxesStyle->18,Ticks->{{0,0.5,1.0,1.5},{0.03,0.06,0.09}},AspectRatio->1]
Show[scale,p62,p64,p66,p68,p42,p44,p46,p48,p32,p34,p36,p38,AxesStyle->18,Ticks->{{0,0.5,1.0,1.5},{0.03,0.06,0.09}},AspectRatio->1]

eps2[[3]]
eps2f[[3]]

Length[eps2]

eps2[[1]]
eps2f[[1]]

eps2f=Drop[eps2f,1];

Length[eps2]
Length[eps2f]

eps2[[17]]

totalovernoise={};
For[i=1,i≤Length[eps2],i++,
If[eps2[[i,1]]>-2&&eps2[[i,2]]>-2,
AppendTo[totalovernoise,{eps2[[i,1]],eps2[[i,2]],((eps2[[i,3]])/(eps2f[[i,3]]))}];
];
]

Length[totalovernoise]

ListDensityPlot[totalovernoise,ColorFunction->"ThermometerColors",InterpolationOrder->0,BoundaryStyle->Black,FrameStyle->18,FrameTicks->{{{-1.5,-1.0,-0.5,0.0,0.15},None},{{-1.5,-1.0,-0.5,0.0,0.15},None}},PlotRange->{{-1.0,0.15},{-1.0,0.15}}]

Export[StringJoin[path,"FinalFIGS/4b.pdf"],,ImageResolution->600]

Needs["PlotLegends`"]

max=Max[Transpose[totalovernoise][[3]]];
min=Min[Transpose[totalovernoise][[3]]];
smax=ToString[max];
smin=ToString[min];
Graphics[Legend[ColorData["ThermometerColors"][1-#1]&, 31]]

Export[StringJoin[path,"FinalFIGS/4bbar.pdf"],,ImageResolution->600]

(min+#(max-min))&[Table[0.1i,{i,0,10}]]

Union[Transpose[totalovernoise][[2]]]

(max-min)/31

(* Variance *)

eps2diff={};
xs={};
counter=0;
For[i=1,i≤Length[eps2],i++,
avgx=Mean[{eps2[[i,1]],eps2f[[i,1]]}];
avgy=Mean[{eps2[[i,2]],eps2f[[i,2]]}];
AppendTo[xs,avgx];
AppendTo[xs,avgy];
If[avgx>-1&&avgx<0&&avgy>-1&&avgy<0&&eps2[[i,3]]-eps2f[[i,3]]<0,   (* only deleterious and not the very last row *)Print[counter++,"  ",eps2[[i,3]],"  ",eps2f[[i,3]],"  ",eps2[[i,3]]-eps2f[[i,3]]]];
diff=eps2[[i,3]]-eps2f[[i,3]];
AppendTo[eps2diff,{avgx,avgy,diff}];
]

xs=Union[xs]
Length[xs]

slices={};
For[i=1,i≤Length[xs],i++,
lista={};
For[j=1,j≤Length[eps2diff],j++,
If[eps2diff[[j,1]]==xs[[i]],
AppendTo[lista,eps2diff[[j]]];
];
];
AppendTo[slices,lista];
]

slices={Take[slices,{3}],Take[slices,{4}],Take[slices,{5}],Take[slices,{6}],Take[slices,{7}],Take[slices,{8}],Take[slices,{10}]};
slices=Flatten[slices,1];

size=0.025;
surf8=ListPointPlot3D[slices,PlotStyle->{Directive[Red,PointSize[size]],Directive[RGBColor[1.0,0.85,0.0],PointSize[size]],Directive[Green,PointSize[size]],Directive[Blue,PointSize[size]],Directive[Purple,PointSize[size]],Directive[Gray,PointSize[size]],Directive[Black,PointSize[size]],Directive[Green,PointSize[0]],Directive[Green,PointSize[0]]},PlotRange->{{-1,0},{-1,0},{0,0.07}},Ticks->{{0,-0.5,-1.0,-1.5},{0,-0.5,-1.0,-1.5},{0,0.02,0.04,0.06},{0,-0.5,-1.0,-1.5},{0,-0.5,-1.0,-1.5},{0,0.02,0.04,0.06}},AxesStyle->18];

surf=Plot3D[((*0.0693*)0.0828 2((Abs[x]Abs[y])/(Abs[x]+Abs[y]))),{x,-1,0},{y,-1,0},LabelStyle->18,ClippingStyle->None,PlotRange->{0,0.11},PlotStyle->Directive[White,Opacity[0.5]],Mesh->4,MaxRecursion->6,MeshStyle->Directive[White],AspectRatio->1];

Show[surf8,surf,BoxStyle->Directive[Black,Thick],AxesEdge->{{1,-1},{1,-1},{1,-1}},TicksStyle->Thick,ViewPoint->{2,1,0.5},BoxRatios->{1,1,0.5}]

Export[StringJoin[path,"FinalFIGS/2a.pdf"],,ImageResolution->600]

size=0.04;
surf8=ListPointPlot3D[slices,PlotStyle->{Directive[Black,PointSize[size]],Directive[Red,PointSize[size]],Directive[RGBColor[1.0,0.85,0.0],PointSize[size]],Directive[Green,PointSize[size]],Directive[Blue,PointSize[size]],Directive[Purple,PointSize[size]],Directive[Gray,PointSize[size]],Directive[Black,PointSize[size]],Directive[Green,PointSize[0]],Directive[Green,PointSize[0]]},PlotRange->{{-1.6,0},{-1.6,0},{0,0.1}},AxesStyle->18];

surf=Plot3D[0.0628Power[Abs[x]Abs[y],0.5],{x,-2.5,0},{y,-2.5,0},LabelStyle->18,ClippingStyle->None,PlotRange->{0,0.1},PlotStyle->Directive[White,Opacity[0.5]],Mesh->5,MaxRecursion->6,MeshStyle->Directive[White]];

Show[surf8,surf]

(* Fig.2a : eps with MM fit 0.374 Sqrt[G1 G2 / (G1 + G2)]*)

(* Fig.2b : variance MM *)

Export["fig3aa.png",]
Export["fig3bb.png",]

(* Plot subtracted data : standard deviation *)

size=0.03;
scale=Plot[0,{x,0,1.5},PlotRange->{-0.01,0.3}];
(*p31=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[1]]][[1]],Transpose[eps2slice[[1]]][[1]]}]],Sqrt[Transpose[eps2slice[[1]]][[2]]-Transpose[eps2fslice[[1]]][[2]]]}],PlotStyle->Directive[PointSize[size],Red]];*)
p32=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[2]]][[1]],Transpose[eps2slice[[2]]][[1]]}]],Sqrt[Transpose[eps2slice[[2]]][[2]]-Transpose[eps2fslice[[2]]][[2]]]}],PlotStyle->Directive[PointSize[size],Red]];
p33=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[3]]][[1]],Transpose[eps2slice[[3]]][[1]]}]],Sqrt[Transpose[eps2slice[[3]]][[2]]-Transpose[eps2fslice[[3]]][[2]]]}],PlotStyle->Directive[PointSize[size],RGBColor[1.0,0.85,0.0]]];
p34=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[4]]][[1]],Transpose[eps2slice[[4]]][[1]]}]],Sqrt[Transpose[eps2slice[[4]]][[2]]-Transpose[eps2fslice[[4]]][[2]]]}],PlotStyle->Directive[PointSize[size],Green]];
p35=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[5]]][[1]],Transpose[eps2slice[[5]]][[1]]}]],Sqrt[Transpose[eps2slice[[5]]][[2]]-Transpose[eps2fslice[[5]]][[2]]]}],PlotStyle->Directive[PointSize[size],Blue]];
p36=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[6]]][[1]],Transpose[eps2slice[[6]]][[1]]}]],Sqrt[Transpose[eps2slice[[6]]][[2]]-Transpose[eps2fslice[[6]]][[2]]]}],PlotStyle->Directive[PointSize[size],Purple]];
p37=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[7]]][[1]],Transpose[eps2slice[[7]]][[1]]}]],Sqrt[Transpose[eps2slice[[7]]][[2]]-Transpose[eps2fslice[[7]]][[2]]]}],PlotStyle->Directive[PointSize[size],Gray]];
p38=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[8]]][[1]],Transpose[eps2slice[[8]]][[1]]}]],Sqrt[Transpose[eps2slice[[8]]][[2]]-Transpose[eps2fslice[[8]]][[2]]]}],PlotStyle->Directive[PointSize[size],Black]];
Show[scale,(*p31,*)p32,p33,p34,p35,p36,p37,p38]


(*p41=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[1]]][[1]],Transpose[eps2slice[[1]]][[1]]}]],Sqrt[Transpose[eps2slice[[1]]][[2]]-Transpose[eps2fslice[[1]]][[2]]}],PlotStyle->Directive[PointSize[size],Dashed,Red]];*)
p42=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[2]]][[1]],Transpose[eps2slice[[2]]][[1]]}]],Sqrt[Transpose[eps2slice[[2]]][[2]]-Transpose[eps2fslice[[2]]][[2]]]}],PlotStyle->Directive[PointSize[size],Dashed,Red],PlotMarkers->"●"];
p43=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[3]]][[1]],Transpose[eps2slice[[3]]][[1]]}]],Sqrt[Transpose[eps2slice[[3]]][[2]]-Transpose[eps2fslice[[3]]][[2]]]}],PlotStyle->Directive[PointSize[size],Dashed,RGBColor[1.0,0.85,0.0]],PlotMarkers->"●"];
p44=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[4]]][[1]],Transpose[eps2slice[[4]]][[1]]}]],Sqrt[Transpose[eps2slice[[4]]][[2]]-Transpose[eps2fslice[[4]]][[2]]]}],PlotStyle->Directive[PointSize[size],Dashed,Green],PlotMarkers->"●"];
p45=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[5]]][[1]],Transpose[eps2slice[[5]]][[1]]}]],Sqrt[Transpose[eps2slice[[5]]][[2]]-Transpose[eps2fslice[[5]]][[2]]]}],PlotStyle->Directive[PointSize[size],Dashed,Blue],PlotMarkers->"●"];
p46=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[6]]][[1]],Transpose[eps2slice[[6]]][[1]]}]],Sqrt[Transpose[eps2slice[[6]]][[2]]-Transpose[eps2fslice[[6]]][[2]]]}],PlotStyle->Directive[PointSize[size],Dashed,Purple],PlotMarkers->"●"];
p47=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[7]]][[1]],Transpose[eps2slice[[7]]][[1]]}]],Sqrt[Transpose[eps2slice[[7]]][[2]]-Transpose[eps2fslice[[7]]][[2]]]}],PlotStyle->Directive[PointSize[size],Dashed,Gray],PlotMarkers->"●"];
p48=ListLinePlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[8]]][[1]],Transpose[eps2slice[[8]]][[1]]}]],Sqrt[Transpose[eps2slice[[8]]][[2]]-Transpose[eps2fslice[[8]]][[2]]]}],PlotStyle->Directive[PointSize[size],Dashed,Black],PlotMarkers->"●"];
Show[scale,(*p41,*)p42,p43,p44,p45,p46,p47,p48]

(* Execute this *)

Clear[y]
ys=Abs[Mean[{Transpose[eps2fslice[[8]]][[1]],Transpose[eps2slice[[8]]][[1]]}]]

(* Random walk fit *)

p51=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[1]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.3}}];
p52=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[2]],{x,0,1.5},PlotStyle->Directive[Red],PlotRange->{{0,1.5},{0,0.3}}];
p53=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[3]],{x,0,1.5},PlotStyle->Directive[RGBColor[1.0,0.85,0.0]],PlotRange->{{0,1.5},{0,0.3}}];
p54=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[4]],{x,0,1.5},PlotStyle->Directive[Green],PlotRange->{{0,1.5},{0,0.3}}];
p55=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[5]],{x,0,1.5},PlotStyle->Directive[Blue],PlotRange->{{0,1.5},{0,0.3}}];
p56=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[6]],{x,0,1.5},PlotStyle->Directive[Purple],PlotRange->{{0,1.5},{0,0.3}}];
p57=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[7]],{x,0,1.5},PlotStyle->Directive[Gray],PlotRange->{{0,1.5},{0,0.3}}];
p58=Plot[0.374Sqrt[((x y)/(x+y))]/.y->ys[[8]],{x,0,1.5},PlotStyle->Directive[Black],PlotRange->{{0,1.5},{0,0.3}}];
Show[scale,(*p51,*)p52,p53,p54,p55,p56,p57,p58,(*p41,*)p42,p43,p44,p45,p46,p47,p48,(* p31,*)p32,p33,p34,p35,p36,p37,p38,AxesStyle->18,Ticks->{{0,0.5,1.0,1.5},{0.1,0.2,0.3}},AspectRatio->1]
Show[scale,p52,p54,p56,p58,p42,p44,p46,p48,p32,p34,p36,p38,AxesStyle->18,Ticks->{{0,0.5,1.0,1.5},{0.1,0.2,0.3}},AspectRatio->1]

(* Standard Deviation *)

epssigmadiff={};
xs={};
For[i=1,i≤Length[eps2],i++,
avgx=Mean[{eps2[[i,1]],eps2f[[i,1]]}];
avgy=Mean[{eps2[[i,2]],eps2f[[i,2]]}];
AppendTo[xs,avgx];
AppendTo[xs,avgy];
If[eps2[[i,3]]-eps2f[[i,3]]<-0.01,Print[eps2[[i,3]]-eps2f[[i,3]]]];
diff=Sqrt[Max[0,eps2[[i,3]]-eps2f[[i,3]]]];
AppendTo[epssigmadiff,{avgx,avgy,diff}];
]

xs=Union[xs]
Length[xs]

slices={};
For[i=1,i≤Length[xs],i++,
lista={};
For[j=1,j≤Length[epssigmadiff],j++,
If[epssigmadiff[[j,1]]==xs[[i]],
AppendTo[lista,epssigmadiff[[j]]];
];
];
AppendTo[slices,lista];
]

size=0.04;
surf8=ListPointPlot3D[slices,PlotStyle->{Directive[Black,PointSize[size]],Directive[Red,PointSize[size]],Directive[RGBColor[1.0,0.85,0.0],PointSize[size]],Directive[Green,PointSize[size]],Directive[Blue,PointSize[size]],Directive[Purple,PointSize[size]],Directive[Gray,PointSize[size]],Directive[Black,PointSize[size]],Directive[Green,PointSize[0]],Directive[Green,PointSize[0]]},PlotRange->{{-1.6,0},{-1.6,0},{0,0.35}},AxesStyle->18];

surf=Plot3D[0.374Sqrt[((Abs[x]Abs[y])/(Abs[x]+Abs[y]))],{x,-2.5,0},{y,-2.5,0},LabelStyle->18,ClippingStyle->None,PlotRange->{0,0.4},PlotStyle->Directive[White,Opacity[0.5]],Mesh->5,MaxRecursion->6,MeshStyle->Directive[White]];

Show[surf8,surf]

0.37/Sqrt[2]

size=0.04;
surf8=ListPointPlot3D[slices,PlotStyle->{Directive[Black,PointSize[size]],Directive[Red,PointSize[size]],Directive[RGBColor[1.0,0.85,0.0],PointSize[size]],Directive[Green,PointSize[size]],Directive[Blue,PointSize[size]],Directive[Purple,PointSize[size]],Directive[Gray,PointSize[size]],Directive[Black,PointSize[size]],Directive[Green,PointSize[0]],Directive[Green,PointSize[0]]},PlotRange->{{-1.6,0},{-1.6,0},{0,0.35}},AxesStyle->18];

surf=Plot3D[0.230Sqrt[Power[Abs[x]Abs[y],0.5]],{x,-2.5,0},{y,-2.5,0},LabelStyle->18,ClippingStyle->None,PlotRange->{0,0.4},PlotStyle->Directive[White,Opacity[0.5]],Mesh->5,MaxRecursion->6,MeshStyle->Directive[White]];

Show[surf8,surf]

(* Fit of Variance *)

(* Here I consider the sigma2(eps) relative to the combination of two deleterious knockouts only.                        *)
(* I assume sigma2(eps) = c Power[Abs[x]Abs[y],0.5] and I estimate the best value for c by minimizing square deviations *)
(* (second column). I also report the mean relative error (third column) and the largest error (fourth column).         *)

epssigma=eps2diff;

For[c=0.061,c≤0.065,c+=0.0001,
total={};
relativeerr1={};
relativeerr2={};
For[i=1,i≤Length[epssigma],i++,
If[epssigma[[i,1]]==xs[[1]]||epssigma[[i,2]]==xs[[1]],Continue[]];
If[epssigma[[i,3]]≠"Null"&&epssigma[[i,1]]<0&&epssigma[[i,2]]≤epssigma[[i,1]],   (* consider only j≤i *)
AppendTo[total,c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.5]-epssigma[[i,3]]];
AppendTo[relativeerr1,((c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.5]-epssigma[[i,3]])/(c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.5]))];
AppendTo[relativeerr2,((c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.5]-epssigma[[i,3]])/(epssigma[[i,3]]))];
];
];
Print[c,"  ",Norm[total],"    ",Mean[Abs[relativeerr1]],"  ",Max[Abs[relativeerr1]],"    ",Mean[Abs[relativeerr2]],"  ",Max[Abs[relativeerr2]]];
]

(* Here I consider the sigma(eps) relative to the combination of two deleterious knockouts only.                *)
(* I assume sigma(eps) = c (Sqrt[((df1 df2)/(df1 + df2))]) and I estimate the best value for c by minimizing square deviations       *)
(* (second column). I also report the mean relative error (third column) and the largest error (fourth column). *)

epssigma=eps2diff;

For[c=0.078,c≤0.080,c+=0.0001,
total={};
relativeerr1={};
relativeerr2={};
For[i=1,i≤Length[epssigma],i++,
If[epssigma[[i,1]]<-1||epssigma[[i,2]]<-1,Continue[]];
If[epssigma[[i,3]]≠"Null"&&epssigma[[i,1]]<0&&epssigma[[i,2]]≤epssigma[[i,1]],   (* consider only j≤i *)
AppendTo[total,c ((2Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))-epssigma[[i,3]]];
AppendTo[relativeerr1,((c ((2Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))-epssigma[[i,3]])/(c ((2Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))))];
AppendTo[relativeerr2,((c ((2Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))-epssigma[[i,3]])/(epssigma[[i,3]]))];
];
];
Print[c,"  ",Norm[total],"    ",Mean[Abs[relativeerr1]],"  ",Max[Abs[relativeerr1]],"    ",Mean[Abs[relativeerr2]],"  ",Max[Abs[relativeerr2]]];
]

(* Fit of Standard Deviation *)

(* Here I consider the sigma2(eps) relative to the combination of two deleterious knockouts only.                        *)
(* I assume sigma2(eps) = c Power[Abs[x]Abs[y],0.25] and I estimate the best value for c by minimizing square deviations *)
(* (second column). I also report the mean relative error (third column) and the largest error (fourth column).         *)

epssigma=epssigmadiff;

For[c=0.22,c≤0.24,c+=0.001,
total={};
relativeerr1={};
relativeerr2={};
For[i=1,i≤Length[epssigma],i++,
If[epssigma[[i,1]]==xs[[1]]||epssigma[[i,2]]==xs[[1]],Continue[]];
If[epssigma[[i,3]]≠"Null"&&epssigma[[i,1]]<0&&epssigma[[i,2]]≤epssigma[[i,1]],   (* consider only j≤i *)
AppendTo[total,c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.25]-epssigma[[i,3]]];
AppendTo[relativeerr1,((c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.25]-epssigma[[i,3]])/(c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.25]))];
(*AppendTo[relativeerr2,((c Power[Abs[epssigma[[i,1]]]Abs[epssigma[[i,2]]],0.25]-epssigma[[i,3]])/(epssigma[[i,3]]))];*)
];
];
Print[c,"  ",Norm[total],"    ",Mean[Abs[relativeerr1]],"  ",Max[Abs[relativeerr1]],"    ",Mean[Abs[relativeerr2]],"  ",Max[Abs[relativeerr2]]];
]

(* Here I consider the sigma(eps) relative to the combination of two deleterious knockouts only.                *)
(* I assume sigma(eps) = c (Sqrt[((df1 df2)/(df1 + df2))]) and I estimate the best value for c by minimizing square deviations       *)
(* (second column). I also report the mean relative error (third column) and the largest error (fourth column). *)

epssigma=epssigmadiff;

For[c=0.35,c≤0.45,c+=0.001,
total={};
relativeerr1={};
relativeerr2={};
For[i=1,i≤Length[epssigma],i++,
If[epssigma[[i,1]]==xs[[1]]||epssigma[[i,2]]==xs[[1]],Continue[]];
If[epssigma[[i,3]]≠"Null"&&epssigma[[i,1]]<0&&epssigma[[i,2]]≤epssigma[[i,1]],   (* consider only j≤i *)
AppendTo[total,c Sqrt[((Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))]-epssigma[[i,3]]];
AppendTo[relativeerr1,((c Sqrt[((2Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))]-epssigma[[i,3]])/(c Sqrt[((2Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))]))];
(*AppendTo[relativeerr2,((c ((2Abs[epssigma[[i,1]]] Abs[epssigma[[i,2]]])/(Abs[epssigma[[i,1]]] + Abs[epssigma[[i,2]]]))-epssigma[[i,3]])/(epssigma[[i,3]]))];*)
];
];
Print[c,"  ",Norm[total],"    ",Mean[Abs[relativeerr1]],"  ",Max[Abs[relativeerr1]],"    ",Mean[Abs[relativeerr2]],"  ",Max[Abs[relativeerr2]]];
]

(* LogLog plots *)

size=0.02;
logscale=LogLogPlot[1,{x,0.04,1.5},PlotRange->{0.002,0.09}];
(*p61=ListPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[1]]][[1]],Transpose[eps2slice[[1]]][[1]]}]],Transpose[eps2slice[[1]]][[2]]-Transpose[eps2fslice[[1]]][[2]]}],PlotStyle->Directive[PointSize[size],Red]];*)
p62=ListLogLogPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[2]]][[1]],Transpose[eps2slice[[2]]][[1]]}]],Transpose[eps2slice[[2]]][[2]]-Transpose[eps2fslice[[2]]][[2]]}],PlotStyle->Directive[PointSize[size],Orange]];
p63=ListLogLogPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[3]]][[1]],Transpose[eps2slice[[3]]][[1]]}]],Transpose[eps2slice[[3]]][[2]]-Transpose[eps2fslice[[3]]][[2]]}],PlotStyle->Directive[PointSize[size],Yellow]];
p64=ListLogLogPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[4]]][[1]],Transpose[eps2slice[[4]]][[1]]}]],Transpose[eps2slice[[4]]][[2]]-Transpose[eps2fslice[[4]]][[2]]}],PlotStyle->Directive[PointSize[size],Green]];
p65=ListLogLogPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[5]]][[1]],Transpose[eps2slice[[5]]][[1]]}]],Transpose[eps2slice[[5]]][[2]]-Transpose[eps2fslice[[5]]][[2]]}],PlotStyle->Directive[PointSize[size],Blue]];
p66=ListLogLogPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[6]]][[1]],Transpose[eps2slice[[6]]][[1]]}]],Transpose[eps2slice[[6]]][[2]]-Transpose[eps2fslice[[6]]][[2]]}],PlotStyle->Directive[PointSize[size],Purple]];
p67=ListLogLogPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[7]]][[1]],Transpose[eps2slice[[7]]][[1]]}]],Transpose[eps2slice[[7]]][[2]]-Transpose[eps2fslice[[7]]][[2]]}],PlotStyle->Directive[PointSize[size],Gray]];
p68=ListLogLogPlot[Transpose[{Abs[Mean[{Transpose[eps2fslice[[8]]][[1]],Transpose[eps2slice[[8]]][[1]]}]],Transpose[eps2slice[[8]]][[2]]-Transpose[eps2fslice[[8]]][[2]]}],PlotStyle->Directive[PointSize[size],Black]];
Show[logscale,(*p61,*)p62,p63,p64,p65,p66,p67(*,p68*)]

p71=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[1]],{x,0.04,1.5},PlotStyle->Red,PlotRange->{{0.04,1.5},{0,0.08}}];
p72=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[2]],{x,0.04,1.5},PlotStyle->Orange,PlotRange->{{0.04,1.5},{0,0.08}}];
p73=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[3]],{x,0.04,1.5},PlotStyle->Yellow,PlotRange->{{0.04,1.5},{0,0.08}}];
p74=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[4]],{x,0.04,1.5},PlotStyle->Green,PlotRange->{{0.04,1.5},{0,0.08}}];
p75=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[5]],{x,0.04,1.5},PlotStyle->Blue,PlotRange->{{0.04,1.5},{0,0.08}}];
p76=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[6]],{x,0.04,1.5},PlotStyle->Purple,PlotRange->{{0.04,1.5},{0,0.08}}];
p77=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[7]],{x,0.04,1.5},PlotStyle->Gray,PlotRange->{{0.04,1.5},{0,0.08}}];
p78=LogLogPlot[(0.0693 2((Abs[x]Abs[y])/(Abs[x]+Abs[y])))/.y->ys[[8]],{x,0.04,1.5},PlotStyle->Black,PlotRange->{{0.04,1.5},{0,0.08}}];
Show[logscale,(*p61,*)p62,p63,p64,p65,p66,p67,(*,p68, p71,*)p72,p73,p74,p75,p76,p77(*,p78*)]

p71=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[1]],{x,0.04,1.5},PlotStyle->Red,PlotRange->{{0.04,1.5},{0,0.08}}];
p72=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[2]],{x,0.04,1.5},PlotStyle->Orange,PlotRange->{{0.04,1.5},{0,0.08}}];
p73=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[3]],{x,0.04,1.5},PlotStyle->Yellow,PlotRange->{{0.04,1.5},{0,0.08}}];
p74=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[4]],{x,0.04,1.5},PlotStyle->Green,PlotRange->{{0.04,1.5},{0,0.08}}];
p75=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[5]],{x,0.04,1.5},PlotStyle->Blue,PlotRange->{{0.04,1.5},{0,0.08}}];
p76=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[6]],{x,0.04,1.5},PlotStyle->Purple,PlotRange->{{0.04,1.5},{0,0.08}}];
p77=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[7]],{x,0.04,1.5},PlotStyle->Gray,PlotRange->{{0.04,1.5},{0,0.08}}];
p78=LogLogPlot[0.0628Power[Abs[x]Abs[y],0.5]/.y->ys[[8]],{x,0.04,1.5},PlotStyle->Black,PlotRange->{{0.04,1.5},{0,0.08}}];
Show[logscale,(*p61,*)p62,p63,p64,p65,p66,p67,(*,p68, p71,*)p72,p73,p74,p75,p76,p77(*,p78*)]

(* Diagonal *)

pdiag=ListPlot[Abs[eps2diag],PlotStyle->PointSize[size]];
pdiagf=ListPlot[Abs[eps2fdiag],PlotMarkers->{"*",30}];
Show[pdiag,pdiagf]

lst={};
For[i=1,i≤9,i++,
AppendTo[lst,{Abs[eps2diag[[i,1]]],eps2diag[[i,2]]-eps2fdiag[[i+1,2]]}];
]

pdiagdiff=ListPlot[lst,PlotStyle->PointSize[size],PlotRange->All];
fitted=Plot[0.06959237936683386`x,{x,0,1.3}];
Show[pdiagdiff,fitted]

Clear[x]
Fit[lst,x,x]

epssigmadiff={};
For[i=1,i≤Length[eps2],i++,
avgx=Mean[{eps2[[i,1]],eps2f[[i,1]]}];
avgy=Mean[{eps2[[i,2]],eps2f[[i,2]]}];
diff=Sqrt[Max[0,eps2[[i,3]]-eps2f[[i,3]]]];
AppendTo[epssigmadiff,{avgx,avgy,diff}];
]
p0=ListPlot3D[epssigmadiff]

p2=Plot3D[Sqrt[0.0628]Power[x y,0.25],{x,-2,0},{y,-2,0},PlotStyle->Blue];
Show[p0,p2]

p1=Plot3D[Sqrt[-0.0639 2((x y)/(x+y))],{x,-2.5,0},{y,-2.5,0},PlotStyle->Red];
Show[p0,p1]

p1=Plot3D[Sqrt[-0.0693 2((x y)/(x+y))],{x,-1.0,0},{y,-1.0,0},PlotStyle->Red];
Show[p1,p0]

p2=Plot3D[Sqrt[0.0628]Power[x y,0.25],{x,-1.0,0},{y,-1.0,0},PlotStyle->Blue];
Show[p2,p0]

p3=Plot3D[0.30Sqrt[Min[{Abs[x],Abs[y]}]],{x,-1.0,0},{y,-1.0,0},PlotStyle->Green];
Show[p3,p0]

eps=Import[StringJoin[path,"FILES2012/c_epsA.dat"]];
Take[Sort[Flatten[eps]],20]

eps=Import[StringJoin[path,"FILES2012/c_epsB.dat"]];
Take[Sort[Flatten[eps]],20]

eps=Import[StringJoin[path,"FILES2012/c_epsC.dat"]];
Take[Sort[Flatten[eps]],20]

singlekor=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoC.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsC.dat"]];

For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,
If[eps[[i,j]]<-10,
Print[i,"  ",j,"  ",eps[[i,j]],"  ",singlekor[[i,2]],"  ",singlekoc[[j,2]],"  ",doubleko[[i,j]]];
];
];
];

(* Diagonal slices raw data *)

diag=Table[0,{120000}];
index=1;
threshold=1.10;

(* Group A *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_common.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsA.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

(* Group B *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsB.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

(* Group C *)
singlekor=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsC.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

index
diag=DeleteCases[diag,0];
Length[diag]

(* DELETERIOUS MUTATIONS *)

uplist={};
midlist={};
lowlist={};
count={};

(*For[mid=Log[2,0.999],mid≥Log[2,0.25],mid=mid-0.05,                                          (* linear binning *)*)
For[mid=Log[2,0.99],mid≥Log[2,0.25],mid=Power[2,0.5]mid,             (* exponential binning *)

lower=0.95mid;
upper=1.05mid;
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]<upper||diag[[i,1]]>lower,Continue[]];
AppendTo[distro,diag[[i,2]]];
];


If[Length[distro]≥2,

(* begin bootstrap *)
bsvar={};
For[j=1,j≤1000,j++,
bsdistro=RandomChoice[distro,Length[distro]];
AppendTo[bsvar,Variance[bsdistro]+((Mean[distro])^2)];
];
(* end bootstrap *)

(*AppendTo[uplist,{-Log[2,-mid],Log[2,((Quantile[bssd,(3/4)])^2)]}];
AppendTo[midlist,{-Log[2,-mid],Log[2,((StandardDeviation[distro])^2)]}];
AppendTo[lowlist,{-Log[2,-mid],Log[2,((Quantile[bssd,(1/4)])^2)]}];*)
AppendTo[uplist,{mid,Quantile[bsvar,(3/4)]}];
AppendTo[midlist,{mid,Variance[distro]+((Mean[distro])^2)}];
AppendTo[lowlist,{mid,Quantile[bsvar,(1/4)]}];
AppendTo[count,{mid,Length[distro]}];

If[mid>-0.1&&((StandardDeviation[distro])^2)>0.01,
Print["z  ",((StandardDeviation[distro])^2),Take[Sort[distro],20]];
];
];

Print[mid]

]

(* 10% ; variance *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue}],Plot[-x+Log[2,0.1],{x,-1,10},PlotStyle->Directive[Red,Thick]]]

(* 10% : variance ; linear ; 0.01 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue}],Plot[-0.1278x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]],PlotRange->All]

(* 10% : variance + (mean^2) ; exp ; 0.5 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{-1.5,0},{0,0.20}}],Plot[-0.11x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]],PlotRange->All]
ListLogPlot[count,Filling->Axis]

lowlist
midlist
uplist

(* 10% : variance ; exp ; 0.5 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{-1.5,0},{0,0.20}}],Plot[-0.11x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]],PlotRange->All]
ListLogPlot[count]

(* 10% : variance ; exp ; 0.125 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{-1.5,0},{0,0.20}}],Plot[-0.11x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]],PlotRange->All]
ListLogPlot[count]

-Log[2,0.001]
-Log[2,0.01]
-Log[2,0.1]
-Log[2,1]

(* Diagonal slices experimental noise *)

diag=Table[0,{1500000}];
index=1;
threshold=1.10;

(* Group A1 *)
Print["1"];
singlekor=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h1c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B1 *)
singlekor=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h1c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C1 *)
singlekor=Import[StringJoin[path,"FILES2012/h1a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h1c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A2 *)
Print["2"];
singlekor=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h2c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B2 *)
singlekor=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h2c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C2 *)
singlekor=Import[StringJoin[path,"FILES2012/h2a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h2c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A3 *)
Print["3"];
singlekor=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h3c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B3 *)
singlekor=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h3c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C3 *)
singlekor=Import[StringJoin[path,"FILES2012/h3a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h3c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A4 *)
Print["4"];
singlekor=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h4c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B4 *)
singlekor=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h4c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C4 *)
singlekor=Import[StringJoin[path,"FILES2012/h4a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h4c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A5 *)
Print["5"];
singlekor=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h5c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B5 *)
singlekor=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h5c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C5 *)
singlekor=Import[StringJoin[path,"FILES2012/h5a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h5c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A6 *)
Print["6"];
singlekor=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h6c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B6 *)
singlekor=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h6c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C6 *)
singlekor=Import[StringJoin[path,"FILES2012/h6a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h6c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A7 *)
Print["7"];
singlekor=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h7c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B7 *)
singlekor=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h7c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C7 *)
singlekor=Import[StringJoin[path,"FILES2012/h7a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h7c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A8 *)
Print["8"];
singlekor=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h8c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B8 *)
singlekor=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h8c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C8 *)
singlekor=Import[StringJoin[path,"FILES2012/h8a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h8c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A9 *)
Print["9"];
singlekor=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h9c_epsA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B9 *)
singlekor=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_arrayonly_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h9c_epsB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C9 *)
singlekor=Import[StringJoin[path,"FILES2012/h9a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_genuinearray_fake_studentt.dat"]];
eps=Import[StringJoin[path,"FILES2012/h9c_epsC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

index
diag=DeleteCases[diag,0];
Length[diag]

uplist={};
midlist={};
lowlist={};

(*For[mid=Log[2,0.999],mid≥Log[2,0.25],mid=mid-0.01,                                          (* linear binning *)*)
For[mid=Log[2,0.99],mid≥Log[2,0.25],mid=Power[2,0.5]mid,             (* exponential binning *)

lower=0.95mid;
upper=1.05mid;
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]<upper||diag[[i,1]]>lower,Continue[]];
AppendTo[distro,diag[[i,2]]];
];


If[Length[distro]≥2,

(* begin bootstrap *)
bsvar={};
For[j=1,j≤1000,j++,
bsdistro=RandomChoice[distro,Length[distro]];
AppendTo[bsvar,Variance[bsdistro]+((Mean[distro])^2)];
];
(* end bootstrap *)

(*AppendTo[uplist,{-Log[2,-mid],Log[2,((Quantile[bssd,(3/4)])^2)]}];
AppendTo[midlist,{-Log[2,-mid],Log[2,((StandardDeviation[distro])^2)]}];
AppendTo[lowlist,{-Log[2,-mid],Log[2,((Quantile[bssd,(1/4)])^2)]}];*)
AppendTo[uplist,{mid,Quantile[bsvar,(3/4)]}];
AppendTo[midlist,{mid,Variance[distro]+((Mean[distro])^2)}];
AppendTo[lowlist,{mid,Quantile[bsvar,(1/4)]}];
];

Print[mid]

]

(* 10% ; variance ; h1 to h9 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue}],Plot[-x+Log[2,0.1],{x,0,10},PlotStyle->Directive[Red,Thick]]]

(* 10% ; variance + (mean^2) ; h1 to h9 ; exp binning 0.5 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->All],Plot[-0.05x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]]]

(* 10% ; variance ; h1 to h9 ; exp binning 0.5 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->All],Plot[-0.05x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]]]

lowlist
midlist
uplist

(* 10% ; variance ; h1 to h9 ; exp binning 0.125 *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->All],Plot[-0.05x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]]]

lowlisterr=lowlist
midlisterr=midlist
uplisterr=uplist

Length[midlist]
Length[midlisterr]
Take[midlist,3]
Take[midlisterr,3]
Take[midlist,-3]
Take[midlisterr,-3]

(*difference={};
difference2={}
For[i=1,i≤Length[midlisterr],i++,
For[j=1,j≤Length[midlist],j++,
If[midlist[[j,1]]==midlisterr[[i,1]],
AppendTo[difference,{midlist[[j,1]],Log[2,(2^(midlist[[j,2]]))-(2^(midlisterr[[i,2]]))]}];
AppendTo[difference2,{(2^(-midlist[[j,1]])),(2^(midlist[[j,2]]))-(2^(midlisterr[[i,2]]))}];
If[i≠j,Print[i,"  ",j]];
Break[];
];
];
];*)

lowdifference={};
middifference={};
updifference={};
For[i=1,i≤Length[midlisterr],i++,
For[j=1,j≤Length[midlist],j++,
If[midlist[[j,1]]==midlisterr[[i,1]],
AppendTo[lowdifference,{lowlist[[j,1]],lowlist[[j,2]]-uplisterr[[i,2]]}];
AppendTo[middifference,{midlist[[j,1]],midlist[[j,2]]-midlisterr[[i,2]]}];
AppendTo[updifference,{uplist[[j,1]],uplist[[j,2]]-lowlisterr[[i,2]]}];
If[i≠j,Print[i,"  ",j]];
Break[];
];
];
];

Show[ListLinePlot[{updifference,middifference,lowdifference},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{-1.0,0},{-0.02,0.11}},AxesStyle->18,Ticks->{{-1.5,-1.0,-0.5,0.0},{0.0,0.03,0.06,0.09,0.12}},AspectRatio->1],ListPlot[middifference,PlotStyle->Directive[Black,PointSize[0.02]],PlotRange->All],ListLinePlot[midlist,PlotStyle->Directive[Black,Dashed]],Plot[-0.0693x,{x,-1.5,0},PlotStyle->Directive[Red,Thick]]]

updifference
middifference
lowdifference

(* exp binning 0.125 from 0.99 *)

(* exp binning 0.25 from 0.99 *)

count

(* exp binning 0.5 from 0.99 *)

(* + (mean^2) *)

Export["fig3cc1.png",]

(* BENEFICIAL MUTATIONS *)

uplist={};
midlist={};
lowlist={};
count={};

(*For[mid=Log[2,0.999],mid≥Log[2,0.25],mid=mid-0.05,                                          (* linear binning *)*)
For[mid=Log[2,1.01],mid≤Log[2,1.35],mid=Power[2,0.5]mid,             (* exponential binning *)

lower=0.95mid;
upper=1.05mid;
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]>upper||diag[[i,1]]<lower,Continue[]];
AppendTo[distro,diag[[i,2]]];
];


If[Length[distro]≥2,

(* begin bootstrap *)
bsvar={};
For[j=1,j≤1000,j++,
bsdistro=RandomChoice[distro,Length[distro]];
AppendTo[bsvar,Variance[bsdistro]+((Mean[distro])^2)];
];
(* end bootstrap *)

(*AppendTo[uplist,{-Log[2,-mid],Log[2,((Quantile[bssd,(3/4)])^2)]}];
AppendTo[midlist,{-Log[2,-mid],Log[2,((StandardDeviation[distro])^2)]}];
AppendTo[lowlist,{-Log[2,-mid],Log[2,((Quantile[bssd,(1/4)])^2)]}];*)
AppendTo[uplist,{mid,Quantile[bsvar,(3/4)]}];
AppendTo[midlist,{mid,Variance[distro]+((Mean[distro])^2)}];
AppendTo[lowlist,{mid,Quantile[bsvar,(1/4)]}];
AppendTo[count,{mid,Length[distro]}];

If[mid>-0.1&&((StandardDeviation[distro])^2)>0.01,
Print["z  ",((StandardDeviation[distro])^2),Take[Sort[distro],20]];
];
];

Print[mid]

]

(* 10% : variance + (mean^2) ; exp ; 0.5 ; raw *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{0,0.17},{0,0.12}},Ticks->{{0.0,0.15},{0.0,0.03,0.06,0.09,0.12}},AxesStyle->18]]
ListLogPlot[count,Filling->Axis]

lowlist
midlist
uplist

lowlisterr=lowlist
midlisterr=midlist
uplisterr=uplist

(* 10% : variance + (mean^2) ; exp ; 0.5 ; noise *)
Length[midlist]
Show[ListLinePlot[{lowlist,midlist,uplist},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{0,0.17},{0,0.12}},Ticks->{{0.0,0.15},{0.0,0.03,0.06,0.09,0.12}},AxesStyle->18]]
ListLogPlot[count,Filling->Axis]

Length[midlist]
Length[midlisterr]
Take[midlist,3]
Take[midlisterr,3]
Take[midlist,-3]
Take[midlisterr,-3]

lowdifference={};
middifference={};
updifference={};
For[i=1,i≤Length[midlisterr],i++,
For[j=1,j≤Length[midlist],j++,
If[midlist[[j,1]]==midlisterr[[i,1]],
AppendTo[lowdifference,{lowlist[[j,1]],lowlist[[j,2]]-uplisterr[[i,2]]}];
AppendTo[middifference,{midlist[[j,1]],midlist[[j,2]]-midlisterr[[i,2]]}];
AppendTo[updifference,{uplist[[j,1]],uplist[[j,2]]-lowlisterr[[i,2]]}];
If[i≠j,Print[i,"  ",j]];
Break[];
];
];
];

Show[ListLinePlot[{updifference,middifference,lowdifference},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{0,0.17},{-0.02,0.12}},AxesStyle->18,Ticks->{{0.0,0.1},{0.0,0.03,0.06,0.09,0.12}},AspectRatio->1],ListPlot[middifference,PlotStyle->Directive[Black,PointSize[0.02]],PlotRange->All],ListLinePlot[midlist,PlotStyle->Directive[Black,Dashed]]]

Export["fig3cc2.png",]

updifference
middifference
lowdifference

updifferencebeneficial={{0.014355292977070055`,-0.00041669478838763947`},{0.020301450020011717`,-0.0006075488453661448`},{0.028710585954140114`,-0.000714170111776214`},{0.04060290004002344`,-0.00013061811669102825`},{0.057421171908280236`,-0.000997795252708595`},{0.0812058000800469`,-0.0008879671042965965`},{0.1148423438165605`,-0.00011891571798281061`},{0.16241160016009382`,-0.0005340363514739861`}};
middifferencebeneficial={{0.014355292977070055`,-0.004677684695439141`},{0.020301450020011717`,-0.0008924638410608193`},{0.028710585954140114`,-0.0009141233692451969`},{0.04060290004002344`,-0.0005676354881947229`},{0.057421171908280236`,-0.0011864322586416492`},{0.0812058000800469`,-0.0011362720163099467`},{0.1148423438165605`,-0.00039978653137545737`},{0.16241160016009382`,-0.012904443652050422`}};
lowdifferencebeneficial={{0.014355292977070055`,-0.008854604562155814`},{0.020301450020011717`,-0.0011948287086415534`},{0.028710585954140114`,-0.0010870488595138817`},{0.04060290004002344`,-0.0010271699465623613`},{0.057421171908280236`,-0.0013451107308049687`},{0.0812058000800469`,-0.0013251081792105533`},{0.1148423438165605`,-0.0007348884764786898`},{0.16241160016009382`,-0.02615775225780644`}};

updifferencedeleterious={{-0.01449956969511509`,-0.00021195920066525206`},{-0.020505488111405686`,0.0031167335420148913`},{-0.028999139390230185`,0.026784023986533533`},{-0.04101097622281138`,0.0037921515178961467`},{-0.057998278780460384`,0.000917726314243624`},{-0.08202195244562277`,0.004610106954331564`},{-0.11599655756092078`,0.012886612938846406`},{-0.16404390489124557`,0.015774891570561472`},{-0.2319931151218416`,0.01623290813309239`},{-0.3280878097824912`,0.02214776083213732`},{-0.4639862302436833`,0.04748350291540128`},{-0.6561756195649825`,0.05654279599040492`},{-0.9279724604873667`,0.08692019739748125`},{-1.3123512391299652`,0.04553484777281849`},{-1.8559449209747338`,0.20749305192670953`}};
middifferencedeleterious={{-0.01449956969511509`,-0.0006097944250001144`},{-0.020505488111405686`,0.0022833027394895747`},{-0.028999139390230185`,0.0190497425674844`},{-0.04101097622281138`,0.0009401854840283726`},{-0.057998278780460384`,0.00009600845656592555`},{-0.08202195244562277`,0.003298444443013777`},{-0.11599655756092078`,0.00814247851397144`},{-0.16404390489124557`,0.011231154324090303`},{-0.2319931151218416`,0.01365795974718281`},{-0.3280878097824912`,0.01735874973871735`},{-0.4639862302436833`,0.04173154869905765`},{-0.6561756195649825`,0.04636438211565004`},{-0.9279724604873667`,0.06576969330562393`},{-1.3123512391299652`,0.014169526430252669`},{-1.8559449209747338`,0.18289901687443744`}};
lowdifferencedeleterious={{-0.01449956969511509`,-0.0009942237279627238`},{-0.020505488111405686`,0.0012727238172878896`},{-0.028999139390230185`,0.008809492414182081`},{-0.04101097622281138`,-0.002167931423502747`},{-0.057998278780460384`,-0.0007958691336396109`},{-0.08202195244562277`,0.001855504115994719`},{-0.11599655756092078`,0.002154373288082394`},{-0.16404390489124557`,0.006069307929814322`},{-0.2319931151218416`,0.010653631242807804`},{-0.3280878097824912`,0.012971067297722736`},{-0.4639862302436833`,0.035717223646131474`},{-0.6561756195649825`,0.0358510685443398`},{-0.9279724604873667`,0.041842523589677535`},{-1.3123512391299652`,-0.028269591451600184`},{-1.8559449209747338`,0.11131146913012106`}};

updiff=Join[Reverse[updifferencedeleterious],updifferencebeneficial];
middiff=Join[Reverse[middifferencedeleterious],middifferencebeneficial];
lowdiff=Join[Reverse[lowdifferencedeleterious],lowdifferencebeneficial];

Show[ListLinePlot[{updiff,middiff,lowdiff},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{-2,0.2},{-0.02,0.2}},AxesStyle->18,Ticks->{{-2.0,-1.5,-1.0,-0.5,0,0.2},{0.0,0.03,0.06,0.09,0.12}},AspectRatio->1],ListPlot[middiff,PlotStyle->Directive[Black,PointSize[0.02]],PlotRange->All],ListLinePlot[midlist,PlotStyle->Directive[Black,Dashed]]]

(* ALL IN ONE STEP *)

pow=0.125;   (* 0.125 for fig 2c *)
threshold=1.20;
wrong=0;

(* Diagonal slices raw data *)

diag=Table[0,{250000}];
index=1;

(* Group A *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_common.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/c_epsA.dat"]],
eps=Import[StringJoin[path,"FILES2012/c_epsA_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

(* Group B *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/c_epsB.dat"]],
eps=Import[StringJoin[path,"FILES2012/c_epsB_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

(* Group C *)
singlekor=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/c_epsC.dat"]],
eps=Import[StringJoin[path,"FILES2012/c_epsC_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

index
diag=DeleteCases[diag,0];
Length[diag]


(* DELETERIOUS MUTATIONS *)

uplist={};
midlist={};
lowlist={};
count={};

(*For[mid=-0.02,mid≥-0.4,mid=mid-0.04,                                          (* linear binning *)*)
(*For[mid=-0.1,mid≥Log[2,0.25],mid=mid-0.2,                                          (* linear binning *)*)
For[mid=Log[2,0.998],mid≥Log[2,0.25],mid=Power[2,pow]mid,             (* exponential binning *)

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
(*lower=mid+0.02;
upper=mid-0.02;*)
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]<upper||diag[[i,1]]>lower,Continue[]];
AppendTo[distro,diag[[i,2]]];
];


If[Length[distro]≥2,

(* begin bootstrap *)
bsvar={};
For[j=1,j≤1000,j++,
bsdistro=RandomChoice[distro,Length[distro]];
AppendTo[bsvar,Variance[bsdistro](*+((Mean[distro])^2)*)];
];
(* end bootstrap *)

AppendTo[uplist,{mid,Quantile[bsvar,(3/4)]}];
AppendTo[midlist,{mid,Variance[distro](*+((Mean[distro])^2)*)}];
AppendTo[lowlist,{mid,Quantile[bsvar,(1/4)]}];
AppendTo[count,{mid,Length[distro]}];

If[mid>-0.1&&((StandardDeviation[distro])^2)>0.01,
Print["z  ",((StandardDeviation[distro])^2),Take[Sort[distro],20]];
];
];

Print[mid]

]

uplistdel=uplist;
midlistdel=midlist;
lowlistdel=lowlist;


(* BENEFICIAL MUTATIONS *)

uplist={};
midlist={};
lowlist={};
count={};

(*For[mid=0.02,mid≤0.20,mid=mid+0.04,                                          (* linear binning *)*)
(*For[mid=Log[2,0.999],mid≥Log[2,0.25],mid=mid-0.05,                                          (* linear binning *)*)
For[mid=Log[2,1.002],mid≤Log[2,1.25],mid=Power[2,pow]mid,             (* exponential binning *)

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
(*lower=mid-0.02;
upper=mid+0.02;*)
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]>upper||diag[[i,1]]<lower,Continue[]];
AppendTo[distro,diag[[i,2]]];
];


If[Length[distro]≥2,

(* begin bootstrap *)
bsvar={};
For[j=1,j≤10,j++,
bsdistro=RandomChoice[distro,Length[distro]];
AppendTo[bsvar,Variance[bsdistro](*+((Mean[distro])^2)*)];
];
(* end bootstrap *)

AppendTo[uplist,{mid,Quantile[bsvar,(3/4)]}];
AppendTo[midlist,{mid,Variance[distro](*+((Mean[distro])^2)*)}];
AppendTo[lowlist,{mid,Quantile[bsvar,(1/4)]}];
AppendTo[count,{mid,Length[distro]}];

If[mid>-0.1&&((StandardDeviation[distro])^2)>0.01,
Print["z  ",((StandardDeviation[distro])^2),Take[Sort[distro],20]];
];
];

Print[mid]

]

uplistben=uplist;
midlistben=midlist;
lowlistben=lowlist;

(* NOISE *)

(* Diagonal slices experimental noise *)

diag=Table[0,{2500000}];
index=1;

(* Group A1 *)
Print["1"];
singlekor=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h1c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h1c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B1 *)
singlekor=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h1c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h1c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C1 *)
singlekor=Import[StringJoin[path,"FILES2012/h1a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h1c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h1c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A2 *)
Print["2"];
singlekor=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h2c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h2c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B2 *)
singlekor=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h2c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h2c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C2 *)
singlekor=Import[StringJoin[path,"FILES2012/h2a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h2c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h2c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A3 *)
Print["3"];
singlekor=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h3c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h3c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B3 *)
singlekor=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h3c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h3c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C3 *)
singlekor=Import[StringJoin[path,"FILES2012/h3a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h3c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h3c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A4 *)
Print["4"];
singlekor=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h4c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h4c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B4 *)
singlekor=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h4c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h4c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C4 *)
singlekor=Import[StringJoin[path,"FILES2012/h4a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h4c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h4c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A5 *)
Print["5"];
singlekor=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h5c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h5c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B5 *)
singlekor=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h5c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h5c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C5 *)
singlekor=Import[StringJoin[path,"FILES2012/h5a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h5c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h5c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A6 *)
Print["6"];
singlekor=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h6c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h6c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B6 *)
singlekor=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h6c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h6c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C6 *)
singlekor=Import[StringJoin[path,"FILES2012/h6a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h6c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h6c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A7 *)
Print["7"];
singlekor=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h7c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h7c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B7 *)
singlekor=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h7c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h7c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C7 *)
singlekor=Import[StringJoin[path,"FILES2012/h7a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h7c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h7c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A8 *)
Print["8"];
singlekor=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h8c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h8c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B8 *)
singlekor=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h8c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h8c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C8 *)
singlekor=Import[StringJoin[path,"FILES2012/h8a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h8c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h8c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A9 *)
Print["9"];
singlekor=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h9c_epsA_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h9c_epsA_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group B9 *)
singlekor=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_arrayonly_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h9c_epsB_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h9c_epsB_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

(* Group C9 *)
singlekor=Import[StringJoin[path,"FILES2012/h9a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_genuinearray_fake_studentt.dat"]];
If[wrong==0,
eps=Import[StringJoin[path,"FILES2012/h9c_epsC_fake_studentt.dat"]],
eps=Import[StringJoin[path,"FILES2012/h9c_epsC_fake_studentt_wrongdef.dat"]];
];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[eps[[i,j]]≠"NaN",
diag[[index]]={Mean[{fi,fj}],eps[[i,j]]};
index++;
];
];

];
]

index
diag=DeleteCases[diag,0];
Length[diag]


(* DELETERIOUS MUTATIONS *)

uplist={};
midlist={};
lowlist={};
count={};

(*For[mid=-0.02,mid≥-0.4,mid=mid-0.04,                                          (* linear binning *)*)
(*For[mid=-0.1,mid≥Log[2,0.25],mid=mid-0.2,                                          (* linear binning *)*)
For[mid=Log[2,0.998],mid≥Log[2,0.25],mid=Power[2,pow]mid,             (* exponential binning *)

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
(*lower=mid+0.02;
upper=mid-0.02;*)
distro={};


For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]<upper||diag[[i,1]]>lower,Continue[]];
AppendTo[distro,diag[[i,2]]];
];


If[Length[distro]≥2,

(* begin bootstrap *)
bsvar={};
For[j=1,j≤1000,j++,
bsdistro=RandomChoice[distro,Length[distro]];
AppendTo[bsvar,Variance[bsdistro](*+((Mean[distro])^2)*)];
];
(* end bootstrap *)

AppendTo[uplist,{mid,Quantile[bsvar,(3/4)]}];
AppendTo[midlist,{mid,Variance[distro](*+((Mean[distro])^2)*)}];
AppendTo[lowlist,{mid,Quantile[bsvar,(1/4)]}];
AppendTo[count,{mid,Length[distro]}];

If[mid>-0.1&&((StandardDeviation[distro])^2)>0.01,
Print["z  ",((StandardDeviation[distro])^2),Take[Sort[distro],20]];
];
];

Print[mid]

]

uplistdelnoise=uplist;
midlistdelnoise=midlist;
lowlistdelnoise=lowlist;


(* BENEFICIAL MUTATIONS *)

uplist={};
midlist={};
lowlist={};
count={};

(*For[mid=0.02,mid≤0.20,mid=mid+0.04,                                          (* linear binning *)*)
(*For[mid=Log[2,0.999],mid≥Log[2,0.25],mid=mid-0.05,                                          (* linear binning *)*)
For[mid=Log[2,1.002],mid≤Log[2,1.25],mid=Power[2,pow]mid,             (* exponential binning *)

(*lower=alpha mid;
upper=beta mid;
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]>upper||diag[[i,1]]<lower,Continue[]];
AppendTo[distro,diag[[i,2]]];
];*)

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
(*lower=mid-0.02;
upper=mid+0.02;*)
distro=Table[666,{Length[diag]}];

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]>upper||diag[[i,1]]<lower,Continue[]];
distro[[i]]=diag[[i,2]];
];
distro=DeleteCases[distro,666];


If[Length[distro]≥2,

(* begin bootstrap *)
bsvar={};
For[j=1,j≤10,j++,
bsdistro=RandomChoice[distro,Length[distro]];
AppendTo[bsvar,Variance[bsdistro](*+((Mean[distro])^2)*)];
];
(* end bootstrap *)

AppendTo[uplist,{mid,Quantile[bsvar,(3/4)]}];
AppendTo[midlist,{mid,Variance[distro](*+((Mean[distro])^2)*)}];
AppendTo[lowlist,{mid,Quantile[bsvar,(1/4)]}];
AppendTo[count,{mid,Length[distro]}];

If[mid>-0.1&&((StandardDeviation[distro])^2)>0.01,
Print["z  ",((StandardDeviation[distro])^2),Take[Sort[distro],20]];
];
];

Print[mid]

]

uplistbennoise=uplist;
midlistbennoise=midlist;
lowlistbennoise=lowlist;


(* DIFFERENCE *)

uplist=Join[Reverse[uplistdel],uplistben];
midlist=Join[Reverse[midlistdel],midlistben];
lowlist=Join[Reverse[lowlistdel],lowlistben];

uplistnoise=Join[Reverse[uplistdelnoise],uplistbennoise];
midlistnoise=Join[Reverse[midlistdelnoise],midlistbennoise];
lowlistnoise=Join[Reverse[lowlistdelnoise],lowlistbennoise];


lowdifference={};
middifference={};
updifference={};
For[i=1,i≤Length[midlistnoise],i++,
For[j=1,j≤Length[midlist],j++,
If[midlist[[j,1]]==midlistnoise[[i,1]],
AppendTo[lowdifference,{lowlist[[j,1]],lowlist[[j,2]]-uplistnoise[[i,2]]}];
AppendTo[middifference,{midlist[[j,1]],midlist[[j,2]]-midlistnoise[[i,2]]}];
AppendTo[updifference,{uplist[[j,1]],uplist[[j,2]]-lowlistnoise[[i,2]]}];
If[i≠j,Print[i,"  ",j]];
Break[];
];
];
];


Show[ListLinePlot[{updifference,middifference,lowdifference},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{{-2,0.2},{-0.02,0.2}},AxesStyle->18,Ticks->{{-2.0,-1.5,-1.0,-0.5,0,0.2},{0.0,0.03,0.06,0.09,0.12}},AspectRatio->1],ListPlot[middifference,PlotStyle->Directive[Black,PointSize[0.02]],PlotRange->All],Plot[-0.069x,{x,-2,0},PlotStyle->Directive[Red,Thick]](*,ListLinePlot[midlist,PlotStyle->Directive[Black,Dashed]]*)]
Show[ListLinePlot[{midlist,midlistnoise},PlotRange->{{-2,0.2},{-0.02,0.5}},AxesStyle->18,AspectRatio->1],ListPlot[midlist,PlotStyle->Directive[Black,PointSize[0.02]],PlotRange->All],Plot[-0.069x,{x,-2,0},PlotStyle->Directive[Red,Thick]](*,ListLinePlot[midlist,PlotStyle->Directive[Black,Dashed]]*)]

updifference
middifference
lowdifference

(* wrongdef *)

updifference={{-1.8512817231554215`,0.0007844583011441697`},{-1.6976328252444324`,0.0022406130686034873`},{-1.5567361646261135`,0.0004191375543114651`},{-1.4275333571650788`,-0.0002928616665406607`},{-1.3090538603299153`,0.000295597433905372`},{-1.2004076826952153`,0.0014946656465263572`},{-1.1007786985254624`,0.0023649195308469376`},{-1.009418517221425`,0.0016003172838273299`},{-0.9256408615777107`,0.0030200393585393132`},{-0.8488164126222162`,0.002098982567404855`},{-0.7783680823130568`,0.001807613657110832`},{-0.7137666785825394`,0.0024289555405403434`},{-0.6545269301649577`,0.0020599958900366635`},{-0.6002038413476076`,0.0022756823494746994`},{-0.5503893492627312`,0.0020587724044127892`},{-0.5047092586107125`,0.003582852088671307`},{-0.4628204307888554`,0.003845153797140927`},{-0.4244082063111081`,0.003684942358591868`},{-0.3891840411565284`,0.0028037899817058955`},{-0.3568833392912697`,0.0030738121875393412`},{-0.32726346508247883`,0.0029804437497058453`},{-0.3001019206738038`,0.002719349015179242`},{-0.2751946746313656`,0.004030937922119814`},{-0.25235462930535624`,0.002508381310514783`},{-0.2314102153944277`,0.0028389023955441546`},{-0.21220410315555405`,0.003697814435078938`},{-0.1945920205782642`,0.0020791859115980985`},{-0.17844166964563485`,0.0029529820335960346`},{-0.16363173254123942`,0.0019445841960295993`},{-0.1500509603369019`,0.001955255808830607`},{-0.1375973373156828`,0.0039685791853985`},{-0.12617731465267812`,0.0035355977001141157`},{-0.11570510769721384`,0.0011221823857416689`},{-0.10610205157777702`,0.0008609870744052694`},{-0.0972960102891321`,0.0027390737157176803`},{-0.08922083482281742`,0.0013629865362589342`},{-0.08181586627061971`,0.0017100397415728392`},{-0.07502548016845095`,0.0013484245087491806`},{-0.0687986686578414`,0.0010093557389931713`},{-0.06308865732633906`,0.00041893064353882214`},{-0.05785255384860692`,0.0003587557313994344`},{-0.05305102578888851`,0.0011419010873150142`},{-0.04864800514456605`,0.0003296386335215147`},{-0.04461041741140871`,0.00003810462091912445`},{-0.040907933135309854`,0.001715955827384298`},{-0.03751274008422548`,0.0009411016838740873`},{-0.0343993343289207`,-0.00006587435512356798`},{-0.03154432866316953`,-0.00012695026230871557`},{-0.02892627692430346`,0.0009152794604235651`},{-0.026525512894444256`,0.0014695483267155407`},{-0.024324002572283024`,0.0011483702649940186`},{-0.022305208705704356`,0.0004182323679359644`},{-0.020453966567654927`,0.0005449068234203195`},{-0.01875637004211274`,0.0008199798004919169`},{-0.01719966716446035`,0.00017953295310632524`},{-0.015772164331584765`,-0.0006372201141554072`},{-0.014463138462151729`,-0.000256321782497074`},{-0.013262756447222126`,-0.0007509522155839731`},{-0.01216200128614151`,-0.00038027788226829265`},{-0.011152604352852176`,0.0010813990851952305`},{-0.010226983283827462`,0.00012118189090180821`},{-0.009378185021056367`,-0.000303033766496327`},{-0.008599833582230173`,-0.00036589859999311316`},{-0.00788608216579238`,0.0030182101588465938`},{-0.0072315692310758635`,-0.000504489063055781`},{0.014355292977070055`,-0.00026002663036274703`},{0.015654557996170163`,-0.00031290846612031355`},{0.017071416546280305`,-0.0003304789644684494`},{0.0186165117512683`,-0.00045210310650893213`},{0.02030145002001172`,-0.00023421811277633733`},{0.02213888823114003`,-0.0003608555626290683`},{0.02414262880867007`,-0.0005165580766462113`},{0.026327723402721732`,-0.0006029637919938444`},{0.028710585954140118`,-0.0002568724452957755`},{0.03130911599234033`,-0.00022086458612569125`},{0.034142833092560616`,-0.00038450966189361435`},{0.03723302350253661`,-0.00037419996026875956`},{0.04060290004002345`,-0.00028573325524324086`},{0.04427777646228007`,-0.000431435282125187`},{0.048285257617340156`,-0.00042747349333121674`},{0.05265544680544348`,-0.0002563965136398918`},{0.05742117190828025`,-0.0004217776897056415`},{0.06261823198468068`,-0.0005120881842649408`},{0.06828566618512125`,-0.00038070858280495697`},{0.07446604700507323`,-0.00045342360537934995`},{0.08120580008004691`,-0.0005664926836970645`},{0.08855555292456016`,0.00032649749923338686`},{0.09657051523468033`,-0.000562470317509369`},{0.10531089361088697`,-0.0005551846022954117`},{0.11484234381656053`,-0.00014787117850334616`},{0.1252364639693614`,-0.00015858621091005532`},{0.13657133237024252`,-0.0006711566677715662`},{0.14893209401014648`,0.00040357500281334156`},{0.16241160016009384`,0.0001433839282973812`},{0.17711110584912035`,-0.0018904264316984614`},{0.19314103046936068`,-0.0006274354703677653`}};

middifference={{-1.8512817231554215`,0.0005663424467419848`},{-1.6976328252444324`,0.0013801234496142734`},{-1.5567361646261135`,0.000024189142188596165`},{-1.4275333571650788`,-0.0008640461632594037`},{-1.3090538603299153`,-0.00031476412447603336`},{-1.2004076826952153`,0.0011911343305689654`},{-1.1007786985254624`,0.0017875357640163825`},{-1.009418517221425`,0.0011419109935276004`},{-0.9256408615777107`,0.0026143502613541806`},{-0.8488164126222162`,0.0017934720546098522`},{-0.7783680823130568`,0.001524650419319694`},{-0.7137666785825394`,0.0020636731458835655`},{-0.6545269301649577`,0.0016970276031434027`},{-0.6002038413476076`,0.002015062406370522`},{-0.5503893492627312`,0.0017732605432206933`},{-0.5047092586107125`,0.003159214352196342`},{-0.4628204307888554`,0.0034765880548413863`},{-0.4244082063111081`,0.003367770083939832`},{-0.3891840411565284`,0.0024740748332806187`},{-0.3568833392912697`,0.0027194279825873613`},{-0.32726346508247883`,0.002687271028430539`},{-0.3001019206738038`,0.0024416054891084242`},{-0.2751946746313656`,0.0037015282924789316`},{-0.25235462930535624`,0.0021854426326596054`},{-0.2314102153944277`,0.0024484836608999624`},{-0.21220410315555405`,0.0032409324958094137`},{-0.1945920205782642`,0.0018395768081575377`},{-0.17844166964563485`,0.0026020400697114375`},{-0.16363173254123942`,0.0015573218117581563`},{-0.1500509603369019`,0.0016631077204347629`},{-0.1375973373156828`,0.0033521462610953613`},{-0.12617731465267812`,0.002832819302594362`},{-0.11570510769721384`,0.000760324046753417`},{-0.10610205157777702`,0.0006200878095899223`},{-0.0972960102891321`,0.0022003501324184965`},{-0.08922083482281742`,0.001047871651331269`},{-0.08181586627061971`,0.0013601868979367228`},{-0.07502548016845095`,0.0009901081100697358`},{-0.0687986686578414`,0.0006458023208391933`},{-0.06308865732633906`,-0.00008998315208061901`},{-0.05785255384860692`,0.00013362359544153097`},{-0.05305102578888851`,0.0008378333616978581`},{-0.04864800514456605`,0.000153150896613089`},{-0.04461041741140871`,-0.00013493111516310542`},{-0.040907933135309854`,0.0010026590302935556`},{-0.03751274008422548`,0.00038490622650336355`},{-0.0343993343289207`,-0.0006280282151318217`},{-0.03154432866316953`,-0.00026785557293596495`},{-0.02892627692430346`,0.0004504193989569537`},{-0.026525512894444256`,0.0009509781430758508`},{-0.024324002572283024`,0.000751537529004353`},{-0.022305208705704356`,0.0001492077108538989`},{-0.020453966567654927`,0.000350076960477487`},{-0.01875637004211274`,0.0004194136931073083`},{-0.01719966716446035`,-2.3888183258537806`*^-6},{-0.015772164331584765`,-0.0008029326362027708`},{-0.014463138462151729`,-0.00038661619993747597`},{-0.013262756447222126`,-0.0009764213282989131`},{-0.01216200128614151`,-0.0005422505739738583`},{-0.011152604352852176`,0.0005916163797402556`},{-0.010226983283827462`,-0.000058839733243499105`},{-0.009378185021056367`,-0.0004614512863219877`},{-0.008599833582230173`,-0.0005088139687833999`},{-0.00788608216579238`,0.0014349780978589234`},{-0.0072315692310758635`,-0.0008514677702441589`},{0.014355292977070055`,-0.00035080761344805816`},{0.015654557996170163`,-0.0004324299094645289`},{0.017071416546280305`,-0.00042749473442584376`},{0.0186165117512683`,-0.00047951482336291854`},{0.02030145002001172`,-0.00033288169450452283`},{0.02213888823114003`,-0.000419928327691504`},{0.02414262880867007`,-0.0005246980654008397`},{0.026327723402721732`,-0.0006202377338135376`},{0.028710585954140118`,-0.00031746966158322984`},{0.03130911599234033`,-0.00024395568489452013`},{0.034142833092560616`,-0.0004736966124577782`},{0.03723302350253661`,-0.00043221384017899016`},{0.04060290004002345`,-0.0003857855894682115`},{0.04427777646228007`,-0.0004989895898734768`},{0.048285257617340156`,-0.00042119976414693337`},{0.05265544680544348`,-0.0003653022504621385`},{0.05742117190828025`,-0.0005010017786326725`},{0.06261823198468068`,-0.0005998458322402037`},{0.06828566618512125`,-0.0027110430920321473`},{0.07446604700507323`,-0.00045919773475378294`},{0.08120580008004691`,-0.0006125962266054774`},{0.08855555292456016`,-0.000020064845832202865`},{0.09657051523468033`,-0.0005925015720570426`},{0.10531089361088697`,-0.0006946614164685088`},{0.11484234381656053`,-0.00030429311505861755`},{0.1252364639693614`,-0.0003587222979725478`},{0.13657133237024252`,-0.001356439396802115`},{0.14893209401014648`,-0.000058832132758215644`},{0.16241160016009384`,-0.00189038164525231`},{0.17711110584912035`,-0.006428831752117226`},{0.19314103046936068`,-0.0006187251400087993`}};

lowdifference={{-1.8512817231554215`,-0.0002086143289959804`},{-1.6976328252444324`,0.0003254664256832653`},{-1.5567361646261135`,-0.0005863628178288656`},{-1.4275333571650788`,-0.0014836345437379997`},{-1.3090538603299153`,-0.0010073975967457248`},{-1.2004076826952153`,0.0008047719110205707`},{-1.1007786985254624`,0.0011264013479284998`},{-1.009418517221425`,0.0006767505880334859`},{-0.9256408615777107`,0.002140749328816139`},{-0.8488164126222162`,0.0014707897426962124`},{-0.7783680823130568`,0.001220743528891221`},{-0.7137666785825394`,0.001654470635545044`},{-0.6545269301649577`,0.001343543071425001`},{-0.6002038413476076`,0.0017779797784664268`},{-0.5503893492627312`,0.001453771068881028`},{-0.5047092586107125`,0.0027519509036310584`},{-0.4628204307888554`,0.0031005000080108263`},{-0.4244082063111081`,0.0030357625350980106`},{-0.3891840411565284`,0.0021236288572213913`},{-0.3568833392912697`,0.0023354697075604735`},{-0.32726346508247883`,0.0024161331224023005`},{-0.3001019206738038`,0.002166566520708362`},{-0.2751946746313656`,0.0033293552154521604`},{-0.25235462930535624`,0.0018363933015277283`},{-0.2314102153944277`,0.002032309327923813`},{-0.21220410315555405`,0.002743822893479433`},{-0.1945920205782642`,0.0015665064722559562`},{-0.17844166964563485`,0.0022422146337335866`},{-0.16363173254123942`,0.0011264394775578196`},{-0.1500509603369019`,0.0013801594776145733`},{-0.1375973373156828`,0.0026625551290614963`},{-0.12617731465267812`,0.0019321046727832148`},{-0.11570510769721384`,0.0003663806214349052`},{-0.10610205157777702`,0.00032682886725471437`},{-0.0972960102891321`,0.0015948989835974671`},{-0.08922083482281742`,0.0007110652226070444`},{-0.08181586627061971`,0.000986438926967815`},{-0.07502548016845095`,0.0004837006394043408`},{-0.0687986686578414`,0.00022818869611754646`},{-0.06308865732633906`,-0.0005882719435444832`},{-0.05785255384860692`,-0.00008186000758382246`},{-0.05305102578888851`,0.00048215791997753923`},{-0.04864800514456605`,-7.594248488197123`*^-6},{-0.04461041741140871`,-0.00031131039106069075`},{-0.040907933135309854`,0.00014061881837724608`},{-0.03751274008422548`,-0.00019101520382982682`},{-0.0343993343289207`,-0.0011147916952151224`},{-0.03154432866316953`,-0.00040273367093630235`},{-0.02892627692430346`,-0.00021215855866822003`},{-0.026525512894444256`,0.00035878964502551215`},{-0.024324002572283024`,0.00033606228443500467`},{-0.022305208705704356`,-0.0001659588664573012`},{-0.020453966567654927`,0.0001262196417859407`},{-0.01875637004211274`,-0.000016748625845018844`},{-0.01719966716446035`,-0.0002206231782585456`},{-0.015772164331584765`,-0.001003591076875681`},{-0.014463138462151729`,-0.0005211251736126031`},{-0.013262756447222126`,-0.0012037311680045768`},{-0.01216200128614151`,-0.0007089985415753239`},{-0.011152604352852176`,2.9353469596566685`*^-6},{-0.010226983283827462`,-0.00024679394317311874`},{-0.009378185021056367`,-0.0005960351735763254`},{-0.008599833582230173`,-0.0006339822818053826`},{-0.00788608216579238`,-0.0004421568164719178`},{-0.0072315692310758635`,-0.0011812721921809733`},{0.014355292977070055`,-0.0003846720813981669`},{0.015654557996170163`,-0.000716044463639842`},{0.017071416546280305`,-0.00047185746359856894`},{0.0186165117512683`,-0.0005380492117295332`},{0.02030145002001172`,-0.0003845392554525387`},{0.02213888823114003`,-0.0004830628085646221`},{0.02414262880867007`,-0.0005681939203624111`},{0.026327723402721732`,-0.0008683769881070233`},{0.028710585954140118`,-0.00045064776493238207`},{0.03130911599234033`,-0.0003078694211758235`},{0.034142833092560616`,-0.0005155981588886483`},{0.03723302350253661`,-0.00043147521165987014`},{0.04060290004002345`,-0.00046442493069653`},{0.04427777646228007`,-0.0005560401027852077`},{0.048285257617340156`,-0.0005590429821949502`},{0.05265544680544348`,-0.00041545610733221823`},{0.05742117190828025`,-0.0005423606020588007`},{0.06261823198468068`,-0.0006657211115702159`},{0.06828566618512125`,-0.005081800493321111`},{0.07446604700507323`,-0.0005025527710187735`},{0.08120580008004691`,-0.0007505737363038245`},{0.08855555292456016`,-0.00006538163425872474`},{0.09657051523468033`,-0.0007553001435398546`},{0.10531089361088697`,-0.000809318724498506`},{0.11484234381656053`,-0.0005579153494873031`},{0.1252364639693614`,-0.0005818712990366961`},{0.13657133237024252`,-0.0019308354064749805`},{0.14893209401014648`,-0.0010375013806668294`},{0.16241160016009384`,-0.004801858886185998`},{0.17711110584912035`,-0.012041995989401883`},{0.19314103046936068`,-0.0008698243652618979`}};

(* rightdef *)

updifference={{-1.8512817231554215`,0.05594439273591405`},{-1.6976328252444324`,0.26958927385656606`},{-1.5567361646261135`,0.12879202515918659`},{-1.4275333571650788`,0.0016089567914471525`},{-1.3090538603299153`,0.036486221196462`},{-1.2004076826952153`,0.15056274599675806`},{-1.1007786985254624`,0.20350783242656317`},{-1.009418517221425`,0.06612249375702704`},{-0.9256408615777107`,0.08391473053784464`},{-0.8488164126222162`,0.06348517828898269`},{-0.7783680823130568`,0.04571424850585022`},{-0.7137666785825394`,0.6227308745933267`},{-0.6545269301649577`,0.03182958131354883`},{-0.6002038413476076`,0.033604538513163605`},{-0.5503893492627312`,0.02921237019221747`},{-0.5047092586107125`,0.04385115900348189`},{-0.4628204307888554`,0.04291320910637217`},{-0.4244082063111081`,0.033409478317221915`},{-0.3891840411565284`,0.02098475758704421`},{-0.3568833392912697`,0.026236341974165717`},{-0.32726346508247883`,0.02386737078219829`},{-0.3001019206738038`,0.01651143342176`},{-0.2751946746313656`,0.030937989410132635`},{-0.25235462930535624`,0.016579752964224936`},{-0.2314102153944277`,0.014390396024076168`},{-0.21220410315555405`,0.033567556482999875`},{-0.1945920205782642`,0.010932578323745216`},{-0.17844166964563485`,0.015417217237930384`},{-0.16363173254123942`,0.009416340409496595`},{-0.1500509603369019`,0.0078123631177437714`},{-0.1375973373156828`,0.030038016312651947`},{-0.12617731465267812`,0.055691087088261836`},{-0.11570510769721384`,0.010086590248425903`},{-0.10610205157777702`,0.00473573120589326`},{-0.0972960102891321`,0.019686561448623397`},{-0.08922083482281742`,0.005597257094917768`},{-0.08181586627061971`,0.005048375806155187`},{-0.07502548016845095`,0.00707354584831722`},{-0.0687986686578414`,0.004390078491451444`},{-0.06308865732633906`,0.003073577751057408`},{-0.05785255384860692`,0.001264155344815698`},{-0.05305102578888851`,0.005730335535559412`},{-0.04864800514456605`,0.0010053485417811747`},{-0.04461041741140871`,0.00039474300146988663`},{-0.040907933135309854`,0.019758135838420704`},{-0.03751274008422548`,0.0068197534953748935`},{-0.0343993343289207`,-0.0006561007987936308`},{-0.03154432866316953`,-0.0005695061435426071`},{-0.02892627692430346`,0.012392737957616622`},{-0.026525512894444256`,0.011749405957336225`},{-0.024324002572283024`,0.007750274965374351`},{-0.022305208705704356`,0.0035241745710390547`},{-0.020453966567654927`,0.001842010547305717`},{-0.01875637004211274`,0.004102052202586316`},{-0.01719966716446035`,0.00100203141549826`},{-0.015772164331584765`,-0.0017889218470814876`},{-0.014463138462151729`,-0.0007933795788773483`},{-0.013262756447222126`,-0.001707198531465873`},{-0.01216200128614151`,-0.0007809200205445696`},{-0.011152604352852176`,0.00432270079931976`},{-0.010226983283827462`,0.00033963934984838906`},{-0.009378185021056367`,-0.0007290877970731456`},{-0.008599833582230173`,-0.0007646209752212275`},{-0.00788608216579238`,0.011358632638918292`},{-0.0072315692310758635`,-0.0010782631136392609`},{0.014355292977070055`,-0.0006892805956677666`},{0.015654557996170163`,0.000703708120816513`},{0.017071416546280305`,-0.0008731868582648392`},{0.0186165117512683`,-0.0010390869852652076`},{0.02030145002001172`,-0.0005437866755744795`},{0.02213888823114003`,-0.0007027395999807983`},{0.02414262880867007`,-0.000980099808836609`},{0.026327723402721732`,-0.0008242616854549556`},{0.028710585954140118`,-0.00041287618621576195`},{0.03130911599234033`,-0.0005822714830122371`},{0.034142833092560616`,-0.0007853696222091232`},{0.03723302350253661`,-0.0011467008417288815`},{0.04060290004002345`,-0.0004198841685508327`},{0.04427777646228007`,-0.0007244049211625409`},{0.048285257617340156`,-0.0006020740565786853`},{0.05265544680544348`,-0.00035105865444368025`},{0.05742117190828025`,-0.0012138387687761574`},{0.06261823198468068`,-0.0010091745145198356`},{0.06828566618512125`,-0.0007063089145336668`},{0.07446604700507323`,-0.0007267432478664602`},{0.08120580008004691`,-0.0008839350054486242`},{0.08855555292456016`,0.008623667253816568`},{0.09657051523468033`,-0.0009614226131053442`},{0.10531089361088697`,-0.0009298021699982275`},{0.11484234381656053`,-0.0002368078220601885`},{0.1252364639693614`,-0.00031150456910670164`},{0.13657133237024252`,-0.0007751525637060849`},{0.14893209401014648`,0.0012978956928877752`},{0.16241160016009384`,0.0013526367782861434`},{0.17711110584912035`,-0.005274973430838892`},{0.19314103046936068`,-0.0004764723430282106`}};

middifference={{-1.8512817231554215`,-0.08631730649332436`},{-1.6976328252444324`,0.2031084158232883`},{-1.5567361646261135`,0.07192541148017453`},{-1.4275333571650788`,-0.04817715236657441`},{-1.3090538603299153`,0.014903377301033041`},{-1.2004076826952153`,0.10415894061495465`},{-1.1007786985254624`,0.13636314780221348`},{-1.009418517221425`,0.046530869116911205`},{-0.9256408615777107`,0.04966200009804825`},{-0.8488164126222162`,0.047845191926483836`},{-0.7783680823130568`,0.03855372941543699`},{-0.7137666785825394`,0.33678190142776365`},{-0.6545269301649577`,0.026431918848995185`},{-0.6002038413476076`,0.028407109816232443`},{-0.5503893492627312`,0.025686082625825647`},{-0.5047092586107125`,0.03477760019801045`},{-0.4628204307888554`,0.037209611986417715`},{-0.4244082063111081`,0.029741907981026824`},{-0.3891840411565284`,0.01777180127383486`},{-0.3568833392912697`,0.022441340912650546`},{-0.32726346508247883`,0.0210263826707942`},{-0.3001019206738038`,0.01456650136998869`},{-0.2751946746313656`,0.02753012829524782`},{-0.25235462930535624`,0.01359984703176272`},{-0.2314102153944277`,0.012104112975137781`},{-0.21220410315555405`,0.02654251190908147`},{-0.1945920205782642`,0.008845544055467697`},{-0.17844166964563485`,0.013194686768454957`},{-0.16363173254123942`,0.006950857765320934`},{-0.1500509603369019`,0.006487772067918993`},{-0.1375973373156828`,0.025242724244401837`},{-0.12617731465267812`,0.03820649730446684`},{-0.11570510769721384`,0.0064595316420667116`},{-0.10610205157777702`,0.003527143383453657`},{-0.0972960102891321`,0.014821593519653741`},{-0.08922083482281742`,0.004172542785893154`},{-0.08181586627061971`,0.004132895399689942`},{-0.07502548016845095`,0.004927851697612529`},{-0.0687986686578414`,0.002716855475225693`},{-0.06308865732633906`,0.0016636528027779126`},{-0.05785255384860692`,0.0007214736370212346`},{-0.05305102578888851`,0.0037785434813538262`},{-0.04864800514456605`,0.0005311856609061046`},{-0.04461041741140871`,-0.0002585861425328708`},{-0.040907933135309854`,0.011092046644554187`},{-0.03751274008422548`,0.0032182190987776705`},{-0.0343993343289207`,-0.001841874266151726`},{-0.03154432866316953`,-0.001084306942752487`},{-0.02892627692430346`,0.005823502291187431`},{-0.026525512894444256`,0.007649249662310759`},{-0.024324002572283024`,0.00494022103443432`},{-0.022305208705704356`,0.0018327334539984638`},{-0.020453966567654927`,0.0012678178595626017`},{-0.01875637004211274`,0.002581501060487235`},{-0.01719966716446035`,0.0003943065972124415`},{-0.015772164331584765`,-0.0025213162363986606`},{-0.014463138462151729`,-0.0011675591549534649`},{-0.013262756447222126`,-0.0024564729214190057`},{-0.01216200128614151`,-0.0011420436275715537`},{-0.011152604352852176`,0.001933463710492295`},{-0.010226983283827462`,-0.00014703146045272342`},{-0.009378185021056367`,-0.0011712335485634731`},{-0.008599833582230173`,-0.0010708956067850743`},{-0.00788608216579238`,0.005704063241526522`},{-0.0072315692310758635`,-0.003478789907885225`},{0.014355292977070055`,-0.0007644611281102428`},{0.015654557996170163`,0.0004704381854733928`},{0.017071416546280305`,-0.0011047696336522325`},{0.0186165117512683`,-0.0013210207866406786`},{0.02030145002001172`,-0.0006887498910042064`},{0.02213888823114003`,-0.0007811306573587554`},{0.02414262880867007`,-0.0010785140081920597`},{0.026327723402721732`,-0.0011631911656720868`},{0.028710585954140118`,-0.0006723370942686244`},{0.03130911599234033`,-0.0012520037261421792`},{0.034142833092560616`,-0.0008819052109930343`},{0.03723302350253661`,-0.0015699851224035492`},{0.04060290004002345`,-0.000725577962386107`},{0.04427777646228007`,-0.0015063130148375643`},{0.048285257617340156`,-0.0007855829031774718`},{0.05265544680544348`,-0.0005983491615348465`},{0.05742117190828025`,-0.0012735038046518335`},{0.06261823198468068`,-0.001101081114232422`},{0.06828566618512125`,-0.0008557872963228068`},{0.07446604700507323`,-0.0008467304825909912`},{0.08120580008004691`,-0.001094782432754065`},{0.08855555292456016`,0.004012597147441918`},{0.09657051523468033`,-0.0013582568933626906`},{0.10531089361088697`,-0.0013267651664110936`},{0.11484234381656053`,-0.0004227367792365205`},{0.1252364639693614`,-0.0003561929424297486`},{0.13657133237024252`,-0.0013562807057269702`},{0.14893209401014648`,0.00007633302344326126`},{0.16241160016009384`,-0.005884210673776313`},{0.17711110584912035`,-0.006432680050612214`},{0.19314103046936068`,-0.0007949676662162413`}};

lowdifference={{-1.8512817231554215`,-0.27458618449317473`},{-1.6976328252444324`,0.10312967318250912`},{-1.5567361646261135`,-0.05546234793757035`},{-1.4275333571650788`,-0.09507681950069233`},{-1.3090538603299153`,-0.013129420945706877`},{-1.2004076826952153`,0.050520359590662284`},{-1.1007786985254624`,0.07691539740080021`},{-1.009418517221425`,0.027178717819956136`},{-0.9256408615777107`,0.019556410003562633`},{-0.8488164126222162`,0.03054541804140544`},{-0.7783680823130568`,0.03118294902543048`},{-0.7137666785825394`,0.0426671087220121`},{-0.6545269301649577`,0.020153852073459752`},{-0.6002038413476076`,0.023138979879360918`},{-0.5503893492627312`,0.021568586937301085`},{-0.5047092586107125`,0.02549694295896054`},{-0.4628204307888554`,0.03150300068681477`},{-0.4244082063111081`,0.02605612193566234`},{-0.3891840411565284`,0.01432034358413411`},{-0.3568833392912697`,0.018117745159489735`},{-0.32726346508247883`,0.017487149033672288`},{-0.3001019206738038`,0.012346692417117569`},{-0.2751946746313656`,0.023929452929382818`},{-0.25235462930535624`,0.010364515978917674`},{-0.2314102153944277`,0.009809489486251797`},{-0.21220410315555405`,0.017998764591070346`},{-0.1945920205782642`,0.006580033412277611`},{-0.17844166964563485`,0.010925079498231748`},{-0.16363173254123942`,0.00439520033767191`},{-0.1500509603369019`,0.0051320566135490174`},{-0.1375973373156828`,0.018927151919165358`},{-0.12617731465267812`,0.014412305684119438`},{-0.11570510769721384`,0.0019307843169859085`},{-0.10610205157777702`,0.00202756434857873`},{-0.0972960102891321`,0.009325519050926103`},{-0.08922083482281742`,0.002280456200070913`},{-0.08181586627061971`,0.003002932356408624`},{-0.07502548016845095`,0.0018927509389690825`},{-0.0687986686578414`,0.0008137188368281664`},{-0.06308865732633906`,0.00004034920879092841`},{-0.05785255384860692`,0.00013220745302069785`},{-0.05305102578888851`,0.0017305512327478048`},{-0.04864800514456605`,-0.00003126496961119735`},{-0.04461041741140871`,-0.000865158448747546`},{-0.040907933135309854`,0.0009482589399384825`},{-0.03751274008422548`,-0.0007215660942881414`},{-0.0343993343289207`,-0.0030483812605125926`},{-0.03154432866316953`,-0.0015566524188341912`},{-0.02892627692430346`,-0.0010576276877020986`},{-0.026525512894444256`,0.0030185195577409453`},{-0.024324002572283024`,0.001554798177264607`},{-0.022305208705704356`,-0.0000774967954130703`},{-0.020453966567654927`,0.0006149866419845875`},{-0.01875637004211274`,0.000976697614515124`},{-0.01719966716446035`,-0.0002535155072276238`},{-0.015772164331584765`,-0.0033077123008243875`},{-0.014463138462151729`,-0.001486595704228007`},{-0.013262756447222126`,-0.0031850556882789985`},{-0.01216200128614151`,-0.0014860455514085764`},{-0.011152604352852176`,-0.0008924185152739367`},{-0.010226983283827462`,-0.0006326706560917479`},{-0.009378185021056367`,-0.0015621264455435756`},{-0.008599833582230173`,-0.0013687402564294762`},{-0.00788608216579238`,-0.0005889713071351337`},{-0.0072315692310758635`,-0.005623062312977803`},{0.014355292977070055`,-0.0009736333227209346`},{0.015654557996170163`,-0.001614400040820529`},{0.017071416546280305`,-0.0012865736020874756`},{0.0186165117512683`,-0.00166575053792133`},{0.02030145002001172`,-0.0008491090159005758`},{0.02213888823114003`,-0.000855837071473778`},{0.02414262880867007`,-0.0011641332171897602`},{0.026327723402721732`,-0.0013056815486723154`},{0.028710585954140118`,-0.0007434180175838045`},{0.03130911599234033`,-0.0017168902192137838`},{0.034142833092560616`,-0.0010650713386900071`},{0.03723302350253661`,-0.00206368696706202`},{0.04060290004002345`,-0.001061765709999076`},{0.04427777646228007`,-0.001539541865824972`},{0.048285257617340156`,-0.0010778858456973056`},{0.05265544680544348`,-0.0007415394305551424`},{0.05742117190828025`,-0.0014702863659412616`},{0.06261823198468068`,-0.0012264198819336193`},{0.06828566618512125`,-0.0011705859385338297`},{0.07446604700507323`,-0.0008816562851082202`},{0.08120580008004691`,-0.001350007376543107`},{0.08855555292456016`,0.003936842356264839`},{0.09657051523468033`,-0.0020058338262690573`},{0.10531089361088697`,-0.0017750921357416207`},{0.11484234381656053`,-0.0007985401142203041`},{0.1252364639693614`,-0.001200762199861409`},{0.13657133237024252`,-0.00210015657496866`},{0.14893209401014648`,-0.0007858186297380364`},{0.16241160016009384`,-0.008326464558204624`},{0.17711110584912035`,-0.013302241015344185`},{0.19314103046936068`,-0.0014355507864520687`}};

(* for right def *)

upnew=Transpose[{-Log[-Transpose[updifference][[1]]],Log[Transpose[updifference][[2]]/.x_/;x<0.001->0.001]}];
midnew=Transpose[{-Log[-Transpose[middifference][[1]]],Log[Transpose[middifference][[2]]/.x_/;x<0.001->0.001]}];
lownew=Transpose[{-Log[-Transpose[lowdifference][[1]]],Log[Transpose[lowdifference][[2]]/.x_/;x<0.001->0.001]}];
(*upnew=Transpose[{-Log[-Transpose[updifference][[1]]],Log[Transpose[updifference][[2]]]}];
midnew=Transpose[{-Log[-Transpose[middifference][[1]]],Log[Transpose[middifference][[2]]]}];
lownew=Transpose[{-Log[-Transpose[lowdifference][[1]]],Log[Transpose[lowdifference][[2]]]}];*)

(* for right def *)

Show[ListLinePlot[{upnew,midnew,lownew},PlotStyle->{Directive[Blue,Opacity[0.3]],Directive[Blue],Directive[Blue,Opacity[0.3]]},PlotRange->{{0,-Log[0.03]},{Log[0.002],Log[0.6]}},Filling->{1->{3}},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{{-Log[0.001],"-0.001"},{-Log[0.03],"-0.03"},{-Log[0.1],"-0.1"},{-Log[0.3],"-0.3"},{-Log[1],"-1"}},{{Log[0.001],"0.001"},{Log[0.003],"0.003"},{Log[0.01],"0.01"},{Log[0.03],"0.03"},{Log[0.1],"0.1"},{Log[0.3],"0.3"}},None,None}],Plot[Log[0.083]-x,{x,-Log[2],5},PlotStyle->Directive[Red,Thick]],Plot[0.4-2x,{x,-Log[2],5},PlotStyle->Directive[Gray,Thick,Dashed]],ImageSize->300]

Export[StringJoin[path,"FinalFIGS/2c.pdf"],,ImageResolution->600]

(* for right def *)

Show[ListLinePlot[{upnew,midnew,lownew},PlotStyle->{Directive[Blue,Opacity[0.3]],Directive[Blue],Directive[Blue,Opacity[0.3]]},PlotRange->{{0,-Log[0.03]},{Log[0.002],Log[0.6]}},Filling->{1->{3}},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{{-Log[0.001],"-0.001"},{-Log[0.03],"-0.03"},{-Log[0.1],"-0.1"},{-Log[0.3],"-0.3"},{-Log[1],"-1"}},{{Log[0.001],"0.001"},{Log[0.003],"0.003"},{Log[0.01],"0.01"},{Log[0.03],"0.03"},{Log[0.1],"0.1"},{Log[0.3],"0.3"}},None,None}],Plot[Log[0.083]-x,{x,-Log[2],5},PlotStyle->Directive[Red,Thick]],ImageSize->300]

Show[ListLinePlot[{upnew,midnew,lownew},PlotStyle->{Directive[Blue,Opacity[0.3]],Directive[Blue],Directive[Blue,Opacity[0.3]]},PlotRange->{{0,-Log[0.03]},{Log[0.002],Log[0.6]}},Filling->{1->{3}},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{{-Log[0.001],"-0.001"},{-Log[0.03],"-0.03"},{-Log[0.1],"-0.1"},{-Log[0.3],"-0.3"},{-Log[1],"-1"}},{{Log[0.001],"0.001"},{Log[0.003],"0.003"},{Log[0.01],"0.01"},{Log[0.03],"0.03"},{Log[0.1],"0.1"},{Log[0.3],"0.3"}},None,None}],Plot[Log[0.083]-x,{x,-Log[2],5},PlotStyle->Directive[Red,Thick]],Plot[0.4-2x,{x,-Log[2],5},PlotStyle->Directive[Gray,Thick,Dashed]],ImageSize->300]

(* for wrong def *)

upnew=Transpose[{-Log[-Transpose[updifference][[1]]],Log[Transpose[updifference][[2]]/.x_/;x<0.0003->0.0003]}];
midnew=Transpose[{-Log[-Transpose[middifference][[1]]],Log[Transpose[middifference][[2]]/.x_/;x<0.0003->0.0003]}];
lownew=Transpose[{-Log[-Transpose[lowdifference][[1]]],Log[Transpose[lowdifference][[2]]/.x_/;x<0.0003->0.0003]}];
(*upnew=Transpose[{-Log[-Transpose[updifference][[1]]],Log[Transpose[updifference][[2]]]}];
midnew=Transpose[{-Log[-Transpose[middifference][[1]]],Log[Transpose[middifference][[2]]]}];
lownew=Transpose[{-Log[-Transpose[lowdifference][[1]]],Log[Transpose[lowdifference][[2]]]}];*)

(* for wrong def *)

Show[ListLinePlot[{upnew,midnew,lownew},PlotStyle->{Directive[Red,Opacity[0.3]],Directive[Red],Directive[Red,Opacity[0.3]]},PlotRange->{{0,-Log[0.03]},{Log[0.0003],Log[0.005]}},Filling->{1->{3}},FillingStyle->Directive[Red,Opacity[0.1]],Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{{-Log[0.001],"0.001"},{-Log[0.03],"0.03"},{-Log[0.1],"0.1"},{-Log[0.3],"0.3"},{-Log[1],"1"}},{{Log[0.0005],"0.0005"},{Log[0.001],"0.001"},{Log[0.002],"0.002"},{Log[0.004],"0.004"},{Log[0.03],"0.03"},{Log[0.1],"0.1"},{Log[0.3],"0.3"}},None,None}],ImageSize->300]

Export[StringJoin[path,"FinalFIGS/6a.pdf"],,ImageResolution->600]

(* pow=0.125 0.998 1.002 *)
updifference
middifference
lowdifference

(* inset *)

Show[ListLinePlot[{updifference,middifference,lowdifference},PlotStyle->{Directive[Blue,Opacity[0.3]],Directive[Thickness[0.005],Blue],Directive[Blue,Opacity[0.3]]},PlotRange->{{-0.3,0.19},{-0.007,0.028}},Filling->{1->{3}},AxesOrigin->{0,0},Frame->True,FrameStyle->Directive[18,Thickness[0.017]],AspectRatio->0.75,FrameTicks->{{-0.3,{-0.15,-0.15,{0.03,0}},{0,0,{0.03,0}},{0.15,0.15,{0.03,0}}},{{0,0,{0.03,0}},{0.01,0.01,{0.03,0}},{0.02,0.02,{0.03,0}}},None,None}],Plot[-0.083x,{x,-1,0},PlotStyle->Directive[Red,Thickness[0.015]]],Plot[0,{x,-1,0.18},PlotStyle->Directive[Black,Thickness[0.002]]],Plot[0,{x,0,0.18},PlotStyle->Directive[Red,Thickness[0.015]]],ImageSize->300]

Show[,PlotRange->{{-0.15,0.15},{-0.005,0.01}}]

Export[StringJoin[path,"FinalFIGS/2cInset.pdf"],,ImageResolution->600]

(* pow=0.125 0.999 1.001 *)

(* pow=0.25 0.999 1.001 *)

(* 0.4 *)

(* 0.3 *)

(* 0.2 *)

ListLinePlot[{updifference,middifference,lowdifference},PlotRange->All]

(* SIGN EPISTASIS *)

pow=0.125;
threshold=1.20;

(* Diagonal slices raw data *)

diag=Table[0,{250000}];
index=1;

(* Group A *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_common.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoA.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

(* Group B *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoB.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];


];
If[Mod[i,100]==1,Print[i]];
]

(* Group C *)
singlekor=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoC.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

index
diag=DeleteCases[diag,0];
Length[diag]


toplot={};
toplotplus={};
toplotminus={};

(* DELETERIOUS MUTATIONS *)

(*For[mid=-0.1,mid≥Log[2,0.25],mid=mid-0.2,                                          (* linear binning *)*)
For[mid=Log[2,0.996],mid≥Log[2,0.25],mid=Power[2,pow]mid,             (* exponential binning *)

totalneg=0;
signepneg=0;

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
(*lower=mid+0.1;
upper=mid-0.1;*)
distro={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]<upper||Mean[{diag[[i,1]],diag[[i,2]]}]>lower,Continue[]];
totalneg++;
If[diag[[i,3]]>Max[{diag[[i,1]],diag[[i,2]]}],
signepneg++;
];
];

Print[mid];

If[totalneg>0,
fraction=N[(signepneg/totalneg)];
err=Sqrt[((signepneg (totalneg-signepneg))/(totalneg^3))],
fraction=0;
err=0;
];
AppendTo[toplot,{mid,fraction}];
AppendTo[toplotplus,{mid,fraction+err}];
AppendTo[toplotminus,{mid,fraction-err}];

]


toplot=Reverse[toplot];
toplotplus=Reverse[toplotplus];
toplotminus=Reverse[toplotminus];


(* NEUTRAL 1 *)

mid=Log[2,0.998];

totalneg=0;
signepneg=0;

lower=Log[2,0.996];
upper=Log[2,1.000];
distro={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]>upper||Mean[{diag[[i,1]],diag[[i,2]]}]<lower,Continue[]];
totalneg++;
If[diag[[i,3]]>Max[{diag[[i,1]],diag[[i,2]]}],
signepneg++;
];
];

Print[mid];

If[totalneg>0,
fraction=N[(signepneg/totalneg)];
err=Sqrt[((signepneg (totalneg-signepneg))/(totalneg^3))],
fraction=0;
err=0;
];
AppendTo[toplot,{mid,fraction}];
AppendTo[toplotplus,{mid,fraction+err}];
AppendTo[toplotminus,{mid,fraction-err}];


(* NEUTRAL 2 *)

mid=Log[2,1.002];

totalneg=0;
signepneg=0;

lower=Log[2,1.000];
upper=Log[2,1.004];
distro={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]>upper||Mean[{diag[[i,1]],diag[[i,2]]}]<lower,Continue[]];
totalneg++;
If[diag[[i,3]]<Min[{diag[[i,1]],diag[[i,2]]}],
signepneg++;
];
];

Print[mid];

If[totalneg>0,
fraction=N[(signepneg/totalneg)];
err=Sqrt[((signepneg (totalneg-signepneg))/(totalneg^3))],
fraction=0;
err=0;
];
AppendTo[toplot,{mid,fraction}];
AppendTo[toplotplus,{mid,fraction+err}];
AppendTo[toplotminus,{mid,fraction-err}];


(* BENEFICIAL MUTATIONS *)

(*For[mid=Log[2,0.999],mid≥Log[2,0.25],mid=mid-0.05,                                          (* linear binning *)*)
For[mid=Log[2,1.004],mid≤Log[2,1.35],mid=Power[2,pow]mid,             (* exponential binning *)

totalpos=0;
signeppos=0;

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
distro={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]>upper||Mean[{diag[[i,1]],diag[[i,2]]}]<lower,Continue[]];
totalpos++;
If[diag[[i,3]]<Min[{diag[[i,1]],diag[[i,2]]}],
signeppos++;
];
];

Print[mid];

If[totalpos>0,
fraction=N[(signeppos/totalpos)];
err=Sqrt[((signeppos (totalpos-signeppos))/(totalpos^3))],
fraction=0;
err=0;
];
AppendTo[toplot,{mid,fraction}];
AppendTo[toplotplus,{mid,fraction+err}];
AppendTo[toplotminus,{mid,fraction-err}];

]

ListPlot[toplot,Filling->Axis,Joined->True]

ListLogPlot[toplot,Filling->Axis,Joined->True,PlotRange->{{-0.35,0.15},{0.002,1}},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{{-0.4,"-0.4"},{-0.3,"-0.3"},{-0.2,"-0.2"},{-0.1,"0.1"},{0,"0"},{0.1,"0.1"}},{{0.005,"0.005"},{0.05,"0.05"},{0.5,"0.5"}},{{-0.4,""},{-0.3,""},{-0.2,""},{-0.1,""},{0,""},{0.1,""}},{{0.005,""},{0.05,""},{0.5,""}}}]

ListLogPlot[{toplotplus,toplot,toplotminus},Filling->{1->{3}},Joined->True,PlotRange->{{-0.33,0.13},{0.002,1}},PlotStyle->{Directive[Blue,Opacity[0.15]],Directive[Blue],Directive[Blue,Opacity[0.15]]},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{{-0.4,"-0.4"},{-0.3,"-0.3"},{-0.2,"-0.2"},{-0.1,"0.1"},{0,"0"},{0.1,"0.1"}},{{0.005,"0.005"},{0.05,"0.05"},{0.5,"0.5"}},{{-0.4,""},{-0.3,""},{-0.2,""},{-0.1,""},{0,""},{0.1,""}},{{0.005,""},{0.05,""},{0.5,""}}},ImageSize->300]

toplot

toplot[[108]]

toplotplus=Drop[toplotplus,{108}]
toplotminus=Drop[toplotminus,{108}]

toplot=Drop[toplot,{108}]

Export[StringJoin[path,"FinalFIGS/3b.pdf"],,ImageResolution->600]

matr={{0,0,1},{0,1,2},{1,0,2},{1,1,3}};
Show[ListPlot3D[matr,PlotRange->{0,3},Mesh->0,Filling->Axis,Axes->False,Boxed->False,BoxRatios->{1,1,1},ViewPoint->{1,-2,0.6}],Graphics3D[{Red,Thickness[0.01],{Arrowheads[Large],Arrow[{{0.1,0.1,1.2},{1.0,0.6,2.8}}]}}],ImageSize->300]
matr={{0,0,2},{0,1,1},{1,0,1},{1,1,3}};
Show[ListPlot3D[matr,PlotRange->{0,3.2},Mesh->0,Filling->Axis,Axes->False,Boxed->False,BoxRatios->{1,1,1},ViewPoint->{1,-2,0.6}],Graphics3D[{{Red,Dashed,Thickness[0.01],{Line[{{0.3,-0.1,2.},{0.6,0.3,1.2}}]}},{Red,Thickness[0.01],{Arrowheads[Large],Arrow[{{0.6,0.3,1.2},{1.0,0.5,2.7}}]}}}],ImageSize->300]

Export[StringJoin[path,"FinalFIGS/3a1.pdf"],,ImageResolution->600]
Export[StringJoin[path,"FinalFIGS/3a2.pdf"],,ImageResolution->600]

(* 1% ; pow=0.125 *)

(* 5% ; pow=0.125 *)

(* 10% ; pow=0.125 *)

(* 20% ; pow=0.125 *)

(* NOISE *)

pow=0.5;
threshold=1.20;

(* Diagonal slices experimental noise *)

diag=Table[0,{3000000}];
index=1;

(* Group A1 *)
Print["1"];
singlekor=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h1b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B1 *)
singlekor=Import[StringJoin[path,"FILES2012/h1a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h1b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C1 *)
singlekor=Import[StringJoin[path,"FILES2012/h1a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h1a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h1b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A2 *)
Print["2"];
singlekor=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h2b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B2 *)
singlekor=Import[StringJoin[path,"FILES2012/h2a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h2b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C2 *)
singlekor=Import[StringJoin[path,"FILES2012/h2a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h2a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h2b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A3 *)
Print["3"];
singlekor=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h3b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B3 *)
singlekor=Import[StringJoin[path,"FILES2012/h3a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h3b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C3 *)
singlekor=Import[StringJoin[path,"FILES2012/h3a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h3a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h3b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A4 *)
Print["4"];
singlekor=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h4b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B4 *)
singlekor=Import[StringJoin[path,"FILES2012/h4a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h4b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C4 *)
singlekor=Import[StringJoin[path,"FILES2012/h4a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h4a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h4b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A5 *)
Print["5"];
singlekor=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h5b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B5 *)
singlekor=Import[StringJoin[path,"FILES2012/h5a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h5b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C5 *)
singlekor=Import[StringJoin[path,"FILES2012/h5a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h5a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h5b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A6 *)
Print["6"];
singlekor=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h6b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B6 *)
singlekor=Import[StringJoin[path,"FILES2012/h6a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h6b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C6 *)
singlekor=Import[StringJoin[path,"FILES2012/h6a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h6a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h6b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A7 *)
Print["7"];
singlekor=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h7b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B7 *)
singlekor=Import[StringJoin[path,"FILES2012/h7a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h7b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C7 *)
singlekor=Import[StringJoin[path,"FILES2012/h7a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h7a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h7b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A8 *)
Print["8"];
singlekor=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h8b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B8 *)
singlekor=Import[StringJoin[path,"FILES2012/h8a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h8b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C8 *)
singlekor=Import[StringJoin[path,"FILES2012/h8a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h8a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h8b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

(* Group A9 *)
Print["9"];
singlekor=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h9b_doublekoA_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group B9 *)
singlekor=Import[StringJoin[path,"FILES2012/h9a_common_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_arrayonly_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h9b_doublekoB_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(* Group C9 *)
singlekor=Import[StringJoin[path,"FILES2012/h9a_queryonly_fake_studentt.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/h9a_genuinearray_fake_studentt.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/h9b_doublekoC_fake_studentt.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
]

(*******************************************************)

index
diag=DeleteCases[diag,0];
Length[diag]


toplot={};

(* DELETERIOUS MUTATIONS *)

(*For[mid=-0.1,mid≥Log[2,0.25],mid=mid-0.2,                                          (* linear binning *)*)
For[mid=Log[2,0.995],mid≥Log[2,0.25],mid=Power[2,pow]mid,             (* exponential binning *)

totalneg=0;
signepneg=0;

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
(*lower=mid+0.1;
upper=mid-0.1;*)
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]<upper||diag[[i,1]]>lower,Continue[]];
totalneg++;
If[diag[[i,3]]>Max[{diag[[i,1]],diag[[i,2]]}],
signepneg++;
];
];

Print[mid];

If[totalneg>0,
fraction=N[(signepneg/totalneg)],
fraction=0;
];
AppendTo[toplot,{mid,fraction}];

]

toplot=Reverse[toplot];

(* BENEFICIAL MUTATIONS *)

(*For[mid=Log[2,0.999],mid≥Log[2,0.25],mid=mid-0.05,                                          (* linear binning *)*)
For[mid=Log[2,1.01],mid≤Log[2,1.35],mid=Power[2,pow]mid,             (* exponential binning *)

totalpos=0;
signeppos=0;

lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);
distro={};

For[i=1,i≤Length[diag],i++,
If[diag[[i,1]]>upper||diag[[i,1]]<lower,Continue[]];
totalpos++;
If[diag[[i,3]]<Min[{diag[[i,1]],diag[[i,2]]}],
signeppos++;
];
];

Print[mid];

If[totalpos>0,
fraction=N[(signeppos/totalpos)],
fraction=0;
];
AppendTo[toplot,{mid,fraction}];

]

ListPlot[toplot,Filling->Axis,Joined->True,PlotStyle->Red,FillingStyle->Directive[Red,Opacity[0.15]]]
ListLogPlot[toplot,Filling->Axis,Joined->True,PlotStyle->Red,FillingStyle->Directive[Red,Opacity[0.15]]]
toplot

(* 20% ; pow=0.5 *)

Show[,]

(* 20% ; pow=0.25 *)

Show[,]

N[StandardDeviation[StudentTDistribution[0,1,3]]]
N[StandardDeviation[StudentTDistribution[0,2,3]]]
Show[{Plot[PDF[StudentTDistribution[0,1,3],x],{x,-5,5}],Plot[PDF[StudentTDistribution[0,2,3],x],{x,-5,5}]}]

c=5;
NIntegrate[PDF[StudentTDistribution[0,1,3],x],{x,c,∞}]
NIntegrate[PDF[StudentTDistribution[0,2,3],x],{x,c,∞}]

(* 20% ; pow=0.125 *)
Show[,]
Show[,]

(* VALIDITY OF THE NULL MODEL *)

pow=0.0625;
threshold=1.10;

(* Diagonal slices raw data *)

diag=Table[0,{250000}];
index=1;

(* Group A *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_common.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoA.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

(* Group B *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoB.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];


];
If[Mod[i,100]==1,Print[i]];
]

(* Group C *)
singlekor=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoC.dat"]];

For[i=1,i≤Length[singlekor],i++,
fi=Log[2,singlekor[[i,2]]];
For[j=1,j≤Length[singlekoc],j++,
fj=Log[2,singlekoc[[j,2]]];

If[fj≠0,
If[fi≠0,
r=(fi/fj),
r=1;
];
];

If[(r≥1&&r≤threshold)||((r^(-1))≥1&&(r^(-1))≤threshold),
If[doubleko[[i,j]]≠"NaN"&&doubleko[[i,j]]>0,
diag[[index]]={fi,fj,Log[2,doubleko[[i,j]]]};
index++;
];
];

];
If[Mod[i,100]==1,Print[i]];
]

index
diag=DeleteCases[diag,0];
Length[diag]


toplot={};
toplotplus={};
toplotminus={};

(* DELETERIOUS MUTATIONS *)

For[mid=-0.005,mid≥Log[2,0.4],mid=mid-0.01,                                          (* linear binning *)
(*For[mid=Log[2,0.996],mid≥Log[2,0.25],mid=Power[2,pow]mid,             (* exponential binning *)*)

totalneg=0;
signepneg=0;

(*lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);*)
lower=mid+0.005;
upper=mid-0.005;
distro={};
distroeps={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]<upper||Mean[{diag[[i,1]],diag[[i,2]]}]>lower,Continue[]];
AppendTo[distro,diag[[i,3]]];
AppendTo[distroeps,diag[[i,3]]-diag[[i,1]]-diag[[i,2]]];
];

Print[mid];

If[Length[distro]>1,
AppendTo[toplot,{mid,Mean[distro]}];
AppendTo[toplotplus,{mid,Mean[distro]+StandardDeviation[distroeps]}];
AppendTo[toplotminus,{mid,Mean[distro]-StandardDeviation[distroeps]}],
AppendTo[toplot,{mid,0}];
AppendTo[toplotplus,{mid,0}];
AppendTo[toplotminus,{mid,0}];
];

]






toplot=Reverse[toplot];
toplotplus=Reverse[toplotplus];
toplotminus=Reverse[toplotminus];


(*(* NEUTRAL 1 *)

mid=Log[2,0.998];

totalneg=0;
signepneg=0;

lower=Log[2,0.996];
upper=Log[2,1.000];
distro={};
distroeps={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]>upper||Mean[{diag[[i,1]],diag[[i,2]]}]<lower,Continue[]];
AppendTo[distro,diag[[i,3]]];
AppendTo[distroeps,diag[[i,3]]-diag[[i,1]]-diag[[i,2]]];
];

Print[mid];

If[Length[distro]>1,
AppendTo[toplot,{mid,Mean[distro]}];
AppendTo[toplotplus,{mid,Mean[distro]+StandardDeviation[distroeps]}];
AppendTo[toplotminus,{mid,Mean[distro]-StandardDeviation[distroeps]}],
AppendTo[toplot,{mid,0}];
AppendTo[toplotplus,{mid,0}];
AppendTo[toplotminus,{mid,0}];
];


(* NEUTRAL 2 *)

mid=Log[2,1.002];

totalneg=0;
signepneg=0;

lower=Log[2,1.000];
upper=Log[2,1.004];
distro={};
distroeps={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]>upper||Mean[{diag[[i,1]],diag[[i,2]]}]<lower,Continue[]];
AppendTo[distro,diag[[i,3]]];
AppendTo[distroeps,diag[[i,3]]-diag[[i,1]]-diag[[i,2]]];
];

Print[mid];

If[Length[distro]>1,
AppendTo[toplot,{mid,Mean[distro]}];
AppendTo[toplotplus,{mid,Mean[distro]+StandardDeviation[distroeps]}];
AppendTo[toplotminus,{mid,Mean[distro]-StandardDeviation[distroeps]}],
AppendTo[toplot,{mid,0}];
AppendTo[toplotplus,{mid,0}];
AppendTo[toplotminus,{mid,0}];
];
*)

(* BENEFICIAL MUTATIONS *)

For[mid=0.005,mid≤Log[2,1.2],mid=mid+0.01,                                          (* linear binning *)
(*For[mid=Log[2,1.004],mid≤Log[2,1.35],mid=Power[2,pow]mid,             (* exponential binning *)*)

totalpos=0;
signeppos=0;

(*lower=0.5 mid(1+Power[2,-pow]);
upper=0.5 mid(1+Power[2,pow]);*)
lower=mid-0.005;
upper=mid+0.005;
distro={};
distroeps={};

For[i=1,i≤Length[diag],i++,
If[Mean[{diag[[i,1]],diag[[i,2]]}]>upper||Mean[{diag[[i,1]],diag[[i,2]]}]<lower,Continue[]];
AppendTo[distro,diag[[i,3]]];
AppendTo[distroeps,diag[[i,3]]-diag[[i,1]]-diag[[i,2]]];
];

Print[mid];

If[Length[distro]>1,
AppendTo[toplot,{mid,Mean[distro]}];
AppendTo[toplotplus,{mid,Mean[distro]+StandardDeviation[distroeps]}];
AppendTo[toplotminus,{mid,Mean[distro]-StandardDeviation[distroeps]}],
AppendTo[toplot,{mid,0}];
AppendTo[toplotplus,{mid,0}];
AppendTo[toplotminus,{mid,0}];
];

]

ListPlot[{toplotplus,toplot,toplotminus},Filling->{1->{3}},Joined->True,PlotRange->{{-1.04,0.15},{-2.08,0.3}},PlotStyle->{Directive[Blue,Opacity[0.15]],Directive[Blue],Directive[Blue,Opacity[0.15]]},Axes->True,AxesOrigin->{0.0,0.0},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->1,FrameTicks->{{{-2,"-2"},{-1.5,"-1.5"},{-1.0,"-1.0"},{-0.5,"-0.5"},{0,"0"}},{{-2,"-2"},{-1.0,"-1.0"},{0,"0"}},None,None},ImageSize->300]

toplot

(* pow=0.125 *)

(* pow=0.0625 *)

(* linear 0.02 *)

pxaxis=Plot[0,{x,-1,0.2},PlotStyle->Directive[Black,Thin]]

plin=Plot[2x,{x,-1.1,0.2},PlotStyle->Directive[Red,Thick],PlotRange->{{-1.04,0.15},{-2.08,0.3}},Axes->True,AxesOrigin->{0.0,0.0},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->1,FrameTicks->{{{-2,"-2"},{-1.5,"-1.5"},{-1.0,"-1.0"},{-0.5,"-0.5"},{0,"0"}},{{-2,"-2"},{-1.0,"-1.0"},{0,"0"}},None,None},ImageSize->300]

pdashor=Plot[-1,{x,-1,-0.5},PlotStyle->Directive[Red,Thick,Dashed]]

pdashver=Plot[(10^6)(x+0.5)-2.5,{x,-0.5,-0.4999985},PlotStyle->Directive[Red,Thick,Dashed]]

Show[,plin(*pxaxis,*)(*,pdashor,pdashver*)]

Export[StringJoin[path,"FinalFIGS/1a.pdf"],,ImageResolution->600]

(* threshold=1.20 ; pow=0.125 ; wrongdef *)

updifference={{-1.8512817231554215`,0.002626790144270608`},{-1.6976328252444324`,0.0025513046365585237`},{-1.5567361646261135`,0.00028227818423710394`},{-1.4275333571650788`,-0.0005264817754551117`},{-1.3090538603299153`,0.00004624894271033084`},{-1.2004076826952153`,0.0014668627017037097`},{-1.1007786985254624`,0.0024514049176815106`},{-1.009418517221425`,0.0017248802916125035`},{-0.9256408615777107`,0.002974372955629683`},{-0.8488164126222162`,0.002206946015341745`},{-0.7783680823130568`,0.0019348402352299865`},{-0.7137666785825394`,0.002701858355666864`},{-0.6545269301649577`,0.0020586313278041883`},{-0.6002038413476076`,0.0023111055496748646`},{-0.5503893492627312`,0.0021521698035119503`},{-0.5047092586107125`,0.0036773424777733293`},{-0.4628204307888554`,0.00390783071424365`},{-0.4244082063111081`,0.003775408224161094`},{-0.3891840411565284`,0.002824716454752146`},{-0.3568833392912697`,0.0031642461920271796`},{-0.32726346508247883`,0.003007961957256088`},{-0.3001019206738038`,0.0027315511635600956`},{-0.2751946746313656`,0.004186927695010561`},{-0.25235462930535624`,0.002547759714170812`},{-0.2314102153944277`,0.0028510105522965277`},{-0.21220410315555405`,0.003803530840084933`},{-0.1945920205782642`,0.0021160224509431066`},{-0.17844166964563485`,0.0029794162674338974`},{-0.16363173254123942`,0.002020821418437247`},{-0.1500509603369019`,0.002005448163671926`},{-0.1375973373156828`,0.004077985852716725`},{-0.12617731465267812`,0.0035820797429539355`},{-0.11570510769721384`,0.0011430143153518255`},{-0.10610205157777702`,0.0009081598365976975`},{-0.0972960102891321`,0.0028524991157714394`},{-0.08922083482281742`,0.0013640083513764272`},{-0.08181586627061971`,0.0016973760491689692`},{-0.07502548016845095`,0.0013910905480710972`},{-0.0687986686578414`,0.0010129806073730034`},{-0.06308865732633906`,0.0004508783849131088`},{-0.05785255384860692`,0.00033830442287678696`},{-0.05305102578888851`,0.0012006906737225859`},{-0.04864800514456605`,0.0003119468978523114`},{-0.04461041741140871`,0.00003947103702788414`},{-0.040907933135309854`,0.0016462322690743332`},{-0.03751274008422548`,0.0008783809715549348`},{-0.0343993343289207`,-0.00007922034033326338`},{-0.03154432866316953`,-0.0001278321368750159`},{-0.02892627692430346`,0.000998082793422265`},{-0.026525512894444256`,0.0015196171102346597`},{-0.024324002572283024`,0.0011876932843028246`},{-0.022305208705704356`,0.00041362444898809217`},{-0.020453966567654927`,0.0005792918817359471`},{-0.01875637004211274`,0.0008413883755541277`},{-0.01719966716446035`,0.00016598575124225244`},{-0.015772164331584765`,-0.0006088718726554018`},{-0.014463138462151729`,-0.0002554514060655309`},{-0.013262756447222126`,-0.0007601648817694035`},{-0.01216200128614151`,-0.000372304918167688`},{-0.011152604352852176`,0.0011841416172122168`},{-0.010226983283827462`,0.0001316873988088385`},{-0.009378185021056367`,-0.0002932456409834432`},{-0.008599833582230173`,-0.00038000268576286744`},{-0.00788608216579238`,0.0022120377829514025`},{-0.0072315692310758635`,-0.0004768815943093263`},{0.014355292977070055`,-0.00024531045168513113`},{0.015654557996170163`,-0.000010655712524448987`},{0.017071416546280305`,-0.00034934696816395314`},{0.0186165117512683`,-0.0004651539365805392`},{0.02030145002001172`,-0.00024755204630140895`},{0.02213888823114003`,-0.00032490285888588176`},{0.02414262880867007`,-0.0004716555662716131`},{0.026327723402721732`,-0.000551768064577996`},{0.028710585954140118`,-0.00024930139946303335`},{0.03130911599234033`,-0.000180482709808338`},{0.034142833092560616`,-0.00037047262567906265`},{0.03723302350253661`,-0.0003974011805214661`},{0.04060290004002345`,-0.0003240921486744229`},{0.04427777646228007`,-0.00038591658104621855`},{0.048285257617340156`,-0.00031898098092438204`},{0.05265544680544348`,-0.0002653881147060609`},{0.05742117190828025`,-0.00043537661845716755`},{0.06261823198468068`,-0.0004879067943173996`},{0.06828566618512125`,-0.0026778243578072037`},{0.07446604700507323`,-0.0004332512771671862`},{0.08120580008004691`,-0.0005370323130782183`},{0.08855555292456016`,0.00024327647767011479`},{0.09657051523468033`,-0.0005432876080311246`},{0.10531089361088697`,-0.000605258754096553`},{0.11484234381656053`,-0.0002420697951340694`},{0.1252364639693614`,-0.00009703162326360829`},{0.13657133237024252`,-0.001158824962364009`},{0.14893209401014648`,0.00035981108559237545`},{0.16241160016009384`,-0.00046679558598284416`},{0.17711110584912035`,-0.0016017140069096492`},{0.19314103046936068`,-0.00048707436812035646`}};
middifference={{-1.8512817231554215`,0.002369932233523388`},{-1.6976328252444324`,0.001696430482642649`},{-1.5567361646261135`,-0.0000545098259313718`},{-1.4275333571650788`,-0.0010574445160022867`},{-1.3090538603299153`,-0.0005616133282346776`},{-1.2004076826952153`,0.0011580242232737835`},{-1.1007786985254624`,0.0018345878371467746`},{-1.009418517221425`,0.0012544404348679645`},{-0.9256408615777107`,0.0025792078096193234`},{-0.8488164126222162`,0.001894453591704471`},{-0.7783680823130568`,0.0016363759752585042`},{-0.7137666785825394`,0.002310315193134558`},{-0.6545269301649577`,0.001712460678245676`},{-0.6002038413476076`,0.0020604179289111283`},{-0.5503893492627312`,0.0018674772128737288`},{-0.5047092586107125`,0.0032792347237696555`},{-0.4628204307888554`,0.0035319579240933622`},{-0.4244082063111081`,0.003430844136420373`},{-0.3891840411565284`,0.002492867578428046`},{-0.3568833392912697`,0.0027777650754070658`},{-0.32726346508247883`,0.002704790218780495`},{-0.3001019206738038`,0.0024718869638851388`},{-0.2751946746313656`,0.0038169645411562595`},{-0.25235462930535624`,0.002241715830158005`},{-0.2314102153944277`,0.002462874487240339`},{-0.21220410315555405`,0.003356580323601436`},{-0.1945920205782642`,0.0018588149851391195`},{-0.17844166964563485`,0.0026530000399467074`},{-0.16363173254123942`,0.0016464145989152717`},{-0.1500509603369019`,0.0017375744557723701`},{-0.1375973373156828`,0.0034659463407826973`},{-0.12617731465267812`,0.002873969903656547`},{-0.11570510769721384`,0.0007863692926639784`},{-0.10610205157777702`,0.0006650890546701031`},{-0.0972960102891321`,0.0022440510439693685`},{-0.08922083482281742`,0.0010719178403806068`},{-0.08181586627061971`,0.0013676371823220005`},{-0.07502548016845095`,0.0009984358910299083`},{-0.0687986686578414`,0.000661758880023863`},{-0.06308865732633906`,-0.00007657640760284738`},{-0.05785255384860692`,0.00012255708252858913`},{-0.05305102578888851`,0.0008672350308984011`},{-0.04864800514456605`,0.0001724572022592302`},{-0.04461041741140871`,-0.00011425407413015042`},{-0.040907933135309854`,0.0010148818547275355`},{-0.03751274008422548`,0.0004111360379647866`},{-0.0343993343289207`,-0.0006334329510112105`},{-0.03154432866316953`,-0.000261415828427486`},{-0.02892627692430346`,0.00048750346689311664`},{-0.026525512894444256`,0.0010033585352927144`},{-0.024324002572283024`,0.0007731837686896135`},{-0.022305208705704356`,0.00015948331294277172`},{-0.020453966567654927`,0.00037474303999826845`},{-0.01875637004211274`,0.0004455626098365385`},{-0.01719966716446035`,3.5806446641670903`*^-6},{-0.015772164331584765`,-0.0008006419488130526`},{-0.014463138462151729`,-0.00038793422938282094`},{-0.013262756447222126`,-0.0009772580157905672`},{-0.01216200128614151`,-0.0005349266106881215`},{-0.011152604352852176`,0.0006531314769565944`},{-0.010226983283827462`,-0.00004935859441620549`},{-0.009378185021056367`,-0.0004608024345416165`},{-0.008599833582230173`,-0.0005224185594234316`},{-0.00788608216579238`,0.0015534076002582814`},{-0.0072315692310758635`,-0.0008296009087911692`},{0.014355292977070055`,-0.00033871174489049163`},{0.015654557996170163`,-0.0004182312492480734`},{0.017071416546280305`,-0.00041996662778027495`},{0.0186165117512683`,-0.0004723384299230673`},{0.02030145002001172`,-0.00032724701900109694`},{0.02213888823114003`,-0.00041212711227676274`},{0.02414262880867007`,-0.0005236947100150697`},{0.026327723402721732`,-0.0006115744432939344`},{0.028710585954140118`,-0.00031271605729262636`},{0.03130911599234033`,-0.0002392614972830619`},{0.034142833092560616`,-0.0004667632372988693`},{0.03723302350253661`,-0.00042787301116850476`},{0.04060290004002345`,-0.0003781242956510416`},{0.04427777646228007`,-0.0004931636917093666`},{0.048285257617340156`,-0.00041417829454073096`},{0.05265544680544348`,-0.00035602300404675795`},{0.05742117190828025`,-0.0005024034595697591`},{0.06261823198468068`,-0.000601380846139777`},{0.06828566618512125`,-0.0027150716007312884`},{0.07446604700507323`,-0.00047604101359717825`},{0.08120580008004691`,-0.0006381152791218549`},{0.08855555292456016`,-0.00004962630478973391`},{0.09657051523468033`,-0.0006354565266822259`},{0.10531089361088697`,-0.0007611616599519856`},{0.11484234381656053`,-0.0003352923743683051`},{0.1252364639693614`,-0.00038828608841208977`},{0.13657133237024252`,-0.001473407440218987`},{0.14893209401014648`,-0.00020835914637652784`},{0.16241160016009384`,-0.002155718183559054`},{0.17711110584912035`,-0.00612263568413469`},{0.19314103046936068`,-0.0006995361701797124`}};
lowdifference={{-1.8512817231554215`,0.0015970781800571233`},{-1.6976328252444324`,0.0006225277020772827`},{-1.5567361646261135`,-0.0006586371574738286`},{-1.4275333571650788`,-0.001672103144574587`},{-1.3090538603299153`,-0.001268389417374368`},{-1.2004076826952153`,0.0007669417138960941`},{-1.1007786985254624`,0.0012175388878490662`},{-1.009418517221425`,0.000779224595384165`},{-0.9256408615777107`,0.002043194264304343`},{-0.8488164126222162`,0.0015887595057028463`},{-0.7783680823130568`,0.001337455570812994`},{-0.7137666785825394`,0.0018801953541129914`},{-0.6545269301649577`,0.0013607237566074682`},{-0.6002038413476076`,0.001791545699595209`},{-0.5503893492627312`,0.0015602291301757792`},{-0.5047092586107125`,0.00286397693298606`},{-0.4628204307888554`,0.003139594181098132`},{-0.4244082063111081`,0.003071346708636763`},{-0.3891840411565284`,0.002161282493756863`},{-0.3568833392912697`,0.002410311518184655`},{-0.32726346508247883`,0.002436417975098593`},{-0.3001019206738038`,0.0021808641418101914`},{-0.2751946746313656`,0.0034199601995163384`},{-0.25235462930535624`,0.001889348628803789`},{-0.2314102153944277`,0.0020485827787461255`},{-0.21220410315555405`,0.00285495676799342`},{-0.1945920205782642`,0.001600159664666106`},{-0.17844166964563485`,0.0022495677542459635`},{-0.16363173254123942`,0.0012582057825465637`},{-0.1500509603369019`,0.0014571352336256148`},{-0.1375973373156828`,0.0028298060833826045`},{-0.12617731465267812`,0.0019488043367601527`},{-0.11570510769721384`,0.0003363090425921515`},{-0.10610205157777702`,0.00038318709308079557`},{-0.0972960102891321`,0.001668205930233103`},{-0.08922083482281742`,0.0007346186594579436`},{-0.08181586627061971`,0.001007332273420602`},{-0.07502548016845095`,0.00052637969382589`},{-0.0687986686578414`,0.000243120231012018`},{-0.06308865732633906`,-0.0005549248658266454`},{-0.05785255384860692`,-0.0000985835044022621`},{-0.05305102578888851`,0.00047247784302372115`},{-0.04864800514456605`,0.000016831197615732943`},{-0.04461041741140871`,-0.0003047666818909848`},{-0.040907933135309854`,0.00005556944248234926`},{-0.03751274008422548`,-0.0001452313444972209`},{-0.0343993343289207`,-0.0010309280229834615`},{-0.03154432866316953`,-0.00040509988009389155`},{-0.02892627692430346`,-0.00016361322141838033`},{-0.026525512894444256`,0.0004275294475598896`},{-0.024324002572283024`,0.0003843281506640138`},{-0.022305208705704356`,-0.00016738512481974995`},{-0.020453966567654927`,0.00016049783972986497`},{-0.01875637004211274`,4.7163745982069325`*^-6},{-0.01719966716446035`,-0.00021824200833780376`},{-0.015772164331584765`,-0.0009800166026524481`},{-0.014463138462151729`,-0.0005261467558159828`},{-0.013262756447222126`,-0.0012304964087644925`},{-0.01216200128614151`,-0.0006986418810836719`},{-0.011152604352852176`,8.022515769609204`*^-6},{-0.010226983283827462`,-0.00024858838973811797`},{-0.009378185021056367`,-0.0005852628191778671`},{-0.008599833582230173`,-0.0006415671449396331`},{-0.00788608216579238`,-0.00033847791754865045`},{-0.0072315692310758635`,-0.0011412035989104125`},{0.014355292977070055`,-0.0004788498468799728`},{0.015654557996170163`,-0.0010094536306168313`},{0.017071416546280305`,-0.000513309631195245`},{0.0186165117512683`,-0.0005718878385570704`},{0.02030145002001172`,-0.0003868555683538052`},{0.02213888823114003`,-0.0004774998263787823`},{0.02414262880867007`,-0.0005850101502422255`},{0.026327723402721732`,-0.0008487619770048637`},{0.028710585954140118`,-0.0004641729372422182`},{0.03130911599234033`,-0.00031793302247678655`},{0.034142833092560616`,-0.0004922581647806247`},{0.03723302350253661`,-0.0004626707375852587`},{0.04060290004002345`,-0.00044304039402985823`},{0.04427777646228007`,-0.0006128752898304639`},{0.048285257617340156`,-0.00047074234052837363`},{0.05265544680544348`,-0.0004749799569808003`},{0.05742117190828025`,-0.0005573028010874134`},{0.06261823198468068`,-0.0005793048884061687`},{0.06828566618512125`,-0.007424952794054102`},{0.07446604700507323`,-0.0005240777116226449`},{0.08120580008004691`,-0.000755866981996343`},{0.08855555292456016`,-0.0003566666988739479`},{0.09657051523468033`,-0.0007318951556126009`},{0.10531089361088697`,-0.0008401761908683647`},{0.11484234381656053`,-0.0004469240551294208`},{0.1252364639693614`,-0.0007258216401767552`},{0.13657133237024252`,-0.0023249753102166544`},{0.14893209401014648`,-0.0011048047502837516`},{0.16241160016009384`,-0.004586159174996288`},{0.17711110584912035`,-0.011117322344373529`},{0.19314103046936068`,-0.0008893966009737984`}};

(* threshold=1.20 ; pow=0.125 *)

updifference={{-1.8512817231554215`,0.42314168281425507`},{-1.6976328252444324`,0.2879754184539196`},{-1.5567361646261135`,0.1109098261417687`},{-1.4275333571650788`,-0.00712181906756984`},{-1.3090538603299153`,0.03117018123491269`},{-1.2004076826952153`,0.16413400651076443`},{-1.1007786985254624`,0.1931141396183355`},{-1.009418517221425`,0.07484679443288096`},{-0.9256408615777107`,0.08379703790914161`},{-0.8488164126222162`,0.07154304325787153`},{-0.7783680823130568`,0.05172983691956377`},{-0.7137666785825394`,0.6347855704530211`},{-0.6545269301649577`,0.032847488727961824`},{-0.6002038413476076`,0.034938329371044144`},{-0.5503893492627312`,0.031229041091093247`},{-0.5047092586107125`,0.045997981580754445`},{-0.4628204307888554`,0.043241568837584024`},{-0.4244082063111081`,0.034509420338850974`},{-0.3891840411565284`,0.021513880298300744`},{-0.3568833392912697`,0.02722244935431843`},{-0.32726346508247883`,0.024740311331022044`},{-0.3001019206738038`,0.016884486336754156`},{-0.2751946746313656`,0.031977378509475136`},{-0.25235462930535624`,0.017283907472989687`},{-0.2314102153944277`,0.014756287129992959`},{-0.21220410315555405`,0.03421412115941995`},{-0.1945920205782642`,0.011081666438686317`},{-0.17844166964563485`,0.0159463899274995`},{-0.16363173254123942`,0.009873507432097884`},{-0.1500509603369019`,0.008123508437701609`},{-0.1375973373156828`,0.031207542784288618`},{-0.12617731465267812`,0.04920830993920865`},{-0.11570510769721384`,0.009919104693607877`},{-0.10610205157777702`,0.005002984072828258`},{-0.0972960102891321`,0.019679907646048243`},{-0.08922083482281742`,0.00579051887008255`},{-0.08181586627061971`,0.0052193274496115435`},{-0.07502548016845095`,0.00762773908769293`},{-0.0687986686578414`,0.0048006313171546425`},{-0.06308865732633906`,0.0032351816720942823`},{-0.05785255384860692`,0.001349371237880292`},{-0.05305102578888851`,0.00569525837794509`},{-0.04864800514456605`,0.0011427305969844812`},{-0.04461041741140871`,0.0004139115408755994`},{-0.040907933135309854`,0.02046149307967529`},{-0.03751274008422548`,0.006934264109319921`},{-0.0343993343289207`,-0.00042574737275927026`},{-0.03154432866316953`,-0.000550903762276627`},{-0.02892627692430346`,0.012625735530803421`},{-0.026525512894444256`,0.011735426271553199`},{-0.024324002572283024`,0.007629799861179149`},{-0.022305208705704356`,0.003679074315257367`},{-0.020453966567654927`,0.0019364146774269318`},{-0.01875637004211274`,0.004105704869545911`},{-0.01719966716446035`,0.001024268841697725`},{-0.015772164331584765`,-0.0017497791704436405`},{-0.014463138462151729`,-0.0007925516870205683`},{-0.013262756447222126`,-0.001759070008660137`},{-0.01216200128614151`,-0.0007703208849420481`},{-0.011152604352852176`,0.004231357085602395`},{-0.010226983283827462`,0.0003892803199591899`},{-0.009378185021056367`,-0.0006935474084447078`},{-0.008599833582230173`,-0.0007682693970089568`},{-0.00788608216579238`,0.011868094520243561`},{-0.0072315692310758635`,-0.0010270625351453833`},{0.014355292977070055`,-0.00045995188865101356`},{0.015654557996170163`,0.002588565636174255`},{0.017071416546280305`,-0.0007492685023988109`},{0.0186165117512683`,-0.0010969675384990979`},{0.02030145002001172`,-0.0005493987920086128`},{0.02213888823114003`,-0.0006777065674034232`},{0.02414262880867007`,-0.0008789916198734969`},{0.026327723402721732`,-0.0008174347035871819`},{0.028710585954140118`,-0.0005274838470671758`},{0.03130911599234033`,-0.0001881459354733479`},{0.034142833092560616`,-0.0007378438594246388`},{0.03723302350253661`,-0.0010265951551606592`},{0.04060290004002345`,-0.0005782036071096599`},{0.04427777646228007`,-0.0007412734644806382`},{0.048285257617340156`,-0.0007283289777743249`},{0.05265544680544348`,-0.0003422140510764369`},{0.05742117190828025`,-0.0010491286554957814`},{0.06261823198468068`,-0.0010563476009098846`},{0.06828566618512125`,-0.0006608286656666245`},{0.07446604700507323`,-0.0008055574402882114`},{0.08120580008004691`,-0.001058002532078808`},{0.08855555292456016`,0.008647373602258365`},{0.09657051523468033`,-0.0008999360712653637`},{0.10531089361088697`,-0.0011407475866509456`},{0.11484234381656053`,-0.0002365049926882465`},{0.1252364639693614`,-0.000259103351537055`},{0.13657133237024252`,-0.0011452752586338098`},{0.14893209401014648`,-0.00016691780226154185`},{0.16241160016009384`,0.0003394038914654113`},{0.17711110584912035`,-0.004075180460812778`},{0.19314103046936068`,-0.0005573200161214473`}};
middifference={{-1.8512817231554215`,0.27659314408462676`},{-1.6976328252444324`,0.22392172759446277`},{-1.5567361646261135`,0.07669772179355797`},{-1.4275333571650788`,-0.053567010019586164`},{-1.3090538603299153`,0.009240576353874014`},{-1.2004076826952153`,0.11357464360186195`},{-1.1007786985254624`,0.1365828214387198`},{-1.009418517221425`,0.057310064300104144`},{-0.9256408615777107`,0.05220711872231955`},{-0.8488164126222162`,0.055056967912226674`},{-0.7783680823130568`,0.04387938961193704`},{-0.7137666785825394`,0.34910155098988754`},{-0.6545269301649577`,0.027407728228391888`},{-0.6002038413476076`,0.029854584376286537`},{-0.5503893492627312`,0.02770871212056114`},{-0.5047092586107125`,0.03733268287016364`},{-0.4628204307888554`,0.03863303791300496`},{-0.4244082063111081`,0.03099538605915931`},{-0.3891840411565284`,0.018184523341424307`},{-0.3568833392912697`,0.023352447487061542`},{-0.32726346508247883`,0.021470968798263258`},{-0.3001019206738038`,0.014961400805163531`},{-0.2751946746313656`,0.028639841602908556`},{-0.25235462930535624`,0.014091148242128138`},{-0.2314102153944277`,0.012322422637030556`},{-0.21220410315555405`,0.027431244740121926`},{-0.1945920205782642`,0.009009284062539702`},{-0.17844166964563485`,0.013567864929952982`},{-0.16363173254123942`,0.007430474123922711`},{-0.1500509603369019`,0.006859102400817623`},{-0.1375973373156828`,0.025970660555592436`},{-0.12617731465267812`,0.038628071608715675`},{-0.11570510769721384`,0.006616881276689244`},{-0.10610205157777702`,0.0037328378784941274`},{-0.0972960102891321`,0.015085852144747114`},{-0.08922083482281742`,0.004298245936767002`},{-0.08181586627061971`,0.004209620810049515`},{-0.07502548016845095`,0.005006505864474413`},{-0.0687986686578414`,0.002812522852083447`},{-0.06308865732633906`,0.0017445993113386652`},{-0.05785255384860692`,0.000734520577177356`},{-0.05305102578888851`,0.003914931277542924`},{-0.04864800514456605`,0.0006088379048486523`},{-0.04461041741140871`,-0.00018275899008747282`},{-0.040907933135309854`,0.011215261399059597`},{-0.03751274008422548`,0.003349634559713101`},{-0.0343993343289207`,-0.0018207817248274646`},{-0.03154432866316953`,-0.0010487487659277374`},{-0.02892627692430346`,0.005973364895947839`},{-0.026525512894444256`,0.007852773521585567`},{-0.024324002572283024`,0.00504185703923468`},{-0.022305208705704356`,0.0018853599029614912`},{-0.020453966567654927`,0.0013519139162857228`},{-0.01875637004211274`,0.002680687623349056`},{-0.01719966716446035`,0.0004279094583599201`},{-0.015772164331584765`,-0.002497554135854339`},{-0.014463138462151729`,-0.0011604992734650789`},{-0.013262756447222126`,-0.002443403531684469`},{-0.01216200128614151`,-0.0011112441559442813`},{-0.011152604352852176`,0.0021240326458306855`},{-0.010226983283827462`,-0.00010936869877915421`},{-0.009378185021056367`,-0.001158793184935786`},{-0.008599833582230173`,-0.001090147000810648`},{-0.00788608216579238`,0.006055145128005904`},{-0.0072315692310758635`,-0.0034241269436462145`},{0.014355292977070055`,-0.0007345470001338605`},{0.015654557996170163`,0.0005087598811312644`},{0.017071416546280305`,-0.0010862470295625374`},{0.0186165117512683`,-0.001303528759471383`},{0.02030145002001172`,-0.0006741410568037692`},{0.02213888823114003`,-0.0007629123740248624`},{0.02414262880867007`,-0.0010769769941345645`},{0.026327723402721732`,-0.0011447504846881194`},{0.028710585954140118`,-0.0006620141017621528`},{0.03130911599234033`,-0.001240860482009055`},{0.034142833092560616`,-0.000866728749024418`},{0.03723302350253661`,-0.0015616570782773934`},{0.04060290004002345`,-0.0007085590705032028`},{0.04427777646228007`,-0.0014944295912674907`},{0.048285257617340156`,-0.0007702085436719407`},{0.05265544680544348`,-0.0005785588131586215`},{0.05742117190828025`,-0.001278998492690027`},{0.06261823198468068`,-0.00110726144086878`},{0.06828566618512125`,-0.0008678577878433347`},{0.07446604700507323`,-0.0008823054278619892`},{0.08120580008004691`,-0.0011470806753151178`},{0.08855555292456016`,0.003963143888314296`},{0.09657051523468033`,-0.0014411064286368976`},{0.10531089361088697`,-0.0014474434047300204`},{0.11484234381656053`,-0.00047652320427543356`},{0.1252364639693614`,-0.0004064010609200377`},{0.13657133237024252`,-0.0015480513568542327`},{0.14893209401014648`,-0.00014711240861454804`},{0.16241160016009384`,-0.006351005922496515`},{0.17711110584912035`,-0.006119139508146004`},{0.19314103046936068`,-0.000908910999618217`}};
lowdifference={{-1.8512817231554215`,0.14473204526020966`},{-1.6976328252444324`,0.12260442295606808`},{-1.5567361646261135`,-0.059325233364073776`},{-1.4275333571650788`,-0.10917980718963038`},{-1.3090538603299153`,-0.021541656321775557`},{-1.2004076826952153`,0.06045863099813796`},{-1.1007786985254624`,0.0655101127129714`},{-1.009418517221425`,0.03661678546352651`},{-0.9256408615777107`,0.021932173032087693`},{-0.8488164126222162`,0.03802688790238297`},{-0.7783680823130568`,0.03623588387266179`},{-0.7137666785825394`,0.053450837277791846`},{-0.6545269301649577`,0.021151400028090413`},{-0.6002038413476076`,0.0247103479809412`},{-0.5503893492627312`,0.023533734899561284`},{-0.5047092586107125`,0.027811036499674077`},{-0.4628204307888554`,0.03268527842342879`},{-0.4244082063111081`,0.0272994243596146`},{-0.3891840411565284`,0.01494425876140819`},{-0.3568833392912697`,0.019420301918206255`},{-0.32726346508247883`,0.017855519532387745`},{-0.3001019206738038`,0.012807969152402893`},{-0.2751946746313656`,0.0250406291344964`},{-0.25235462930535624`,0.010587475055497666`},{-0.2314102153944277`,0.009978122649953415`},{-0.21220410315555405`,0.01894645731744984`},{-0.1945920205782642`,0.006835149244874751`},{-0.17844166964563485`,0.01131852112014949`},{-0.16363173254123942`,0.00487955582981193`},{-0.1500509603369019`,0.005468606867891901`},{-0.1375973373156828`,0.0195821952846221`},{-0.12617731465267812`,0.013176796837794826`},{-0.11570510769721384`,0.002240759069467811`},{-0.10610205157777702`,0.0022801235855580866`},{-0.0972960102891321`,0.009700253979561885`},{-0.08922083482281742`,0.002291215992243173`},{-0.08181586627061971`,0.0031107009991204427`},{-0.07502548016845095`,0.0019570975213249863`},{-0.0687986686578414`,0.0010458897986684017`},{-0.06308865732633906`,0.0000219856036166163`},{-0.05785255384860692`,0.00013283176584069807`},{-0.05305102578888851`,0.001825688066337686`},{-0.04864800514456605`,0.00005953327786735116`},{-0.04461041741140871`,-0.0008607322103375082`},{-0.040907933135309854`,0.0011608038325710366`},{-0.03751274008422548`,-0.0004739929225485561`},{-0.0343993343289207`,-0.0029727677538576216`},{-0.03154432866316953`,-0.001511773592531625`},{-0.02892627692430346`,-0.000879757838581941`},{-0.026525512894444256`,0.003585539898703466`},{-0.024324002572283024`,0.0016166209672211253`},{-0.022305208705704356`,-0.00006407306061013279`},{-0.020453966567654927`,0.0007188508345438039`},{-0.01875637004211274`,0.0010179980274794029`},{-0.01719966716446035`,-0.00023236146632628265`},{-0.015772164331584765`,-0.0031477518158896938`},{-0.014463138462151729`,-0.0015259868189424711`},{-0.013262756447222126`,-0.003223470038623527`},{-0.01216200128614151`,-0.001497321213015807`},{-0.011152604352852176`,-0.0006232602667820978`},{-0.010226983283827462`,-0.0005729771650973517`},{-0.009378185021056367`,-0.0016036117833065234`},{-0.008599833582230173`,-0.0013552382218404789`},{-0.00788608216579238`,-0.0003189424391117357`},{-0.0072315692310758635`,-0.004140758753232766`},{0.014355292977070055`,-0.0008699547195051838`},{0.015654557996170163`,-0.0017051204828739933`},{0.017071416546280305`,-0.0013316154381741413`},{0.0186165117512683`,-0.001441408460648983`},{0.02030145002001172`,-0.0008180908733491452`},{0.02213888823114003`,-0.0008993644885188826`},{0.02414262880867007`,-0.0011202607064543782`},{0.026327723402721732`,-0.0012740008464906351`},{0.028710585954140118`,-0.0007819327962716087`},{0.03130911599234033`,-0.0022598727886016714`},{0.034142833092560616`,-0.0010240166901464706`},{0.03723302350253661`,-0.002235576222540783`},{0.04060290004002345`,-0.0008743179734883267`},{0.04427777646228007`,-0.0019727608908284514`},{0.048285257617340156`,-0.0009555975771411397`},{0.05265544680544348`,-0.0007621285314262784`},{0.05742117190828025`,-0.0015012921912132464`},{0.06261823198468068`,-0.001220990518320948`},{0.06828566618512125`,-0.001253017613770192`},{0.07446604700507323`,-0.001014502311626625`},{0.08120580008004691`,-0.0013188064712209902`},{0.08855555292456016`,-0.0005742295626722114`},{0.09657051523468033`,-0.0016299487968049599`},{0.10531089361088697`,-0.001536283037322935`},{0.11484234381656053`,-0.0006900594782457438`},{0.1252364639693614`,-0.0010428463081622718`},{0.13657133237024252`,-0.0027561320379770105`},{0.14893209401014648`,-0.001654251765809976`},{0.16241160016009384`,-0.009378927435429816`},{0.17711110584912035`,-0.011564216699598633`},{0.19314103046936068`,-0.0014118926748925079`}};

(* threshold=1.20 ; pow=0.0625 *)
updifference
middifference
lowdifference

(* threshold=1.10 ; pow=0.25 *)
updifference
middifference
lowdifference

(* threshold=1.10 ; pow=0.125 *)

updifference={{-1.8512817231554215`,0.2200812381227107`},{-1.6976328252444324`,0.3364454867068711`},{-1.4275333571650788`,0.008705552650384335`},{-1.3090538603299153`,0.034766167311957155`},{-1.2004076826952153`,0.34814879866945614`},{-1.1007786985254624`,0.2489355510776035`},{-1.009418517221425`,0.10372483667977679`},{-0.9256408615777107`,0.09898424740534571`},{-0.8488164126222162`,0.10648941252062794`},{-0.7783680823130568`,0.043423785392164425`},{-0.7137666785825394`,1.1863194783460955`},{-0.6545269301649577`,0.047957474638353884`},{-0.6002038413476076`,0.04096189508183211`},{-0.5503893492627312`,0.028878136570034425`},{-0.5047092586107125`,0.03256830563802144`},{-0.4628204307888554`,0.0526374333037684`},{-0.4244082063111081`,0.03801907649027869`},{-0.3891840411565284`,0.02388527628461199`},{-0.3568833392912697`,0.035983916706661664`},{-0.32726346508247883`,0.023670371898671792`},{-0.3001019206738038`,0.02003525239536292`},{-0.2751946746313656`,0.03484510903084911`},{-0.25235462930535624`,0.02800862477724508`},{-0.2314102153944277`,0.015872018837420017`},{-0.21220410315555405`,0.01720980768832438`},{-0.1945920205782642`,0.012278007681064268`},{-0.17844166964563485`,0.014224136713523454`},{-0.16363173254123942`,0.01621333376199031`},{-0.1500509603369019`,0.007964164006566824`},{-0.1375973373156828`,0.02369494007681852`},{-0.12617731465267812`,0.13844703951851622`},{-0.11570510769721384`,0.014802104712939534`},{-0.10610205157777702`,0.006310470645567867`},{-0.0972960102891321`,0.028722692606304882`},{-0.08922083482281742`,0.003868936797314695`},{-0.08181586627061971`,0.00434868275672902`},{-0.07502548016845095`,0.0046063069198698185`},{-0.0687986686578414`,0.004729870331443883`},{-0.06308865732633906`,0.0045571584638310495`},{-0.05785255384860692`,0.0011832310971921127`},{-0.05305102578888851`,0.0075218554575047815`},{-0.04864800514456605`,0.0016954021900723532`},{-0.04461041741140871`,0.0017936702716985884`},{-0.040907933135309854`,0.004825578427929334`},{-0.03751274008422548`,0.0017090515764146045`},{-0.0343993343289207`,-0.000015957695804181236`},{-0.03154432866316953`,-0.0006336131535757531`},{-0.02892627692430346`,0.02346083086907151`},{-0.026525512894444256`,0.03051974959431216`},{-0.024324002572283024`,0.012458565467869635`},{-0.022305208705704356`,0.006197777228274494`},{-0.020453966567654927`,0.0037766566670917774`},{-0.01875637004211274`,0.007685238133698634`},{-0.01719966716446035`,0.0014936188922752697`},{-0.015772164331584765`,-0.0027705012455215856`},{-0.014463138462151729`,-0.0002823623044435979`},{-0.013262756447222126`,-0.001173316058002648`},{-0.01216200128614151`,-0.0008930539576328174`},{-0.011152604352852176`,0.006393403111460621`},{-0.010226983283827462`,-0.00011153424017468`},{-0.009378185021056367`,-0.0007607283520778391`},{-0.008599833582230173`,-0.0010013498721091869`},{-0.00788608216579238`,0.0012444198564958119`},{-0.0072315692310758635`,-0.0015300437128338204`},{0.014355292977070055`,-0.00047389212357726676`},{0.015654557996170163`,-0.001968555040898409`},{0.017071416546280305`,-0.0008262958024775702`},{0.0186165117512683`,-0.000975424043453283`},{0.02030145002001172`,-0.00036017750997528156`},{0.02213888823114003`,-0.0004921177912536072`},{0.02414262880867007`,-0.001318300054248295`},{0.026327723402721732`,-0.0008385050363304085`},{0.028710585954140118`,-0.0008055185815521333`},{0.03130911599234033`,0.00024800792047206333`},{0.034142833092560616`,-0.0005737099848630656`},{0.03723302350253661`,-0.0008116068594754898`},{0.04060290004002345`,-0.0004765374065389626`},{0.04427777646228007`,-0.0009881924785975693`},{0.048285257617340156`,-0.00041107689710735804`},{0.05265544680544348`,-0.00014910957673321297`},{0.05742117190828025`,-0.0010643605653847571`},{0.06261823198468068`,-0.0011118596058359235`},{0.06828566618512125`,-0.0006420241498982465`},{0.07446604700507323`,-0.0008167257890511312`},{0.08120580008004691`,-0.000849765835395455`},{0.08855555292456016`,-0.0003878391425698811`},{0.09657051523468033`,-0.0012389415786325266`},{0.10531089361088697`,-0.0011016772649469415`},{0.11484234381656053`,-0.00019022362832091418`},{0.1252364639693614`,-0.00018165205898326665`},{0.13657133237024252`,-0.001371778818923065`},{0.14893209401014648`,-0.0012023608154909126`},{0.16241160016009384`,-0.0009946724120300614`},{0.17711110584912035`,-0.0003639004176227015`}};
middifference={{-1.8512817231554215`,0.19470217675290707`},{-1.6976328252444324`,0.2473440078162003`},{-1.4275333571650788`,-0.030704737571050494`},{-1.3090538603299153`,-0.0013185547790569851`},{-1.2004076826952153`,0.2735722957762632`},{-1.1007786985254624`,0.15777029425139308`},{-1.009418517221425`,0.06888165627030415`},{-0.9256408615777107`,0.08075221310997473`},{-0.8488164126222162`,0.08262696534939167`},{-0.7783680823130568`,0.03366921138113365`},{-0.7137666785825394`,0.6324169489834096`},{-0.6545269301649577`,0.03831585984374964`},{-0.6002038413476076`,0.03319400279150024`},{-0.5503893492627312`,0.024180119835030035`},{-0.5047092586107125`,0.021865644364754598`},{-0.4628204307888554`,0.04558570931700079`},{-0.4244082063111081`,0.03309329932532618`},{-0.3891840411565284`,0.020208038368980063`},{-0.3568833392912697`,0.02855128748558458`},{-0.32726346508247883`,0.019191441223481532`},{-0.3001019206738038`,0.01650652669468483`},{-0.2751946746313656`,0.030677761750100722`},{-0.25235462930535624`,0.02018661502571678`},{-0.2314102153944277`,0.013078645751349273`},{-0.21220410315555405`,0.014140075381599254`},{-0.1945920205782642`,0.009481842677461595`},{-0.17844166964563485`,0.012068143949139624`},{-0.16363173254123942`,0.010324243751530777`},{-0.1500509603369019`,0.006084623756909109`},{-0.1375973373156828`,0.018775554379805853`},{-0.12617731465267812`,0.07769001014846652`},{-0.11570510769721384`,0.00930911592868181`},{-0.10610205157777702`,0.004106824813344299`},{-0.0972960102891321`,0.020451123656351686`},{-0.08922083482281742`,0.0029966104329306148`},{-0.08181586627061971`,0.003155250134867456`},{-0.07502548016845095`,0.003527026859742626`},{-0.0687986686578414`,0.0021596150520264337`},{-0.06308865732633906`,0.0028361900998717547`},{-0.05785255384860692`,0.00025611673098936173`},{-0.05305102578888851`,0.004224917875434172`},{-0.04864800514456605`,0.0010542072853694817`},{-0.04461041741140871`,0.0007647318295894816`},{-0.040907933135309854`,0.0015479016067263228`},{-0.03751274008422548`,0.001017419546651615`},{-0.0343993343289207`,-0.002541620628585722`},{-0.03154432866316953`,-0.0013745810288293497`},{-0.02892627692430346`,0.012269892117997557`},{-0.026525512894444256`,0.020138303532373107`},{-0.024324002572283024`,0.008175561092955414`},{-0.022305208705704356`,0.0030222055038060954`},{-0.020453966567654927`,0.002743210918062985`},{-0.01875637004211274`,0.003919961042305164`},{-0.01719966716446035`,0.0005959036579398329`},{-0.015772164331584765`,-0.004032711287149798`},{-0.014463138462151729`,-0.0006968338747267038`},{-0.013262756447222126`,-0.0026740423299277923`},{-0.01216200128614151`,-0.0013813460112933882`},{-0.011152604352852176`,0.002446800736240028`},{-0.010226983283827462`,-0.0009298606769037264`},{-0.009378185021056367`,-0.001168313299924139`},{-0.008599833582230173`,-0.0012971712629225053`},{-0.00788608216579238`,0.0004804677909297523`},{-0.0072315692310758635`,-0.006530919240508381`},{0.014355292977070055`,-0.00044629292965690207`},{0.015654557996170163`,-0.002006812123328445`},{0.017071416546280305`,-0.0009750934413365331`},{0.0186165117512683`,-0.001521664637071625`},{0.02030145002001172`,-0.0006982873895908879`},{0.02213888823114003`,-0.0007122572459868264`},{0.02414262880867007`,-0.0013240468919592087`},{0.026327723402721732`,-0.0014690803210195304`},{0.028710585954140118`,-0.0008815731551348929`},{0.03130911599234033`,-0.0014020276456445891`},{0.034142833092560616`,-0.001072315184004483`},{0.03723302350253661`,-0.002026421695318712`},{0.04060290004002345`,-0.00036517121130608555`},{0.04427777646228007`,-0.002267704839951868`},{0.048285257617340156`,-0.0007479002799173097`},{0.05265544680544348`,-0.0006852368960053965`},{0.05742117190828025`,-0.0013071236772670995`},{0.06261823198468068`,-0.0012411337844578847`},{0.06828566618512125`,-0.001036338244837622`},{0.07446604700507323`,-0.000901593979264435`},{0.08120580008004691`,-0.0011954720334974647`},{0.08855555292456016`,-0.0005117606522971761`},{0.09657051523468033`,-0.0020567217869695833`},{0.10531089361088697`,-0.0018402051763869035`},{0.11484234381656053`,-0.00033449673656311724`},{0.1252364639693614`,-0.0003214912967313597`},{0.13657133237024252`,-0.0018252472309765598`},{0.14893209401014648`,-0.0015666744922104227`},{0.16241160016009384`,-0.01729200057943048`},{0.17711110584912035`,-0.009253857846907892`}};
lowdifference={{-1.8512817231554215`,0.12309845733136185`},{-1.6976328252444324`,0.07843625321847564`},{-1.4275333571650788`,-0.08757739278545845`},{-1.3090538603299153`,-0.04996997867215812`},{-1.2004076826952153`,0.15732376346371404`},{-1.1007786985254624`,0.05921301288194197`},{-1.009418517221425`,0.03149583860115704`},{-0.9256408615777107`,0.05739057264066753`},{-0.8488164126222162`,0.05909652772045197`},{-0.7783680823130568`,0.023948615305823498`},{-0.7137666785825394`,0.05854572037058185`},{-0.6545269301649577`,0.02712484366056914`},{-0.6002038413476076`,0.024928610428795746`},{-0.5503893492627312`,0.019996562868614457`},{-0.5047092586107125`,0.012840333227874937`},{-0.4628204307888554`,0.03910856617102022`},{-0.4244082063111081`,0.026797613621151028`},{-0.3891840411565284`,0.015462835528062406`},{-0.3568833392912697`,0.020597045136193957`},{-0.32726346508247883`,0.014165955360461238`},{-0.3001019206738038`,0.012882476116190937`},{-0.2751946746313656`,0.0258160258829777`},{-0.25235462930535624`,0.012551524356125937`},{-0.2314102153944277`,0.009906474457017768`},{-0.21220410315555405`,0.011004149486602015`},{-0.1945920205782642`,0.005714086359208291`},{-0.17844166964563485`,0.008630508881917624`},{-0.16363173254123942`,0.004058569636550347`},{-0.1500509603369019`,0.004067057011343908`},{-0.1375973373156828`,0.012903009450595158`},{-0.12617731465267812`,0.01137394797839248`},{-0.11570510769721384`,0.0026931357901397376`},{-0.10610205157777702`,0.0010429536849879874`},{-0.0972960102891321`,0.010362713806126493`},{-0.08922083482281742`,0.0020377831552619062`},{-0.08181586627061971`,0.0016923505384499613`},{-0.07502548016845095`,0.0023444147295976197`},{-0.0687986686578414`,0.00008581042718235933`},{-0.06308865732633906`,0.0007948650507976687`},{-0.05785255384860692`,-0.0007530645881985709`},{-0.05305102578888851`,0.0003409559794884413`},{-0.04864800514456605`,0.0003774027174486428`},{-0.04461041741140871`,-0.0002703931929057789`},{-0.040907933135309854`,-0.0021403774341799417`},{-0.03751274008422548`,0.00029033791287901185`},{-0.0343993343289207`,-0.004739661569317023`},{-0.03154432866316953`,-0.0020259328997303916`},{-0.02892627692430346`,0.0007499431106991585`},{-0.026525512894444256`,0.009352550836777707`},{-0.024324002572283024`,0.003014441497234262`},{-0.022305208705704356`,-0.0003452605444014666`},{-0.020453966567654927`,0.001706899371247077`},{-0.01875637004211274`,-0.0003361841739342279`},{-0.01719966716446035`,-0.00045141974674566855`},{-0.015772164331584765`,-0.005048336428693009`},{-0.014463138462151729`,-0.0011218460778653913`},{-0.013262756447222126`,-0.004283631753931509`},{-0.01216200128614151`,-0.001870467923980153`},{-0.011152604352852176`,-0.0017572409765159083`},{-0.010226983283827462`,-0.0016772910932638376`},{-0.009378185021056367`,-0.0015363764287594595`},{-0.008599833582230173`,-0.0016490214996405942`},{-0.00788608216579238`,-0.0004676531972181231`},{-0.0072315692310758635`,-0.0113323713517357`},{0.014355292977070055`,-0.0008756673390425689`},{0.015654557996170163`,-0.0025818494741835884`},{0.017071416546280305`,-0.0012558546753090405`},{0.0186165117512683`,-0.0017756259867131481`},{0.02030145002001172`,-0.0008153139239270213`},{0.02213888823114003`,-0.0008822529394163661`},{0.02414262880867007`,-0.0015005399136568892`},{0.026327723402721732`,-0.0018555038881362255`},{0.028710585954140118`,-0.0011621761707246876`},{0.03130911599234033`,-0.003040220464601003`},{0.034142833092560616`,-0.0012449157246258308`},{0.03723302350253661`,-0.002921649156628483`},{0.04060290004002345`,-0.0009215499479166148`},{0.04427777646228007`,-0.002613656973113494`},{0.048285257617340156`,-0.0011560068935971574`},{0.05265544680544348`,-0.0008470713538244446`},{0.05742117190828025`,-0.0015765080134894846`},{0.06261823198468068`,-0.0012992951123426493`},{0.06828566618512125`,-0.0012779060546633417`},{0.07446604700507323`,-0.0010201283718769994`},{0.08120580008004691`,-0.001240865705916537`},{0.08855555292456016`,-0.0007240909754905771`},{0.09657051523468033`,-0.002106663938371573`},{0.10531089361088697`,-0.001962970459834416`},{0.11484234381656053`,-0.0009714947428242364`},{0.1252364639693614`,-0.001290387971861156`},{0.13657133237024252`,-0.0031611199939626236`},{0.14893209401014648`,-0.002055087476764581`},{0.16241160016009384`,-0.03273499851746872`},{0.17711110584912035`,-0.010647328388203129`}};

(* threshold=1.10 ; pow=0.0625 *)
updifference
middifference
lowdifference

x/;x_<6,x->7

middifference/.x_/;x<0->666

upnew=Transpose[{-Log[-Transpose[updifference][[1]]],Log[Transpose[updifference][[2]]/.x_/;x<0.0003->0.0003]}];
midnew=Transpose[{-Log[-Transpose[middifference][[1]]],Log[Transpose[middifference][[2]]/.x_/;x<0.0003->0.0003]}];
lownew=Transpose[{-Log[-Transpose[lowdifference][[1]]],Log[Transpose[lowdifference][[2]]/.x_/;x<0.0003->0.0003]}];

(* for right def *)
Show[ListLinePlot[{upnew,midnew,lownew},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{Log[0.0003],Log[0.6]},Filling->{1->{3}},AxesStyle->18,AspectRatio->0.8,AxesOrigin->{-Log[0.01],Log[0.0003]},Ticks->{{{-Log[0.001],"0.001"},{-Log[0.03],"0.03"},{-Log[0.1],"0.1"},{-Log[0.3],"0.3"},{-Log[1],"1"}},{{Log[0.001],"0.001"},{Log[0.003],"0.003"},{Log[0.01],"0.01"},{Log[0.03],"0.03"},{Log[0.1],"0.1"},{Log[0.3],"0.3"}}}],Plot[Log[0.069]-x,{x,-Log[2],5},PlotStyle->Directive[Red,Thick]],Plot[1-2x,{x,-Log[2],5},PlotStyle->Directive[Black,Thick,Dashed]]]

Export["loglogright.png",]

(* for wrongdef *)
Show[ListLinePlot[{upnew,midnew,lownew},PlotStyle->{Blue,Directive[Black,Thick],Blue},PlotRange->{Log[0.0003],Log[0.005]},Filling->{1->{3}},AxesStyle->18,AspectRatio->0.8,AxesOrigin->{-Log[0.01],Log[0.0003]},Ticks->{{{-Log[0.001],"0.001"},{-Log[0.03],"0.03"},{-Log[0.1],"0.1"},{-Log[0.3],"0.3"},{-Log[1],"1"}},{{Log[0.004],"0.004"},{Log[0.002],"0.002"},{Log[0.001],"0.001"},{Log[0.0005],"0.0005"}}}](*,Plot[Log[0.069]-x,{x,-Log[2],5},PlotStyle->Directive[Red,Thick]]*)]

Export["loglogwrong.png",]

(* FULL DISTRIBUTION OF EPISTASIS *)

(* expbinning[r] implements the exponential binning. The value returned, is an integer from 1 to dim=17. *)

expbinning[r_]:=Module[{bin},

bin=0;

If[r<-(2^1),bin=1];
If[r≥ -(2^1)&&r<-(2^(-0)),bin=2;Return[bin];];
If[r≥ -(2^(-0))&&r<-(2^(-1)),bin=3;Return[bin];];
If[r≥ -(2^(-1))&&r<-(2^(-2)),bin=4;Return[bin];];
If[r≥ -(2^(-2))&&r<-(2^(-3)),bin=5;Return[bin];];
If[r≥ -(2^(-3))&&r<-(2^(-4)),bin=6;Return[bin];];
If[r≥ -(2^(-4))&&r<-(2^(-5)),bin=7;Return[bin];];
If[r≥ -(2^(-5))&&r<-(2^(-6)),bin=8;Return[bin];];
If[r≥ -(2^(-6))&&r<-(2^(-7)),bin=9;Return[bin];];
If[r≥ -(2^(-7))&&r<-(2^(-8)),bin=10;Return[bin];];
If[r≥ -(2^(-8))&&r<(2^(-8)),bin=11;Return[bin];];
If[r≥ (2^(-8))&&r<(2^(-7)),bin=12;Return[bin];];
If[r≥ (2^(-7))&&r<(2^(-6)),bin=13;Return[bin];];
If[r≥ (2^(-6))&&r<(2^(-5)),bin=14;Return[bin];];
If[r≥ (2^(-5))&&r<(2^(-4)),bin=15;Return[bin];];
If[r≥ (2^(-4))&&r<(2^(-3)),bin=16;Return[bin];];
If[r≥ (2^(-3)),bin=17;Return[bin];];

bin
]

dim=17;

For[binn=1,binn≤dim,binn++,

Print[binn];

epses=Table[0,{250000}];
index=1;

(* Group A *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_common.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsA.dat"]];

For[i=1,i≤Length[singlekor],i++,
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
If[a≠binn,Continue[]];
b=expbinning[Log[2,singlekoc[[j,2]]]];
If[b≠binn,Continue[]];

epses[[index]]=eps[[i,j]];
index++;

];
(*If[Mod[i,100]==1,Print[i]];*)
];

(* Group B *)
singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsB.dat"]];

For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
If[a≠binn,Continue[]];
b=expbinning[Log[2,singlekoc[[j,2]]]];
If[b≠binn,Continue[]];

epses[[index]]=eps[[i,j]];
index++;

];
(*If[Mod[i,100]==1,Print[i]];*)
];

(* Group C *)
singlekor=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsC.dat"]];

For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
If[a≠binn,Continue[]];
b=expbinning[Log[2,singlekoc[[j,2]]]];
If[b≠binn,Continue[]];

epses[[index]]=eps[[i,j]];
index++;

];
(*If[Mod[i,100]==1,Print[i]];*)
];

epses=DeleteCases[epses,0];
Print[Length[epses]];
Export[StringJoin[path,"FILES2012/fulleps",ToString[binn],".dat"],epses];

]

{4,1340,12848,32868,30194,26560,25954,28798,8656,2452,20950,4704,25970,95776,273812,112118,908}

RGBColor[1.0,0.85,0.0]

plots={};
grain=0.5;
For[binn=1,binn≤dim,binn++,
tab={};
epses=Import[StringJoin[path,"FILES2012/fulleps",ToString[binn],".dat"]];
epses=Flatten[epses];
normepses=(epses/(StandardDeviation[epses]));
binned=BinCounts[normepses,{-15-0.5 grain,5,grain}];
binned=(1/grain)(binned/(N[Total[binned]]));
For[i=1,i≤Length[binned],i++,
AppendTo[tab,{-15+grain (i-1),binned[[i]]}];
];
(*AppendTo[plots,ListLogPlot[tab,Joined->True,PlotRange->{{-12,4},{(10^(-3.7)),1}},PlotStyle->Directive[Hue[((((2binn-2))^2)/256),1(*-((elem1+elem2)/32)*),1-((2binn)/40)]]]];*)
AppendTo[plots,ListLogPlot[tab,Joined->True,PlotRange->{{-12,4},{(10^(-3.9)),1}},PlotStyle->Directive[Thick,Purple]]];
]

plots

p3=plots[[3]]

p4=plots[[4]]

p5=plots[[5]]

p6=plots[[6]]

p7=plots[[7]]

(* in want to show plots[[3]],plots[[4]],plots[[5]],plots[[7]] *)

Show[{p3,p4,p5,p6,p7,LogPlot[PDF[NormalDistribution[0,1],x],{x,-4,4},PlotStyle->Directive[Thickness[0.005],Black,DotDashed]]},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{-12,-8,-4,0,4},{{Log[1],"1"},{Log[(10^(-1))],"(10^(-1))"},{Log[(10^(-2))],"(10^(-2))"},{Log[(10^(-3))],"(10^(-3))"},{Log[(10^(-4))],"(10^(-4))"}},None,None},ImageSize->300]

Export[StringJoin[path,"FinalFIGS/2d.pdf"],,ImageResolution->600]

(* grain 0.25 *)

Show[plots[[3]],plots[[5]],plots[[7]],plots[[11]],Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{-12,-8,-4,0,4},{{Log[1],"1"},{Log[(10^(-1))],"(10^(-1))"},{Log[(10^(-2))],"(10^(-2))"},{Log[(10^(-3))],"(10^(-3))"},{Log[(10^(-4))],"(10^(-4))"}},None,None},ImageSize->300]

Show[{plots[[4]],plots[[6]],plots[[8]],LogPlot[PDF[NormalDistribution[0,1],x],{x,-4,4},PlotStyle->Directive[Gray,Dashed]]},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{-12,-8,-4,0,4},{{Log[1],"1"},{Log[(10^(-1))],"(10^(-1))"},{Log[(10^(-2))],"(10^(-2))"},{Log[(10^(-3))],"(10^(-3))"},{Log[(10^(-4))],"(10^(-4))"}},None,None},ImageSize->300]

(* grain 0.1 *)

(* grain 0.2 *)

(* grain 0.3 *)

(* grain 0.5 *)

Show[plots[[3]],plots[[4]],plots[[5]],plots[[6]],plots[[7]],plots[[8]]]

Show[plots[[3]],plots[[4]],plots[[5]],plots[[6]],plots[[7]],plots[[8]],plots[[9]],plots[[10]],plots[[11]]]

Show[Take[plots,17]]

ListLogPlot[binned,Joined->True,PlotRange->{{0,130},{0.01,1}}]

(* 0.1 *) plots

N[-(2^(-1))]
N[-(2^(-2))]
N[-(2^(-3))]
N[-(2^(-4))]
N[-(2^(-5))]

matA=Import[StringJoin[path,"FILES2012/d_npointsA.dat"]];
matB=Import[StringJoin[path,"FILES2012/d_npointsB.dat"]];
matC=Import[StringJoin[path,"FILES2012/d_npointsC.dat"]];

matall=matA+matB+matC;
MatrixForm[matall]

Table[matall[[i,i]],{i,1,17}]

diag={};
For[i=1,i≤dim,i++,
AppendTo[diag,matall[[i,i]]];
]
diag

(* ERROR BARS ON THE SEA CREATURE *)

(* expbinning[r] implements the exponential binning. The value returned, is an integer from 1 to dim=17. *)

expbinning[r_]:=Module[{bin},

bin=0;

If[r<-(2^1),bin=1];
If[r≥ -(2^1)&&r<-(2^(-0)),bin=2;Return[bin];];
If[r≥ -(2^(-0))&&r<-(2^(-1)),bin=3;Return[bin];];
If[r≥ -(2^(-1))&&r<-(2^(-2)),bin=4;Return[bin];];
If[r≥ -(2^(-2))&&r<-(2^(-3)),bin=5;Return[bin];];
If[r≥ -(2^(-3))&&r<-(2^(-4)),bin=6;Return[bin];];
If[r≥ -(2^(-4))&&r<-(2^(-5)),bin=7;Return[bin];];
If[r≥ -(2^(-5))&&r<-(2^(-6)),bin=8;Return[bin];];
If[r≥ -(2^(-6))&&r<-(2^(-7)),bin=9;Return[bin];];
If[r≥ -(2^(-7))&&r<-(2^(-8)),bin=10;Return[bin];];
If[r≥ -(2^(-8))&&r<(2^(-8)),bin=11;Return[bin];];
If[r≥ (2^(-8))&&r<(2^(-7)),bin=12;Return[bin];];
If[r≥ (2^(-7))&&r<(2^(-6)),bin=13;Return[bin];];
If[r≥ (2^(-6))&&r<(2^(-5)),bin=14;Return[bin];];
If[r≥ (2^(-5))&&r<(2^(-4)),bin=15;Return[bin];];
If[r≥ (2^(-4))&&r<(2^(-3)),bin=16;Return[bin];];
If[r≥ (2^(-3)),bin=17;Return[bin];];

bin
]

dim=17;

singlekorA=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekocA=Import[StringJoin[path,"FILES2012/a_common.dat"]];
epsA=Import[StringJoin[path,"FILES2012/c_epsA.dat"]];

singlekorB=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekocB=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
epsB=Import[StringJoin[path,"FILES2012/c_epsB.dat"]];

singlekorC=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekocC=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
epsC=Import[StringJoin[path,"FILES2012/c_epsC.dat"]];

summary={};

For[binn=1,binn≤11,binn++,
(*For[binn=1,binn≤dim,binn++,*)

epses=Table[0,{250000}];
index=1;

(* Group A *)
singlekor=singlekorA;
singlekoc=singlekocA;
eps=epsA;

For[i=1,i≤Length[singlekor],i++,
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
If[a≠11,Continue[]];
b=expbinning[Log[2,singlekoc[[j,2]]]];
If[b≠binn,Continue[]];

epses[[index]]=eps[[i,j]];
index++;

];
];
Print["A completed."];

(* Group B *)
singlekor=singlekorB;
singlekoc=singlekocB;
eps=epsB;

For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
If[a≠binn,Continue[]];
b=expbinning[Log[2,singlekoc[[j,2]]]];
If[b≠binn,Continue[]];

epses[[index]]=eps[[i,j]];
index++;

];
];
Print["B completed."];

(* Group C *)
singlekor=singlekorC;
singlekoc=singlekocC;
eps=epsC;

For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
If[a≠binn,Continue[]];
b=expbinning[Log[2,singlekoc[[j,2]]]];
If[b≠binn,Continue[]];

epses[[index]]=eps[[i,j]];
index++;

];
];
Print["C completed."];

epses=DeleteCases[epses,0];

len=Length[epses];
variances=Table[0,{100}];
For[k=1,k≤100,k++,
bseps=RandomChoice[epses,len];
variances[[k]]=Variance[bseps];
];
Print[binn,"  ",Length[epses],"  ",Quantile[variances,0.25],"  ",Quantile[variances,0.5],"  ",Quantile[variances,0.75],"\n\n"];
AppendTo[summary,{binn,Length[epses],Quantile[variances,0.25],Quantile[variances,0.5],Quantile[variances,0.75]}];

]

(* [[3]] slice *)
summary

summary={{1,2,0.`,0.03737646795712676`,0.03737646795712676`},{2,831,0.16358600875742457`,0.1797609221518079`,0.1896544914998217`},{3,6423,0.08388990979787649`,0.09697929754457145`,0.11062441189585744`},{4,13672,0.041051531547368125`,0.04186108094115798`,0.043332421153438605`},{5,14196,0.02083893084463846`,0.021429021317057696`,0.02238627995830851`},{6,12616,0.01238491243791206`,0.013368153073780687`,0.014151709740394768`},{7,12545,0.007774367472340548`,0.008466488637954767`,0.009318650336236332`},{8,14130,0.006800542582761623`,0.007311964866726355`,0.00799060268482998`},{9,4830,0.0058314153866546176`,0.00666450251220464`,0.007106731225636763`},{10,1702,0.0047322740032932735`,0.00574349971294014`,0.006764893037214402`},{11,10730,0.0032908101769798166`,0.0034202868667089575`,0.0035344910400031825`}};

(* [[11]] slice *)
summary

eps2slice[[3]]
Length[eps2slice[[3]]]
avg=Take[eps2slice[[3]],{2,10}]
Length[avg]
smary=Take[summary,{2,10}]
Length[smary]

-(2^(-8))//N

uplist={};
lowlist={};
For[i=1,i≤9,i++,
AppendTo[lowlist,{avg[[i,1]],smary[[i,3]]}];
AppendTo[uplist,{avg[[i,1]],smary[[i,5]]}];
]

ListLinePlot[{Abs[lowlist],Abs[avg],Abs[uplist]},PlotStyle->{Red,Directive[Thick,Red],Red},PlotRange->{{0,2.3},{0,0.16}},Frame->True,FrameStyle->Directive[18,Thick],AspectRatio->0.75,FrameTicks->{{0,0.5,1.0},{0,0.03,0.06,0.09,0.12},None,None},ImageSize->300]

(* PROVA *)

singlekorA=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekocA=Import[StringJoin[path,"FILES2012/a_common.dat"]];
epsA=Import[StringJoin[path,"FILES2012/c_epsA.dat"]];

singlekorB=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekocB=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
epsB=Import[StringJoin[path,"FILES2012/c_epsB.dat"]];

singlekorC=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekocC=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
epsC=Import[StringJoin[path,"FILES2012/c_epsC.dat"]];

summary={};
numbers=Table[0,{11},{11}];

For[bin1=1,bin1≤11,bin1++,
For[bin2=1,bin2≤11,bin2++,

epses=Table[666,{250000}];
index=1;

(* Group A *)
singlekor=singlekorA;
singlekoc=singlekocA;
eps=epsA;

For[i=1,i≤Length[singlekor],i++,
For[j=i+1,j≤Length[singlekoc],j++,   (* ..so that I don't double count *)

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
b=expbinning[Log[2,singlekoc[[j,2]]]];

If[(a==bin1&&b==bin2)||(a==bin2&&b==bin1),
epses[[index]]=eps[[i,j]];
index++;
];

];
];
(*Print["A completed."];*)

(* Group B *)
singlekor=singlekorB;
singlekoc=singlekocB;
eps=epsB;

For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
b=expbinning[Log[2,singlekoc[[j,2]]]];

If[(a==bin1&&b==bin2)||(a==bin2&&b==bin1),
epses[[index]]=eps[[i,j]];
index++;
];

];
];
(*Print["B completed."];*)

(* Group C *)
singlekor=singlekorC;
singlekoc=singlekocC;
eps=epsC;

For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,

If[eps[[i,j]]=="NaN",Continue[]];
a=expbinning[Log[2,singlekor[[i,2]]]];
b=expbinning[Log[2,singlekoc[[j,2]]]];

If[(a==bin1&&b==bin2)||(a==bin2&&b==bin1),
epses[[index]]=eps[[i,j]];
index++;
];

];
];
(*Print["C completed."];*)

epses=DeleteCases[epses,666];

len=Length[epses];
variances=Table[0,{100}];
For[k=1,k≤100,k++,
bseps=RandomChoice[epses,len];
variances[[k]]=Variance[bseps];
];
Print[binn,"  ",Length[epses],"  ",Quantile[variances,0.25],"  ",Quantile[variances,0.5],"  ",Quantile[variances,0.75]];
AppendTo[summary,{bin1,bin2,Length[epses],Quantile[variances,0.25],Quantile[variances,0.5],Quantile[variances,0.75]}];
Print[bin1,"  ",bin2,"  ",Length[epses],"\n\n"];
numbers[[bin1,bin2]]=Length[epses];

];
]

MatrixForm[numbers]

numbers

summary

Length[summary]

Variance[epses]

epssigma2

npoints[[3,4]]

Transpose[summary][[2]]

npoints[[3]]

i=2;
j=2;

counter=1;

nnanpoints=Table[0,{dim},{dim}];
npoints=Table[0,{dim},{dim}];
delta1=Table[0,{dim},{dim}];
delta2=Table[0,{dim},{dim}];
binx=Table[0,{dim}];
nx=Table[0,{dim}];

(* Group C = queryonly x genuinearray. *)

singlekor=Import[StringJoin[path,"FILES2012/a_queryonly.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_genuinearray.dat"]];
eps=Import[StringJoin[path,"FILES2012/c_epsC.dat"]];

(* Create look-up tables associating to each mutant its log-growth rate and its bin. *)

logsinglekor=Table[0,{Length[singlekor]}];
binsinglekor=Table[0,{Length[singlekor]}];
For[n=1,n≤Length[singlekor],n++,
logsinglekor[[n]]=Log[2,singlekor[[n,2]]];
binsinglekor[[n]]=expbinning[logsinglekor[[n]]];
];

logsinglekoc=Table[0,{Length[singlekoc]}];
binsinglekoc=Table[0,{Length[singlekoc]}];
For[n=1,n≤Length[singlekoc],n++,
logsinglekoc[[n]]=Log[2,singlekoc[[n,2]]];
binsinglekoc[[n]]=expbinning[logsinglekoc[[n]]];
];

For[n1=1,n1≤Length[singlekor],n1++,
For[n2=1,n2≤Length[singlekoc],n2++,

If[n1==2&&n2==2587,Print["\t\t",singlekor[[n1]],"  ",singlekoc[[n2]],"  ",eps[[n1,n2]]]];


df1=logsinglekor[[n1]];
df2=logsinglekoc[[n2]];
a=binsinglekor[[n1]];
b=binsinglekoc[[n2]];

(*If[a≠i||b≠j,Continue[]];*)
If[!((a==i&&b==j)||(a==j&&b==i)),Continue[]];

If[eps[[n1,n2]]=="NaN",nnanpoints[[a,b]]++;nnanpoints[[b,a]]++;Continue[]];

(* each double-knockout is counted as two points *)

Print[counter++,"  ",n1,"  ",n2,"\t\t",singlekor[[n1]],"  ",singlekoc[[n2]],"  ",eps[[n1,n2]]];

(*npoints[[a,b]]++;
delta1[[a,b]]+=eps[[n1,n2]];
delta2[[a,b]]+=((eps[[n1,n2]])^2);

npoints[[b,a]]++;   (* different from A to double count correctly *)
delta1[[b,a]]+=eps[[n1,n2]];
delta2[[b,a]]+=(((eps[[n1,n2]]))^2);

binx[[a]]+= df1;
nx[[a]]++;
binx[[b]]+= df2;
nx[[b]]++;

*)
];
];

eps[[2,2587]]