l=Import["/Users/troyday/Desktop/Transfer/AntigenicCut.txt","Table"]

ll=SortBy[l,First]

aa=Transpose[Append[Table[Transpose[ll][[k]],{k,2,6}],Transpose[ll][[1]]]]

data=Transpose[aa]

Example 8.1.3

data2=Drop[data,-1]

Manipulate[ListPlot[{Table[{data2[[i,k]],data2[[j,k]]},{k,1,3}],Table[{data2[[i,k]],data2[[j,k]]},{k,4,6}],Table[{data2[[i,k]],data2[[j,k]]},{k,7,8}],Table[{data2[[i,k]],data2[[j,k]]},{k,9,11}],Table[{data2[[i,k]],data2[[j,k]]},{k,12,15}],Table[{data2[[i,k]],data2[[j,k]]},{k,16,18}],Table[{data2[[i,k]],data2[[j,k]]},{k,19,23}],Table[{data2[[i,k]],data2[[j,k]]},{k,24,28}],Table[{data2[[i,k]],data2[[j,k]]},{k,29,35}]},PlotStyle->{Yellow,Blue,Red,Black,Brown,Green,Purple,Orange,Gray},PlotRange->{{0,1500},{0,1500}}],{i,{1,2,3,4,5}},{j,{1,2,3,4,5}}]

Manipulate[data2={{354,640,1163,320,554,1280,320,1109,165,905,905,80,80,80,453,52,80,160,16,20,40,40,60,10,40,40,40,80,10,10,10,10,10,10,20},{501,320,1163,640,453,640,320,640,392,905,905,640,640,1280,905,640,1280,640,291,320,320,320,392,320,160,320,320,320,120,120,160,160,160,320,210},{109,80,291,120,113,80,80,100,57,139,160,640,640,1280,226,1280,1280,1280,905,2560,640,2560,2560,1280,1280,640,1280,1280,320,640,160,320,640,320,320},{30,40,73,80,42,40,24,57,575,98,98,320,320,640,226,291,320,640,80,320,640,160,320,160,160,2560,160,2560,80,160,40,80,80,160,80},{63,40,89,160,46,57,46,46,35,89,87,226,226,160,184,135,101,226,320,80,80,160,254,160,160,40,80,40,80,160,905,905,1280,1016,905}};ListPointPlot3D[{Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,1,3}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,4,6}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,7,8}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,9,11}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,12,15}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,16,18}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,19,23}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,24,28}],Table[{data2[[i,k]],data2[[j,k]],data2[[l,k]]},{k,29,35}]},PlotStyle->{{Yellow,PointSize[.02]},{Blue,PointSize[.02]},{Red,PointSize[.02]},{Black,PointSize[.02]},{Brown,PointSize[.02]},{Green,PointSize[.02]},{Purple,PointSize[.02]},{Orange,PointSize[.02]},{Gray,PointSize[.02]}},PlotStyle->PointSize[.02],PlotRange->{{0,1500},{0,1500},{0,1500}},PlotLegends->{"1968","1969","1970","1971","1972","1973","1974","1975","1976"},AxesLabel->{"x axis","y axis","z axis"}],{{i,2,"Antiserum on x axis"},{1,2,3,4,5}},{{j,1,"Antiserum on y axis"},{1,2,3,4,5}},{{l,5,"Antiserum on z axis"},{1,2,3,4,5}}]

data1=Table[Log[2,((Max[data[[k]]])/(data[[k]]))],{k,1,5}]//N

Manipulate[data1={{1.8543225448043648`,1.`,0.13829271341414398`,2.`,1.208185928838174`,0.`,2.`,0.20688444472565237`,2.955605880641546`,0.5001541129167946`,0.5001541129167946`,4.`,4.`,4.`,1.4985608548411273`,4.62148837674627`,4.`,3.`,6.321928094887362`,6.`,5.`,5.`,4.415037499278843`,7.`,5.`,5.`,5.`,4.`,7.`,7.`,7.`,7.`,7.`,7.`,6.`},{1.353261301692154`,2.`,0.13829271341414398`,1.`,1.4985608548411273`,1.`,2.`,1.`,1.7072182507721543`,0.5001541129167946`,0.5001541129167946`,1.`,1.`,0.`,0.5001541129167946`,1.`,0.`,1.`,2.1370527519790787`,2.`,2.`,2.`,1.7072182507721543`,2.`,3.`,2.`,2.`,2.`,3.415037499278844`,3.415037499278844`,3.`,3.`,3.`,2.`,2.6076825772212398`},{4.553743770110436`,5.`,3.1370527519790787`,4.415037499278843`,4.501749132472174`,5.`,5.`,4.678071905112637`,5.4890380807226204`,4.202987022163855`,4.`,2.`,2.`,1.`,3.501749132472175`,1.`,1.`,1.`,1.5001541129167946`,0.`,2.`,0.`,0.`,1.`,1.`,2.`,1.`,1.`,3.`,2.`,4.`,3.`,2.`,3.`,3.`},{6.415037499278843`,6.`,5.132103536007345`,5.`,5.929610672108603`,6.`,6.7369655941662066`,5.4890380807226204`,2.1545099490556248`,4.707218250772154`,4.707218250772154`,3.`,3.`,2.`,3.501749132472175`,3.1370527519790787`,3.`,2.`,5.`,3.`,2.`,4.`,3.`,4.`,4.`,0.`,4.`,0.`,5.`,4.`,6.`,5.`,5.`,4.`,5.`},{4.344648171387446`,5.`,3.8461946639209645`,3.`,4.79836613883035`,4.4890380807226204`,4.79836613883035`,4.79836613883035`,5.192645077942396`,3.8461946639209645`,3.878984599038634`,2.501749132472175`,2.501749132472175`,3.`,2.798366138830349`,3.245112497836531`,3.663716612135568`,2.501749132472175`,2.`,4.`,4.`,3.`,2.3332434081151963`,3.`,3.`,5.`,4.`,5.`,4.`,3.`,0.5001541129167946`,0.5001541129167946`,0.`,0.3332434081151965`,0.5001541129167946`}};ListPointPlot3D[{Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,1,3}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,4,6}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,7,8}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,9,11}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,12,15}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,16,18}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,19,23}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,24,28}],Table[{data1[[i,k]],data1[[j,k]],data1[[l,k]]},{k,29,35}]},PlotStyle->{{Yellow,PointSize[.02]},{Blue,PointSize[.02]},{Red,PointSize[.02]},{Black,PointSize[.02]},{Brown,PointSize[.02]},{Green,PointSize[.02]},{Purple,PointSize[.02]},{Orange,PointSize[.02]},{Gray,PointSize[.02]}},PlotStyle->PointSize[.02],PlotRange->{{0,7},{0,7},{0,7}},PlotLegends->{"1968","1969","1970","1971","1972","1973","1974","1975","1976"},AxesLabel->{"x axis","y axis","z axis"}],{{i,2,"Antiserum on x axis"},{1,2,3,4,5}},{{j,1,"Antiserum on y axis"},{1,2,3,4,5}},{{l,5,"Antiserum on z axis"},{1,2,3,4,5}}]

Table[data2[[6,i]],{i,1,3}]
Table[data2[[6,i]],{i,4,6}]
Table[data2[[6,i]],{i,7,8}]
Table[data2[[6,i]],{i,9,11}]
Table[data2[[6,i]],{i,12,15}]
Table[data2[[6,i]],{i,16,18}]
Table[data2[[6,i]],{i,19,23}]
Table[data2[[6,i]],{i,24,28}]
Table[data2[[6,i]],{i,29,35}]

data1=Table[Log[2,((Max[data[[k]]])/(data[[k]]))],{k,1,5}]

MatrixForm[data2]
MatrixForm[data1]

fitdata=Transpose[data1]

fitdata={{((Log[(640/177)])/(Log[2])),((Log[(1280/501)])/(Log[2])),((Log[(2560/109)])/(Log[2])),((Log[(256/3)])/(Log[2])),((Log[(1280/63)])/(Log[2]))},{1,2,5,6,5},{((Log[(1280/1163)])/(Log[2])),((Log[(1280/1163)])/(Log[2])),((Log[(2560/291)])/(Log[2])),((Log[(2560/73)])/(Log[2])),((Log[(1280/89)])/(Log[2]))},{2,1,((Log[(64/3)])/(Log[2])),5,3},{((Log[(640/277)])/(Log[2])),((Log[(1280/453)])/(Log[2])),((Log[(2560/113)])/(Log[2])),((Log[(1280/21)])/(Log[2])),((Log[(640/23)])/(Log[2]))},{0,1,5,6,((Log[(1280/57)])/(Log[2]))},{2,2,5,((Log[(320/3)])/(Log[2])),((Log[(640/23)])/(Log[2]))},{((Log[(1280/1109)])/(Log[2])),1,((Log[(128/5)])/(Log[2])),((Log[(2560/57)])/(Log[2])),((Log[(640/23)])/(Log[2]))},{((Log[(256/33)])/(Log[2])),((Log[(160/49)])/(Log[2])),((Log[(2560/57)])/(Log[2])),((Log[(512/115)])/(Log[2])),((Log[(256/7)])/(Log[2]))},{((Log[(256/181)])/(Log[2])),((Log[(256/181)])/(Log[2])),((Log[(2560/139)])/(Log[2])),((Log[(1280/49)])/(Log[2])),((Log[(1280/89)])/(Log[2]))},{((Log[(256/181)])/(Log[2])),((Log[(256/181)])/(Log[2])),4,((Log[(1280/49)])/(Log[2])),((Log[(1280/87)])/(Log[2]))},{4,1,2,3,((Log[(640/113)])/(Log[2]))},{4,1,2,3,((Log[(640/113)])/(Log[2]))},{4,0,1,2,3},{((Log[(1280/453)])/(Log[2])),((Log[(256/181)])/(Log[2])),((Log[(1280/113)])/(Log[2])),((Log[(1280/113)])/(Log[2])),((Log[(160/23)])/(Log[2]))},{((Log[(320/13)])/(Log[2])),1,1,((Log[(2560/291)])/(Log[2])),((Log[(256/27)])/(Log[2]))},{4,0,1,3,((Log[(1280/101)])/(Log[2]))},{3,1,1,2,((Log[(640/113)])/(Log[2]))},{((Log[80])/(Log[2])),((Log[(1280/291)])/(Log[2])),((Log[(512/181)])/(Log[2])),5,2},{6,2,0,3,4},{5,2,2,2,4},{5,2,0,4,3},{((Log[(64/3)])/(Log[2])),((Log[(160/49)])/(Log[2])),0,3,((Log[(640/127)])/(Log[2]))},{7,2,1,4,3},{5,3,1,4,3},{5,2,2,0,5},{5,2,1,4,4},{4,2,1,0,5},{7,((Log[(32/3)])/(Log[2])),3,5,4},{7,((Log[(32/3)])/(Log[2])),2,4,3},{7,3,4,6,((Log[(256/181)])/(Log[2]))},{7,3,3,5,((Log[(256/181)])/(Log[2]))},{7,3,2,5,0},{7,2,3,4,((Log[(160/127)])/(Log[2]))},{6,((Log[(128/21)])/(Log[2])),3,5,((Log[(256/181)])/(Log[2]))}};

i=strain
j=antiserum

opt=Minimize[Sum[(((Sqrt[(((x[i]-w[j]))^2)+(((y[i]-z[j]))^2)]-fitdata[[i,j]]))^2),{i,1,2},{j,1,1}],Flatten[Table[{x[i],w[j],y[i],z[j]},{i,1,2},{j,1,1}]]]

a=Table[{{w[j],z[j]}},{j,1,5}]/.opt[[2]]
list68=Table[{x[i],y[i]},{i,1,3}]/.opt[[2]]
list69=Table[{x[i],y[i]},{i,4,6}]/.opt[[2]]
list70=Table[{x[i],y[i]},{i,7,8}]/.opt[[2]]
list71=Table[{x[i],y[i]},{i,9,11}]/.opt[[2]]
list72=Table[{x[i],y[i]},{i,12,15}]/.opt[[2]]
list73=Table[{x[i],y[i]},{i,16,18}]/.opt[[2]]
list74=Table[{x[i],y[i]},{i,19,23}]/.opt[[2]]
list75=Table[{x[i],y[i]},{i,24,28}]/.opt[[2]]
list76=Table[{x[i],y[i]},{i,29,35}]/.opt[[2]]

ListPlot[{list68,list69,list70,list71,list72,list73,list74,list75,list76},PlotStyle->{Yellow,Blue,Red,Black,Brown,Green,Purple,Orange,Gray},PlotRange->{{-4,4},{-4,4}},Axes->False]
ListPlot[a,PlotMarkers->{"1","2","3","4","5"},PlotStyle->{{Black,20},{Black,Larger},{Black,Larger},{Black,Larger},{Black,Larger}},PlotRange->{{-4,4},{-4,4}},Axes->False]
Show[%,%%]

opt=Minimize[Sum[(((Sqrt[(((x[i]-w[j]))^2)+(((y[i]-z[j]))^2)]-fitdata[[i,j]]))^2),{i,1,35},{j,1,2}],Flatten[Table[{x[i],w[j],y[i],z[j]},{i,1,35},{j,1,2}]]]

a=Table[{{w[j],z[j]}},{j,1,5}]/.opt[[2]];
list68=Table[{x[i],y[i]},{i,1,3}]/.opt[[2]];
list69=Table[{x[i],y[i]},{i,4,6}]/.opt[[2]];
list70=Table[{x[i],y[i]},{i,7,8}]/.opt[[2]];
list71=Table[{x[i],y[i]},{i,9,11}]/.opt[[2]];
list72=Table[{x[i],y[i]},{i,12,15}]/.opt[[2]];
list73=Table[{x[i],y[i]},{i,16,18}]/.opt[[2]];
list74=Table[{x[i],y[i]},{i,19,23}]/.opt[[2]];
list75=Table[{x[i],y[i]},{i,24,28}]/.opt[[2]];
list76=Table[{x[i],y[i]},{i,29,35}]/.opt[[2]];

ListPlot[{list68,list69,list70,list71,list72,list73,list74,list75,list76},PlotStyle->{Yellow,Blue,Red,Black,Brown,Green,Purple,Orange,Gray},PlotRange->{{-4,4},{-4,4}},Axes->False]
ListPlot[a,PlotMarkers->{"1","2","3","4","5"},PlotStyle->{{Black,20},{Black,Larger},{Black,Larger},{Black,Larger},{Black,Larger}},PlotRange->{{-4,4},{-4,4}},Axes->False]
Show[%,%%]

ListPlot[{Table[{data2[[i,k]],data2[[j,k]]},{k,1,3}],Table[{data2[[i,k]],data2[[j,k]]},{k,4,6}],Table[{data2[[i,k]],data2[[j,k]]},{k,7,8}],Table[{data2[[i,k]],data2[[j,k]]},{k,9,11}],Table[{data2[[i,k]],data2[[j,k]]},{k,12,15}],Table[{data2[[i,k]],data2[[j,k]]},{k,16,18}],Table[{data2[[i,k]],data2[[j,k]]},{k,19,23}],Table[{data2[[i,k]],data2[[j,k]]},{k,24,28}],Table[{data2[[i,k]],data2[[j,k]]},{k,29,35}]},

NMinimize[(((-0.18293285544112342`+(Sqrt[(((-w[1]+x[1]))^2)+(((y[1]-z[1]))^2)])))^2)+(((-0.19375605085116362`+(Sqrt[(((-w[1]+x[2]))^2)+(((y[2]-z[1]))^2)])))^2)+(((-0.20283323561311856`+(Sqrt[(((-w[1]+x[3]))^2)+(((y[3]-z[1]))^2)])))^2)+(((-0.03328365834916694`+(Sqrt[(((-w[2]+x[1]))^2)+(((y[1]-z[2]))^2)])))^2)+(((-0.024618490094964043`+(Sqrt[(((-w[2]+x[2]))^2)+(((y[2]-z[2]))^2)])))^2)+(((-0.046586190563095556`+(Sqrt[(((-w[2]+x[3]))^2)+(((y[3]-z[2]))^2)])))^2)+(((-0.023691487395227334`+(Sqrt[(((-w[3]+x[1]))^2)+(((y[1]-z[3]))^2)])))^2)+(((-0.013262009634131183`+(Sqrt[(((-w[3]+x[2]))^2)+(((y[2]-z[3]))^2)])))^2)+(((-0.049265029996520174`+(Sqrt[(((-w[3]+x[3]))^2)+(((y[3]-z[3]))^2)])))^2)+(((-0.014309244895025386`+(Sqrt[(((-w[4]+x[1]))^2)+(((y[1]-z[4]))^2)])))^2)+(((-0.030202467276423978`+(Sqrt[(((-w[4]+x[2]))^2)+(((y[2]-z[4]))^2)])))^2)+(((-0.05654882454253518`+(Sqrt[(((-w[4]+x[3]))^2)+(((y[3]-z[4]))^2)])))^2)+(((-0.02765884308361216`+(Sqrt[(((-w[5]+x[1]))^2)+(((y[1]-z[5]))^2)])))^2)+(((-0.007057197184678732`+(Sqrt[(((-w[5]+x[2]))^2)+(((y[2]-z[5]))^2)])))^2)+(((-0.040536359092676166`+(Sqrt[(((-w[5]+x[3]))^2)+(((y[3]-z[5]))^2)])))^2),{x[1],w[1],y[1],z[1],x[1],w[2],y[1],z[2],x[1],w[3],y[1],z[3],x[1],w[4],y[1],z[4],x[1],w[5],y[1],z[5],x[2],w[1],y[2],z[1],x[2],w[2],y[2],z[2],x[2],w[3],y[2],z[3],x[2],w[4],y[2],z[4],x[2],w[5],y[2],z[5],x[3],w[1],y[3],z[1],x[3],w[2],y[3],z[2],x[3],w[3],y[3],z[3],x[3],w[4],y[3],z[4],x[3],w[5],y[3],z[5]}]