1
$\begingroup$

I have a set of data in the form {x,y}, and the corresponding errors:

data = {{0.5, 1}, {1.5, 5}, {2.5, 3}, {3.5, 1}, {4.5, 1}, {5.5, 
3}, {6.5, 1}, {7.5, 1}, {8.5, 3}, {9.5, 2}, {10.5, 1}, {11.5, 
4}, {12.5, 3}, {13.5, 1}, {14.5, 1}, {15.5, 4}, {16.5, 2}, {17.5, 
1}, {18.5, 3}, {19.5, 4}, {20.5, 3}, {21.5, 2}, {22.5, 6}, {23.5, 
1}, {24.5, 4}, {25.5, 6}, {26.5, 2}, {27.5, 3}, {28.5, 4}, {29.5, 
1}, {30.5, 5}, {32.5, 2}, {33.5, 1}, {34.5, 1}, {35.5, 1}, {36.5, 
2}, {37.5, 1}, {38.5, 1}, {39.5, 1}, {40.5, 1}, {41.5, 3}, {42.5, 
3}, {43.5, 2}, {44.5, 2}, {46.5, 2}, {47.5, 1}, {49.5, 2}, {51.5, 
4}, {52.5, 1}, {53.5, 2}, {54.5, 1}, {55.5, 3}, {56.5, 3}, {57.5, 
5}, {58.5, 4}, {59.5, 1}, {60.5, 2}, {61.5, 1}, {62.5, 3}, {63.5, 
5}, {64.5, 2}, {65.5, 3}, {66.5, 1}, {67.5, 2}, {68.5, 2}, {69.5, 
4}, {70.5, 3}, {71.5, 1}, {72.5, 1}, {73.5, 2}, {74.5, 1}, {75.5, 
2}, {76.5, 3}, {77.5, 3}, {78.5, 1}, {79.5, 1}, {80.5, 1}, {81.5, 
1}, {82.5, 1}, {83.5, 2}, {84.5, 2}, {85.5, 3}, {86.5, 1}, {87.5, 
2}, {88.5, 1}, {89.5, 3}, {90.5, 2}, {92.5, 1}, {93.5, 2}, {95.5, 
1}, {96.5, 2}, {99.5, 2}, {100.5, 1}, {101.5, 1}, {104.5, 
2}, {105.5, 1}, {106.5, 1}, {108.5, 1}, {109.5, 2}, {110.5, 
3}, {111.5, 2}, {115.5, 1}, {116.5, 1}, {118.5, 1}, {119.5, 
1}, {120.5, 1}, {122.5, 1}, {123.5, 2}, {125.5, 1}, {126.5, 
1}, {127.5, 1}, {128.5, 2}, {129.5, 1}, {130.5, 1}, {131.5, 
1}, {135.5, 1}, {137.5, 1}, {138.5, 1}, {139.5, 2}, {140.5, 
1}, {143.5, 3}, {144.5, 1}, {145.5, 1}, {146.5, 1}, {151.5, 
1}, {154.5, 1}, {157.5, 1}, {158.5, 2}, {160.5, 2}, {161.5, 
1}, {165.5, 1}, {172.5, 1}, {173.5, 1}, {174.5, 1}, {178.5, 
1}, {179.5, 1}, {180.5, 1}, {182.5, 1}, {185.5, 3}, {187.5, 
1}, {188.5, 1}, {189.5, 2}, {191.5, 1}, {193.5, 1}, {194.5, 
1}, {197.5, 1}, {199.5, 1}, {201.5, 1}, {204.5, 2}, {207.5, 
2}, {210.5, 1}, {214.5, 1}, {216.5, 1}, {217.5, 1}, {218.5, 
2}, {220.5, 3}, {225.5, 1}, {228.5, 1}, {242.5, 1}, {245.5, 
1}, {256.5, 1}, {266.5, 1}, {271.5, 2}, {273.5, 1}, {274.5, 
1}, {276.5, 1}, {278.5, 1}, {279.5, 3}, {280.5, 4}, {281.5, 
1}, {282.5, 1}, {283.5, 5}, {284.5, 6}, {285.5, 7}, {286.5, 
9}, {287.5, 3}, {288.5, 6}, {289.5, 10}, {290.5, 12}, {291.5, 
12}, {292.5, 15}, {293.5, 24}, {294.5, 23}, {295.5, 32}, {296.5, 
31}, {297.5, 38}, {298.5, 30}, {299.5, 54}, {300.5, 53}, {301.5, 
73}, {302.5, 67}, {303.5, 77}, {304.5, 80}, {305.5, 68}, {306.5, 
107}, {307.5, 115}, {308.5, 112}, {309.5, 116}, {310.5, 
142}, {311.5, 123}, {312.5, 143}, {313.5, 172}, {314.5, 
176}, {315.5, 197}, {316.5, 201}, {317.5, 215}, {318.5, 
249}, {319.5, 269}, {320.5, 271}, {321.5, 270}, {322.5, 
308}, {323.5, 311}, {324.5, 353}, {325.5, 346}, {326.5, 
401}, {327.5, 370}, {328.5, 403}, {329.5, 425}, {330.5, 
418}, {331.5, 417}, {332.5, 471}, {333.5, 506}, {334.5, 
488}, {335.5, 503}, {336.5, 507}, {337.5, 510}, {338.5, 
584}, {339.5, 568}, {340.5, 559}, {341.5, 601}, {342.5, 
555}, {343.5, 578}, {344.5, 681}, {345.5, 588}, {346.5, 
600}, {347.5, 605}, {348.5, 647}, {349.5, 673}, {350.5, 
636}, {351.5, 680}, {352.5, 695}, {353.5, 716}, {354.5, 
717}, {355.5, 742}, {356.5, 679}, {357.5, 724}, {358.5, 
724}, {359.5, 746}, {360.5, 728}, {361.5, 705}, {362.5, 
726}, {363.5, 732}, {364.5, 686}, {365.5, 699}, {366.5, 
750}, {367.5, 709}, {368.5, 703}, {369.5, 723}, {370.5, 
718}, {371.5, 677}, {372.5, 670}, {373.5, 760}, {374.5, 
653}, {375.5, 730}, {376.5, 694}, {377.5, 731}, {378.5, 
649}, {379.5, 704}, {380.5, 692}, {381.5, 647}, {382.5, 
635}, {383.5, 673}, {384.5, 675}, {385.5, 693}, {386.5, 
617}, {387.5, 656}, {388.5, 656}, {389.5, 623}, {390.5, 
584}, {391.5, 672}, {392.5, 643}, {393.5, 649}, {394.5, 
568}, {395.5, 638}, {396.5, 624}, {397.5, 619}, {398.5, 
559}, {399.5, 621}, {400.5, 544}, {401.5, 558}, {402.5, 
553}, {403.5, 555}, {404.5, 551}, {405.5, 534}, {406.5, 
583}, {407.5, 526}, {408.5, 526}, {409.5, 541}, {410.5, 
509}, {411.5, 496}, {412.5, 504}, {413.5, 550}, {414.5, 
509}, {415.5, 466}, {416.5, 441}, {417.5, 475}, {418.5, 
469}, {419.5, 454}, {420.5, 443}, {421.5, 415}, {422.5, 
426}, {423.5, 452}, {424.5, 420}, {425.5, 416}, {426.5, 
424}, {427.5, 407}, {428.5, 437}, {429.5, 397}, {430.5, 
396}, {431.5, 420}, {432.5, 402}, {433.5, 398}, {434.5, 
394}, {435.5, 390}, {436.5, 351}, {437.5, 401}, {438.5, 
335}, {439.5, 388}, {440.5, 346}, {441.5, 347}, {442.5, 
358}, {443.5, 353}, {444.5, 322}, {445.5, 326}, {446.5, 
338}, {447.5, 315}, {448.5, 310}, {449.5, 350}, {450.5, 
314}, {451.5, 299}, {452.5, 309}, {453.5, 272}, {454.5, 
293}, {455.5, 297}, {456.5, 284}, {457.5, 281}, {458.5, 
249}, {459.5, 281}, {460.5, 263}, {461.5, 271}, {462.5, 
277}, {463.5, 271}, {464.5, 285}, {465.5, 268}, {466.5, 
255}, {467.5, 261}, {468.5, 246}, {469.5, 234}, {470.5, 
263}, {471.5, 228}, {472.5, 248}, {473.5, 221}, {474.5, 
238}, {475.5, 226}, {476.5, 205}, {477.5, 209}, {478.5, 
187}, {479.5, 226}, {480.5, 220}, {481.5, 202}, {482.5, 
216}, {483.5, 209}, {484.5, 191}, {485.5, 200}, {486.5, 
205}, {487.5, 190}, {488.5, 203}, {489.5, 216}, {490.5, 
194}, {491.5, 193}, {492.5, 219}, {493.5, 161}, {494.5, 
169}, {495.5, 175}, {496.5, 154}, {497.5, 179}, {498.5, 
165}, {499.5, 173}, {500.5, 175}, {501.5, 161}, {502.5, 
151}, {503.5, 145}, {504.5, 156}, {505.5, 147}, {506.5, 
148}, {507.5, 136}, {508.5, 160}, {509.5, 150}, {510.5, 
139}, {511.5, 168}, {512.5, 142}, {513.5, 144}, {514.5, 
124}, {515.5, 141}, {516.5, 154}, {517.5, 137}, {518.5, 
134}, {519.5, 132}, {520.5, 129}, {521.5, 107}, {522.5, 
106}, {523.5, 138}, {524.5, 120}, {525.5, 108}, {526.5, 
104}, {527.5, 108}, {528.5, 119}, {529.5, 120}, {530.5, 
112}, {531.5, 121}, {532.5, 115}, {533.5, 123}, {534.5, 
122}, {535.5, 85}, {536.5, 92}, {537.5, 111}, {538.5, 
100}, {539.5, 111}, {540.5, 89}, {541.5, 95}, {542.5, 
115}, {543.5, 98}, {544.5, 101}, {545.5, 97}, {546.5, 94}, {547.5,
 103}, {548.5, 104}, {549.5, 100}, {550.5, 102}, {551.5, 
86}, {552.5, 75}, {553.5, 91}, {554.5, 91}, {555.5, 96}, {556.5, 
100}, {557.5, 92}, {558.5, 81}, {559.5, 85}, {560.5, 79}, {561.5, 
80}, {562.5, 86}, {563.5, 81}, {564.5, 74}, {565.5, 64}, {566.5, 
84}, {567.5, 72}, {568.5, 89}, {569.5, 67}, {570.5, 73}, {571.5, 
69}, {572.5, 75}, {573.5, 51}, {574.5, 72}, {575.5, 68}, {576.5, 
72}, {577.5, 70}, {578.5, 80}, {579.5, 51}, {580.5, 64}, {581.5, 
55}, {582.5, 52}, {583.5, 75}, {584.5, 53}, {585.5, 59}, {586.5, 
81}, {587.5, 56}, {588.5, 56}, {589.5, 72}, {590.5, 67}, {591.5, 
44}, {592.5, 62}, {593.5, 54}, {594.5, 45}, {595.5, 61}, {596.5, 
50}, {597.5, 65}, {598.5, 46}, {599.5, 69}, {600.5, 54}, {601.5, 
43}, {602.5, 61}, {603.5, 43}, {604.5, 50}, {605.5, 37}, {606.5, 
40}, {607.5, 50}, {608.5, 44}, {609.5, 43}, {610.5, 58}, {611.5, 
46}, {612.5, 49}, {613.5, 42}, {614.5, 34}, {615.5, 35}, {616.5, 
49}, {617.5, 44}, {618.5, 54}, {619.5, 50}, {620.5, 42}, {621.5, 
62}, {622.5, 42}, {623.5, 40}, {624.5, 41}, {625.5, 46}, {626.5, 
44}, {627.5, 31}, {628.5, 43}, {629.5, 41}, {630.5, 53}, {631.5, 
39}, {632.5, 29}, {633.5, 35}, {634.5, 45}, {635.5, 41}, {636.5, 
46}, {637.5, 36}, {638.5, 53}, {639.5, 38}, {640.5, 45}, {641.5, 
40}, {642.5, 35}, {643.5, 28}, {644.5, 38}, {645.5, 33}, {646.5, 
33}, {647.5, 25}, {648.5, 33}, {649.5, 32}, {650.5, 37}, {651.5, 
35}, {652.5, 29}, {653.5, 39}, {654.5, 36}, {655.5, 34}, {656.5, 
27}, {657.5, 26}, {658.5, 34}, {659.5, 26}, {660.5, 27}, {661.5, 
40}, {662.5, 32}, {663.5, 22}, {664.5, 23}, {665.5, 25}, {666.5, 
30}, {667.5, 20}, {668.5, 30}, {669.5, 27}, {670.5, 23}, {671.5, 
22}, {672.5, 30}, {673.5, 10}, {674.5, 32}, {675.5, 29}, {676.5, 
34}, {677.5, 29}, {678.5, 30}, {679.5, 13}, {680.5, 16}, {681.5, 
16}, {682.5, 29}, {683.5, 18}, {684.5, 21}, {685.5, 28}, {686.5, 
17}, {687.5, 15}, {688.5, 20}, {689.5, 26}, {690.5, 22}, {691.5, 
19}, {692.5, 20}, {693.5, 22}, {694.5, 16}, {695.5, 27}, {696.5, 
20}, {697.5, 18}, {698.5, 25}, {699.5, 21}, {700.5, 20}, {701.5, 
13}, {702.5, 15}, {703.5, 17}, {704.5, 12}, {705.5, 10}, {706.5, 
23}, {707.5, 26}, {708.5, 29}, {709.5, 17}, {710.5, 18}, {711.5, 
24}, {712.5, 18}, {713.5, 19}, {714.5, 14}, {715.5, 10}, {716.5, 
20}, {717.5, 12}, {718.5, 11}, {719.5, 15}, {720.5, 13}, {721.5, 
17}, {722.5, 22}, {723.5, 16}, {724.5, 8}, {725.5, 14}, {726.5, 
13}, {727.5, 11}, {728.5, 8}, {729.5, 11}, {730.5, 10}, {731.5, 
12}, {732.5, 11}, {733.5, 12}, {734.5, 9}, {735.5, 10}, {736.5, 
11}, {737.5, 13}, {738.5, 13}, {739.5, 19}, {740.5, 19}, {741.5, 
13}, {742.5, 12}, {743.5, 7}, {744.5, 10}, {745.5, 9}, {746.5, 
8}, {747.5, 10}, {748.5, 11}, {749.5, 9}, {750.5, 17}, {751.5, 
12}, {752.5, 11}, {753.5, 12}, {754.5, 11}, {755.5, 14}, {756.5, 
11}, {757.5, 14}, {758.5, 11}, {759.5, 9}, {760.5, 14}, {761.5, 
9}, {762.5, 10}, {763.5, 11}, {764.5, 7}, {765.5, 10}, {766.5, 
8}, {767.5, 11}, {768.5, 10}, {769.5, 9}, {770.5, 4}, {771.5, 
13}, {772.5, 7}, {773.5, 8}, {774.5, 8}, {775.5, 7}, {776.5, 
9}, {777.5, 12}, {778.5, 11}, {779.5, 6}, {780.5, 6}, {781.5, 
8}, {782.5, 5}, {783.5, 6}, {784.5, 4}, {785.5, 6}, {786.5, 
6}, {787.5, 7}, {788.5, 9}, {789.5, 7}, {790.5, 8}, {791.5, 
3}, {792.5, 5}, {793.5, 6}, {794.5, 8}, {795.5, 6}, {796.5, 
5}, {797.5, 8}, {798.5, 5}, {799.5, 11}, {800.5, 7}, {801.5, 
7}, {802.5, 10}, {803.5, 8}, {804.5, 3}, {805.5, 6}, {806.5, 
3}, {807.5, 8}, {808.5, 7}, {809.5, 8}, {810.5, 6}, {811.5, 
3}, {812.5, 3}, {813.5, 6}, {814.5, 8}, {815.5, 4}, {816.5, 
9}, {817.5, 8}, {818.5, 6}, {819.5, 5}, {820.5, 7}, {821.5, 
5}, {822.5, 4}, {823.5, 4}, {824.5, 6}, {825.5, 5}, {826.5, 
5}, {827.5, 6}, {828.5, 6}, {829.5, 8}, {830.5, 1}, {831.5, 
3}, {832.5, 2}, {833.5, 3}, {834.5, 4}, {835.5, 6}, {836.5, 
4}, {837.5, 5}, {838.5, 5}, {839.5, 4}, {840.5, 10}, {841.5, 
5}, {842.5, 6}, {843.5, 4}, {844.5, 2}, {845.5, 1}, {846.5, 
3}, {847.5, 3}, {848.5, 4}, {849.5, 6}, {850.5, 4}, {851.5, 
6}, {852.5, 5}, {853.5, 2}, {854.5, 2}, {855.5, 4}, {856.5, 
5}, {857.5, 2}, {858.5, 1}, {859.5, 2}, {860.5, 3}, {861.5, 
1}, {862.5, 2}, {863.5, 6}, {864.5, 5}, {865.5, 1}, {866.5, 
5}, {867.5, 2}, {868.5, 4}, {869.5, 4}, {870.5, 3}, {871.5, 
1}, {872.5, 1}, {873.5, 4}, {874.5, 2}, {875.5, 2}, {876.5, 
3}, {877.5, 2}, {878.5, 2}, {879.5, 2}, {880.5, 4}, {881.5, 
1}, {882.5, 2}, {883.5, 4}, {884.5, 2}, {885.5, 4}, {886.5, 
7}, {887.5, 1}, {888.5, 3}, {889.5, 1}, {890.5, 1}, {891.5, 
5}, {892.5, 7}, {893.5, 2}, {894.5, 3}, {895.5, 5}, {896.5, 
3}, {897.5, 1}, {898.5, 1}, {899.5, 2}, {900.5, 1}, {901.5, 
1}, {903.5, 1}, {905.5, 2}, {906.5, 3}, {907.5, 2}, {908.5, 
7}, {909.5, 2}, {911.5, 2}, {912.5, 1}, {915.5, 4}, {916.5, 
4}, {917.5, 2}, {918.5, 1}, {919.5, 1}, {920.5, 3}, {921.5, 
1}, {922.5, 3}, {924.5, 4}, {925.5, 1}, {926.5, 3}, {927.5, 
2}, {928.5, 1}, {929.5, 1}, {930.5, 3}, {932.5, 1}, {933.5, 
1}, {935.5, 1}, {936.5, 1}, {937.5, 2}, {938.5, 2}, {940.5, 
1}, {941.5, 1}, {943.5, 2}, {944.5, 1}, {945.5, 1}, {946.5, 
2}, {947.5, 2}, {948.5, 1}, {949.5, 1}, {950.5, 3}, {953.5, 
2}, {956.5, 1}, {958.5, 1}, {960.5, 2}, {961.5, 2}, {963.5, 
1}, {970.5, 2}, {971.5, 1}, {976.5, 1}, {977.5, 1}, {978.5, 
1}, {983.5, 1}, {985.5, 1}, {987.5, 3}, {989.5, 1}, {990.5, 
1}, {994.5, 1}, {995.5, 2}, {996.5, 1}, {997.5, 1}, {1005.5, 
1}, {1010.5, 1}, {1014.5, 1}, {1024.5, 1}, {1026.5, 1}, {1028.5, 
1}, {1029.5, 1}, {1035.5, 1}, {1037.5, 1}, {1038.5, 1}, {1055.5, 
1}, {1057.5, 1}, {1067.5, 1}, {1071.5, 1}, {1080.5, 1}, {1088.5, 
2}, {1091.5, 1}, {1097.5, 1}, {1098.5, 1}, {1100.5, 1}, {1108.5, 
1}, {1117.5, 1}, {1125.5, 1}, {1138.5, 1}, {1141.5, 1}, {1156.5, 
1}, {1187.5, 1}, {1195.5, 1}, {1201.5, 1}, {1202.5, 1}, {1227.5, 
1}, {1277.5, 1}};

datax = data[[All, 1]];
datay = data[[All, 2]];

errors = {1, 2.23606797749979, 1.73205080756888, 1, 1, 
   1.73205080756888, 1, 1, 1.73205080756888, 1.4142135623731, 1, 2, 
   1.73205080756888, 1, 1, 2, 1.4142135623731, 1, 1.73205080756888, 2,
    1.73205080756888, 1.4142135623731, 2.44948974278318, 1, 2, 
   2.44948974278318, 1.4142135623731, 1.73205080756888, 2, 1, 
   2.23606797749979, 1.4142135623731, 1, 1, 1, 1.4142135623731, 1, 1, 
   1, 1, 1.73205080756888, 1.73205080756888, 1.4142135623731, 
   1.4142135623731, 1.4142135623731, 1, 1.4142135623731, 2, 1, 
   1.4142135623731, 1, 1.73205080756888, 1.73205080756888, 
   2.23606797749979, 2, 1, 1.4142135623731, 1, 1.73205080756888, 
   2.23606797749979, 1.4142135623731, 1.73205080756888, 1, 
   1.4142135623731, 1.4142135623731, 2, 1.73205080756888, 1, 1, 
   1.4142135623731, 1, 1.4142135623731, 1.73205080756888, 
   1.73205080756888, 1, 1, 1, 1, 1, 1.4142135623731, 1.4142135623731, 
   1.73205080756888, 1, 1.4142135623731, 1, 1.73205080756888, 
   1.4142135623731, 1, 1.4142135623731, 1, 1.4142135623731, 
   1.4142135623731, 1, 1, 1.4142135623731, 1, 1, 1, 1.4142135623731, 
   1.73205080756888, 1.4142135623731, 1, 1, 1, 1, 1, 1, 
   1.4142135623731, 1, 1, 1, 1.4142135623731, 1, 1, 1, 1, 1, 1, 
   1.4142135623731, 1, 1.73205080756888, 1, 1, 1, 1, 1, 1, 
   1.4142135623731, 1.4142135623731, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
   1.73205080756888, 1, 1, 1.4142135623731, 1, 1, 1, 1, 1, 1, 
   1.4142135623731, 1.4142135623731, 1, 1, 1, 1, 1.4142135623731, 
   1.73205080756888, 1, 1, 1, 1, 1, 1, 1.4142135623731, 1, 1, 1, 1, 
   1.73205080756888, 2, 1, 1, 2.23606797749979, 2.44948974278318, 
   2.64575131106459, 3, 1.73205080756888, 2.44948974278318, 
   3.16227766016838, 3.46410161513775, 3.46410161513775, 
   3.87298334620742, 4.89897948556636, 4.79583152331272, 
   5.65685424949238, 5.56776436283002, 6.16441400296898, 
   5.47722557505166, 7.34846922834953, 7.28010988928052, 
   8.54400374531753, 8.18535277187245, 8.77496438739212, 
   8.94427190999916, 8.24621125123532, 10.3440804327886, 
   10.7238052947636, 10.5830052442584, 10.770329614269, 
   11.916375287813, 11.0905365064094, 11.9582607431014, 
   13.114877048604, 13.2664991614216, 14.0356688476182, 
   14.1774468787578, 14.6628782986152, 15.7797338380595, 
   16.4012194668567, 16.4620776331543, 16.431676725155, 
   17.5499287747842, 17.6351920885484, 18.7882942280559, 
   18.6010752377383, 20.0249843945008, 19.2353840616713, 
   20.0748598998847, 20.6155281280883, 20.4450483002609, 
   20.4205778566621, 21.7025344142107, 22.494443758404, 
   22.0907220343745, 22.4276614920058, 22.5166604983954, 
   22.5831795812724, 24.1660919471891, 23.832750575626, 
   23.6431808350738, 24.5153013442625, 23.5584379787795, 
   24.0416305603426, 26.0959767013998, 24.2487113059643, 
   24.4948974278318, 24.5967477524977, 25.4361946839538, 
   25.9422435421457, 25.219040425837, 26.0768096208106, 
   26.3628526529281, 26.7581763205193, 26.7768556779918, 
   27.2396769437525, 26.0576284415908, 26.9072480941474, 
   26.9072480941474, 27.3130005674953, 26.9814751264641, 
   26.5518360947035, 26.944387170615, 27.0554985169374, 
   26.1916017074176, 26.4386081328046, 27.3861278752583, 
   26.6270539113887, 26.5141471671257, 26.8886593194975, 
   26.7955220139485, 26.0192236625154, 25.8843582110896, 
   27.5680975041804, 25.5538646783613, 27.0185121722126, 
   26.343879744639, 27.0370116691916, 25.475478405714, 
   26.5329983228432, 26.3058928759318, 25.4361946839538, 
   25.1992063367083, 25.9422435421457, 25.9807621135332, 
   26.3248931621764, 24.8394846967484, 25.6124969497314, 
   25.6124969497314, 24.9599679486974, 24.1660919471891, 
   25.9229627936314, 25.3574446662119, 25.475478405714, 
   23.832750575626, 25.2586618806302, 24.9799919935936, 
   24.8797106092495, 23.6431808350738, 24.9198715887542, 
   23.3238075793812, 23.6220236220354, 23.5159520326097, 
   23.5584379787795, 23.473389188611, 23.1084400165827, 
   24.1453929352993, 22.9346898823594, 22.9346898823594, 
   23.259406699226, 22.561028345357, 22.2710574513201, 
   22.4499443206436, 23.4520787991172, 22.561028345357, 
   21.5870331449229, 21, 21.7944947177034, 21.6564078277077, 
   21.3072757526625, 21.0475651798492, 20.3715487874634, 
   20.6397674405503, 21.2602916254693, 20.4939015319192, 
   20.3960780543711, 20.591260281974, 20.174241001832, 
   20.9045449603669, 19.9248588451713, 19.8997487421324, 
   20.4939015319192, 20.0499376557634, 19.94993734326, 
   19.8494332412792, 19.7484176581315, 18.7349939951952, 
   20.0249843945008, 18.3030052177231, 19.6977156035922, 
   18.6010752377383, 18.6279360101972, 18.9208879284245, 
   18.7882942280559, 17.9443584449264, 18.0554700852678, 
   18.3847763108502, 17.7482393492988, 17.606816861659, 
   18.7082869338697, 17.7200451466693, 17.2916164657906, 
   17.5783958312469, 16.4924225024706, 17.1172427686237, 
   17.2336879396141, 16.8522995463527, 16.7630546142402, 
   15.7797338380595, 16.7630546142402, 16.2172747402269, 
   16.4620776331543, 16.6433169770932, 16.4620776331543, 
   16.8819430161341, 16.3707055437449, 15.9687194226713, 
   16.1554944214035, 15.6843871413581, 15.2970585407784, 
   16.2172747402269, 15.0996688705415, 15.7480157480236, 
   14.8660687473185, 15.4272486205415, 15.0332963783729, 
   14.3178210632764, 14.456832294801, 13.6747943311773, 
   15.0332963783729, 14.8323969741913, 14.2126704035519, 
   14.6969384566991, 14.456832294801, 13.8202749610853, 
   14.142135623731, 14.3178210632764, 13.7840487520902, 
   14.247806848775, 14.6969384566991, 13.9283882771841, 
   13.8924439894498, 14.7986485869487, 12.6885775404495, 13, 
   13.228756555323, 12.4096736459909, 13.3790881602597, 
   12.8452325786651, 13.1529464379659, 13.228756555323, 
   12.6885775404495, 12.2882057274445, 12.0415945787923, 
   12.4899959967968, 12.1243556529821, 12.1655250605964, 
   11.6619037896906, 12.6491106406735, 12.2474487139159, 
   11.7898261225516, 12.9614813968157, 11.916375287813, 12, 
   11.13552872566, 11.8743420870379, 12.4096736459909, 
   11.7046999107196, 11.5758369027902, 11.4891252930761, 
   11.3578166916005, 10.3440804327886, 10.295630140987, 
   11.7473401244707, 10.9544511501033, 10.3923048454133, 
   10.1980390271856, 10.3923048454133, 10.9087121146357, 
   10.9544511501033, 10.5830052442584, 11, 10.7238052947636, 
   11.0905365064094, 11.0453610171873, 9.21954445729289, 
   9.59166304662544, 10.5356537528527, 10, 10.5356537528527, 
   9.4339811320566, 9.74679434480896, 10.7238052947636, 
   9.89949493661167, 10.0498756211209, 9.8488578017961, 
   9.69535971483266, 10.1488915650922, 10.1980390271856, 10, 
   10.0995049383621, 9.2736184954957, 8.66025403784439, 
   9.53939201416946, 9.53939201416946, 9.79795897113271, 10, 
   9.59166304662544, 9, 9.21954445729289, 8.88819441731559, 
   8.94427190999916, 9.2736184954957, 9, 8.60232526704263, 8, 
   9.16515138991168, 8.48528137423857, 9.4339811320566, 
   8.18535277187245, 8.54400374531753, 8.30662386291807, 
   8.66025403784439, 7.14142842854285, 8.48528137423857, 
   8.24621125123532, 8.48528137423857, 8.36660026534076, 
   8.94427190999916, 7.14142842854285, 8, 7.41619848709566, 
   7.21110255092798, 8.66025403784439, 7.28010988928052, 
   7.68114574786861, 9, 7.48331477354788, 7.48331477354788, 
   8.48528137423857, 8.18535277187245, 6.6332495807108, 
   7.87400787401181, 7.34846922834953, 6.70820393249937, 
   7.81024967590665, 7.07106781186548, 8.06225774829855, 
   6.78232998312527, 8.30662386291807, 7.34846922834953, 
   6.557438524302, 7.81024967590665, 6.557438524302, 7.07106781186548,
    6.08276253029822, 6.32455532033676, 7.07106781186548, 
   6.6332495807108, 6.557438524302, 7.61577310586391, 
   6.78232998312527, 7, 6.48074069840786, 5.8309518948453, 
   5.91607978309962, 7, 6.6332495807108, 7.34846922834953, 
   7.07106781186548, 6.48074069840786, 7.87400787401181, 
   6.48074069840786, 6.32455532033676, 6.40312423743285, 
   6.78232998312527, 6.6332495807108, 5.56776436283002, 
   6.557438524302, 6.40312423743285, 7.28010988928052, 
   6.2449979983984, 5.3851648071345, 5.91607978309962, 
   6.70820393249937, 6.40312423743285, 6.78232998312527, 6, 
   7.28010988928052, 6.16441400296898, 6.70820393249937, 
   6.32455532033676, 5.91607978309962, 5.29150262212918, 
   6.16441400296898, 5.74456264653803, 5.74456264653803, 5, 
   5.74456264653803, 5.65685424949238, 6.08276253029822, 
   5.91607978309962, 5.3851648071345, 6.2449979983984, 6, 
   5.8309518948453, 5.19615242270663, 5.09901951359278, 
   5.8309518948453, 5.09901951359278, 5.19615242270663, 
   6.32455532033676, 5.65685424949238, 4.69041575982343, 
   4.79583152331272, 5, 5.47722557505166, 4.47213595499958, 
   5.47722557505166, 5.19615242270663, 4.79583152331272, 
   4.69041575982343, 5.47722557505166, 3.16227766016838, 
   5.65685424949238, 5.3851648071345, 5.8309518948453, 
   5.3851648071345, 5.47722557505166, 3.60555127546399, 4, 4, 
   5.3851648071345, 4.24264068711928, 4.58257569495584, 
   5.29150262212918, 4.12310562561766, 3.87298334620742, 
   4.47213595499958, 5.09901951359278, 4.69041575982343, 
   4.35889894354067, 4.47213595499958, 4.69041575982343, 4, 
   5.19615242270663, 4.47213595499958, 4.24264068711928, 5, 
   4.58257569495584, 4.47213595499958, 3.60555127546399, 
   3.87298334620742, 4.12310562561766, 3.46410161513775, 
   3.16227766016838, 4.79583152331272, 5.09901951359278, 
   5.3851648071345, 4.12310562561766, 4.24264068711928, 
   4.89897948556636, 4.24264068711928, 4.35889894354067, 
   3.74165738677394, 3.16227766016838, 4.47213595499958, 
   3.46410161513775, 3.3166247903554, 3.87298334620742, 
   3.60555127546399, 4.12310562561766, 4.69041575982343, 4, 
   2.82842712474619, 3.74165738677394, 3.60555127546399, 
   3.3166247903554, 2.82842712474619, 3.3166247903554, 
   3.16227766016838, 3.46410161513775, 3.3166247903554, 
   3.46410161513775, 3, 3.16227766016838, 3.3166247903554, 
   3.60555127546399, 3.60555127546399, 4.35889894354067, 
   4.35889894354067, 3.60555127546399, 3.46410161513775, 
   2.64575131106459, 3.16227766016838, 3, 2.82842712474619, 
   3.16227766016838, 3.3166247903554, 3, 4.12310562561766, 
   3.46410161513775, 3.3166247903554, 3.46410161513775, 
   3.3166247903554, 3.74165738677394, 3.3166247903554, 
   3.74165738677394, 3.3166247903554, 3, 3.74165738677394, 3, 
   3.16227766016838, 3.3166247903554, 2.64575131106459, 
   3.16227766016838, 2.82842712474619, 3.3166247903554, 
   3.16227766016838, 3, 2, 3.60555127546399, 2.64575131106459, 
   2.82842712474619, 2.82842712474619, 2.64575131106459, 3, 
   3.46410161513775, 3.3166247903554, 2.44948974278318, 
   2.44948974278318, 2.82842712474619, 2.23606797749979, 
   2.44948974278318, 2, 2.44948974278318, 2.44948974278318, 
   2.64575131106459, 3, 2.64575131106459, 2.82842712474619, 
   1.73205080756888, 2.23606797749979, 2.44948974278318, 
   2.82842712474619, 2.44948974278318, 2.23606797749979, 
   2.82842712474619, 2.23606797749979, 3.3166247903554, 
   2.64575131106459, 2.64575131106459, 3.16227766016838, 
   2.82842712474619, 1.73205080756888, 2.44948974278318, 
   1.73205080756888, 2.82842712474619, 2.64575131106459, 
   2.82842712474619, 2.44948974278318, 1.73205080756888, 
   1.73205080756888, 2.44948974278318, 2.82842712474619, 2, 3, 
   2.82842712474619, 2.44948974278318, 2.23606797749979, 
   2.64575131106459, 2.23606797749979, 2, 2, 2.44948974278318, 
   2.23606797749979, 2.23606797749979, 2.44948974278318, 
   2.44948974278318, 2.82842712474619, 1, 1.73205080756888, 
   1.4142135623731, 1.73205080756888, 2, 2.44948974278318, 2, 
   2.23606797749979, 2.23606797749979, 2, 3.16227766016838, 
   2.23606797749979, 2.44948974278318, 2, 1.4142135623731, 1, 
   1.73205080756888, 1.73205080756888, 2, 2.44948974278318, 2, 
   2.44948974278318, 2.23606797749979, 1.4142135623731, 
   1.4142135623731, 2, 2.23606797749979, 1.4142135623731, 1, 
   1.4142135623731, 1.73205080756888, 1, 1.4142135623731, 
   2.44948974278318, 2.23606797749979, 1, 2.23606797749979, 
   1.4142135623731, 2, 2, 1.73205080756888, 1, 1, 2, 1.4142135623731, 
   1.4142135623731, 1.73205080756888, 1.4142135623731, 
   1.4142135623731, 1.4142135623731, 2, 1, 1.4142135623731, 2, 
   1.4142135623731, 2, 2.64575131106459, 1, 1.73205080756888, 1, 1, 
   2.23606797749979, 2.64575131106459, 1.4142135623731, 
   1.73205080756888, 2.23606797749979, 1.73205080756888, 1, 1, 
   1.4142135623731, 1, 1, 1, 1.4142135623731, 1.73205080756888, 
   1.4142135623731, 2.64575131106459, 1.4142135623731, 
   1.4142135623731, 1, 2, 2, 1.4142135623731, 1, 1, 1.73205080756888, 
   1, 1.73205080756888, 2, 1, 1.73205080756888, 1.4142135623731, 1, 1,
    1.73205080756888, 1, 1, 1, 1, 1.4142135623731, 1.4142135623731, 1,
    1, 1.4142135623731, 1, 1, 1.4142135623731, 1.4142135623731, 1, 1, 
   1.73205080756888, 1.4142135623731, 1, 1, 1.4142135623731, 
   1.4142135623731, 1, 1.4142135623731, 1, 1, 1, 1, 1, 1, 
   1.73205080756888, 1, 1, 1, 1.4142135623731, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1.4142135623731, 1, 1, 1, 1, 1, 1, 1, 
   1, 1, 1, 1, 1, 1, 1, 1, 1};

I want to perform a fit with the Landau function on the errors including data:

Landau[ampl_, x0_, sigma_, x_] :=  ampl*PDF[LandauDistribution[x0, sigma], x]

nlm = NonlinearModelFit[data, 
   Landau[ampl, x0, sigma, x], {{ampl, 135000}, {x0, 270}, {sigma, 50}}, x, Weights -> 1/errors^2];
nlm[{"BestFitParameters", "ParameterTable"}]

Which returns some nice results: enter image description here The problem is when I perform the Chi squared test:

fit = Part[nlm["BestFitParameters"], 2 ;; 3];

threesigmaCL = 1 - 0.997300204;
fivesigmaCL = 1 - 0.999999426697;
H=PearsonChiSquareTest[datay, LandauDistribution[x0, sigma] /. fit, "HypothesisTestData", SignificanceLevel -> fivesigmaCL]
H["TestDataTable", "TestConclusion"]
H["DegreesOfFreedom"]

it returns that the data are not distributed as the Landau (see image below), even if the distribution actually fits the data pretty well (see image above) enter image description here

I think this is due to the PearsonChiSquareTest not taking errors into account, but I have no idea of how to feed them to the test.

Does anyone have an idea on how to proceeed?

Thanks in advance

$\endgroup$
4
  • $\begingroup$ You are confusing fitting a curve that has the shape of a Landau distribution (i.e., a regression) and fitting a Landau distribution with a random sample from a (contaminated with small errors) Landau distribution. The PearsonChiSquareTest assumes the latter (which you don't have even if you didn't have the measurement errors). $\endgroup$
    – JimB
    Jun 14 at 17:56
  • $\begingroup$ So you are saying the PearsonChiSquareTest does not do what I want... then the question becomes how can I obtain chi squared value for my fit? Is there something ready to use or I have to write the function on my own? Thanks for helping me understand anyway :) $\endgroup$
    – J. Dowe
    Jun 14 at 19:21
  • $\begingroup$ Look into nlm["ANOVATable"]. There you find it in the error row and MS column. $\endgroup$ Jun 14 at 20:33
  • $\begingroup$ @JulienKluge. But the "ANOVATable" will only suggest that fitting the Landau curve is better than just fitting an overall mean. $\endgroup$
    – JimB
    Jun 14 at 21:16
2
$\begingroup$

There are two parts to this response: (1) Why a chisquare test is inappropriate for your data and objective, and (2) What you might consider as to the adequacy of the fit.

Why a chisquare test is inappropriate for your data and objective.

The PearsonChiSquareTest assumes that the data is a random sample from a specified probability distribution. Your "data" is not a random sample from any distribution but rather the measured values that are thought to be of something proportional to the height of a Landau probability density function. (Appropriate data for PearsonChiSquareTest would be in the same units as datax.)

For the remainder of this response I'll refer to a "Landau curve" as opposed to a "Landau probability distribution" as it's simply the curve form you're dealing with and not any statements about samples from a Landau probability distribution.

What you might consider as to the adequacy of the fit.

How to judge the adequacy of a regression is better asked at CrossValidated but here are some considerations:

Your statement of "nice results". The P-values simply tell you that what you observed is unlikely to occur vary often if the parameters are zero and that isn't or shouldn't be very interesting as I'm sure you already know the parameter values are not zero. The standard errors displayed in the "ParameterTable" are constructed under the assumption that the Landau curve form is correct. So those can't give you an indication that you have a Landau curve form.

Patterns of residuals If one sees patterns in the residuals, then that (many times) means lack of an adequate fit. Here are the residuals (divided by the measurement error standard deviations) vs the x value:

ListPlot[Transpose[{data[[All, 1]], nlm["FitResiduals"]/errors}]]

Standardized residuals vs predictor variable

There are definite areas where the Landau curve is higher than the data values and areas where the Landau curve is much lower than the data values. Are those deviances too large? Well, it depends on what you (as opposed to a P-value) decide is large. And your standard for what is large should be determined prior to collecting the data. (In other words, it shouldn't be "I'll know it when I see it." Although you certainly wouldn't be alone if you used that criterion.)

Use of "errors". The errors list is simply proportional to the square root of the response variable so you are making assumptions (rightly or wrongly) about the standard deviation of the response variable rather than "measuring" the error at each data point. That assumption could be influencing the fit. I assume your response variable is a count that you know (?) has a Poisson distribution.

An alternative to a Landau curve. Do you have an alternative to a Landau curve? If not, then an assessment might be based on various summary statistics that you consider as goodness-of-fit statistics is about all you can do. Those goodness-of-fit statistics might weigh the fit in the tails more than near the maximum. But, again, that depends on subject matter and the objectives. And without specific objectives, you can't conclude that "this data follows a Landau curve". You can only state how well it fits.

OK. Enough sermonizing. You'll (generally) get better responses on such topics at CrossValidated

$\endgroup$
4
  • 1
    $\begingroup$ Thanks for accepting but you might want to retract that and wait as there are really good folks out there with better answers. And I have an alternative approach I'm about to enter. $\endgroup$
    – JimB
    Jun 14 at 22:40
  • $\begingroup$ You already clarified a lot for me anyway, thanks $\endgroup$
    – J. Dowe
    Jun 14 at 22:45
  • $\begingroup$ I have modified a bit my code following your suggestions, and I think I have reached quite a reasonable point. It is difficult to explain everything I did in a comment, but you can fin my modified code in here: link. What it shows is that the maximum likelihood procedure brings smaller residuals that are contained within 5 sigma up to a certain energy, which I find more than a reasonable conclusion for a student exercise $\endgroup$
    – J. Dowe
    Jun 15 at 9:00
  • 1
    $\begingroup$ Looks good. Three comments: (1) The fitted curve in your question appears to be the "unweighted" fit using FindFit, and (2) If you are more interested in fitting at lower energy levels (which I'm assuming is the x variable), consider only using x values up to say 800 and you might get an even better fit - which is part of explicitly stating objectives prior to analysis, and (3) Don't rely too strongly on 3 or 5 "sigmas" as why should your current measurement error overly influence whatever physical process is going on> $\endgroup$
    – JimB
    Jun 15 at 15:48
2
$\begingroup$

Rather than using weighted least squares with NonlinearModelFit to estimate the parameters for the Landau curve, you might consider an explicit maximum likelihood approach.

Because the response variable is a count and the "errors" you give are simply the square root of the response, I'm assuming that for any particular predictor value, the response follows a Poisson distribution with a mean corresponding to a value proportional to the pdf of a Landau distribution. If so, maximum likelihood (with that additional assumption) might give a better fit.

The log of the likelihood is

logL = Total[LogLikelihood[PoissonDistribution[
  ampl PDF[LandauDistribution[x0, sigma], #[[1]]]], {#[[2]]}] & /@ data];

Because of the large negative exponents found, I need to modify that slightly:

logL = Total[LogLikelihood[PoissonDistribution[
   Max[0.00001, ampl PDF[LandauDistribution[x0, sigma], #[[1]]]]], {#[[2]]}] & /@ data];

Now we find the values of the parameters that maximize logL:

mle = FindMaximum[{logL, sigma > 0 && ampl > 0}, {{ampl, 94817.}, {x0, 293.5}, {sigma, 35.4}}]
(* {-7477.54, {ampl -> 104750., x0 -> 281.426, sigma -> 40.9344}} *)

A plot of both the maximum likelihood and weighted least squares results along with the data (without the error bars) is as follows:

Show[ListPlot[data, PlotStyle -> {{LightGray, PointSize[0.005]}}, ImageSize -> Large],
  Plot[{ampl PDF[LandauDistribution[x0, sigma], x] /. mle[[2]],
   Landau[94816.98859939395`, 293.4768377025875`, 35.39767223064983`, x]},
  {x, 0, 1300}, PlotStyle -> {Red, Green}, PlotRange -> All,
  PlotLegends -> Placed[{"Maximum likelihood", "Weighted least squares with `NonlinearModelFit`"},
    {Right, Center}]]]

Data and fits

The removal of the error bars show that the weighted least squares result seems to underestimate the data from predictor values 400 to 550. Neither fit drops to zero as quickly as the data.

Which approach is best? Are either adequate? (I'll have to write that up a bit later.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.