2
$\begingroup$

If I have the following data:

data={{63.0359,-0.377468},{63.1371,-0.36889},{63.236,-0.340264},{63.3372,-0.311102},{63.4386,-0.317515},{63.5377,-0.302648},{63.6382,-0.285227},{63.7386,-0.309458},{63.8393,-0.271844},{63.9399,-0.274895},{64.0393,-0.286301},{64.1397,-0.245381},{64.2408,-0.284001},{64.3407,-0.237523},{64.4422,-0.197306},{64.54,-0.186697},{64.6404,-0.133621},{64.7412,-0.262931},{64.8425,-0.134602},{64.9444,-0.180465},{65.0425,-0.141258},{65.1429,-0.124103},{65.2432,-0.14909},{65.3423,-0.165316},{65.443,-0.119178},{65.5434,-0.154446},{65.6434,-0.142109},{65.7436,-0.184858},{65.844,-0.161701},{65.945,-0.109441},{66.0458,-0.198008},{66.1447,-0.0930774},{66.2465,-0.11443},{66.3454,-0.0846786},{66.4464,-0.0878157},{66.5471,-0.148279},{66.6477,-0.122703},{66.7478,-0.129607},{66.846,-0.130622},{66.9465,-0.136439},{67.048,-0.237768},{67.1481,-0.124143},{67.2486,-0.0698046},{67.3503,-0.0452734},{67.4509,-0.109995},{67.551,-0.144111},{67.6488,-0.0767324},{67.7514,-0.104839},{67.8498,-0.043911},{67.9504,-0.0875963},{68.0527,-0.106565},{68.1505,-0.0352017},{68.2529,-0.0995127},{68.3522,-0.105364},{68.4524,0.0275967},{68.5548,-0.0881422},{68.6534,-0.120237},{68.7538,-0.0829747},{68.8549,-0.135021},{68.9576,-0.186265},{69.0557,-0.0837615},{69.1571,-0.210476},{69.2541,-0.103774},{69.3557,-0.197768},{69.4549,-0.176159},{69.5554,-0.16489},{69.6563,-0.145311},{69.7568,-0.129697},{69.8581,-0.178585},{69.9582,-0.0514388},{70.0609,-0.119592},{70.159,-0.155045},{70.2588,-0.046378},{70.3599,-0.141985},{70.4599,-0.122845},{70.5603,-0.0442577},{70.661,-0.0841938},{70.7612,-0.0780952},{70.8623,-0.196571},{70.9596,-0.0420082},{71.0612,-0.089715},{71.1626,-0.0875202},{71.2624,-0.0848227},{71.3632,-0.0510948},{71.4646,-0.0747354},{71.5653,-0.0647276},{71.6637,-0.0593889},{71.7651,0.015856},{71.8655,-0.08077},{71.9656,0.0328062},{72.0663,-0.0861278},{72.1666,-0.0136021},{72.2666,-0.0388442},{72.367,0.00699998},{72.4675,-0.0403441},{72.5671,0.0209988},{72.6682,-0.053782},{72.7689,-0.0424938},{72.8687,0.0153571},{72.9697,-0.105135},{73.0685,-0.0408923},{73.1695,-0.0689926},{73.2691,-0.114818},{73.3694,-0.0556425},{73.47,-0.113179},{73.5686,-0.0279214},{73.6706,-0.0711992},{73.7712,-0.0754252},{73.8719,-0.0714618},{73.9714,-0.104854},{74.0701,-0.0184052},{74.1729,-0.0242854},{74.2733,-0.0403457},{74.3723,-0.025646},{74.4731,-0.0500356},{74.5728,-0.0199442},{74.6733,0.0168603},{74.7742,0.04879},{74.8737,0.023149},{74.9739,0.0393329},{75.0749,0.0430668},{75.1756,0.0853634},{75.2754,0.0430295},{75.3755,0.0833915},{75.4767,0.0775784},{75.576,0.0736538},{75.6765,0.0771978},{75.7763,0.0444032},{75.8773,0.0591804},{75.977,0.0673182},{76.0777,0.0711651},{76.1774,0.101622},{76.2783,0.102251},{76.3784,0.0688463},{76.4781,0.076515},{76.5777,0.0826821},{76.6782,0.0839145},{76.7795,0.0867357},{76.8803,0.0295746},{76.9804,0.103667},{77.0799,0.0527557},{77.1808,0.0660514},{77.2816,0.0295279},{77.3809,0.129854},{77.4815,0.0984308},{77.5829,-0.00994034},{77.6826,0.0925383},{77.7832,0.0285631},{77.8827,0.0342876},{77.9833,0.0514509},{78.0839,-0.0306254},{78.1825,0.0245728},{78.2832,-0.00395284},{78.384,0.0701531},{78.4835,0.0560318},{78.5839,0.0296539},{78.6838,0.0252336},{78.7839,0.0452132},{78.8845,0.0555628},{78.9845,0.115994},{79.0854,0.0294528},{79.1845,0.102611},{79.2849,0.149225},{79.3865,0.00471552},{79.4858,0.102026},{79.5866,0.0593717},{79.6856,0.111954},{79.7864,0.120631},{79.8866,0.0939448},{79.986,0.124297},{80.0874,0.0483595},{80.1867,0.104533},{80.2866,0.127849},{80.3893,0.01285},{80.4878,0.0938407},{80.5891,0.0480354},{80.6881,0.0484184},{80.7882,0.0100602},{80.8901,0.0102189},{80.9897,0.0459907},{81.0896,0.047609},{81.19,0.0192626},{81.2902,0.0437195},{81.3916,0.000117753},{81.4905,0.0674037},{81.5909,0.0625754},{81.6925,-0.0421826},{81.7916,0.0660971},{81.892,0.0609279},{81.9913,0.0946857},{82.092,0.102265},{82.1942,0.0184685},{82.2935,0.0348381},{82.3947,0.0431542},{82.4943,0.0370449},{82.594,0.0936491},{82.6955,-0.0225001},{82.7945,0.0538391},{82.8967,-0.00553105},{82.9972,0.0277808},{83.0962,0.0528907},{83.1965,0.0365817},{83.2962,-0.00254658},{83.3963,0.0806524},{83.4983,-0.0324423},{83.5967,0.0681519},{83.6992,0.00392629},{83.7983,0.0334884},{83.8987,0.101576},{83.9984,-0.0605161},{84.0987,0.0527921},{84.2,0.0372952},{84.2993,-0.00451583},{84.3992,0.0741938},{84.5002,-0.0306354},{84.5997,0.0126465},{84.7004,0.0374626},{84.8007,0.00627066},{84.9004,0.0819417},{85.0015,0.024233},{85.101,0.0305066},{85.2013,0.0903355},{85.3017,0.0302726},{85.401,0.0794114},{85.503,0.0828585},{85.6022,0.0936857},{85.703,0.156533},{85.8045,0.114789},{85.9029,0.161412},{86.0036,0.127524},{86.1033,0.184279},{86.2044,0.29168},{86.3062,0.157925},{86.4051,0.218502},{86.5055,0.186206},{86.6056,0.259661},{86.7062,0.314921},{86.8068,0.193787},{86.9069,0.255744},{87.0078,0.288432},{87.1083,0.18052},{87.2081,0.233166},{87.3089,0.16766},{87.4083,0.208161},{87.5093,0.154674},{87.6099,0.0820034},{87.7092,0.159547},{87.8108,0.118381},{87.9091,0.11305},{88.01,0.160598},{88.1106,0.0625675},{88.2107,0.114323},{88.3115,0.0607155},{88.4115,0.0626875},{88.512,0.0787813},{88.6134,0.00629379},{88.7134,0.0386982},{88.8132,0.0420906},{88.913,0.0361965},{89.0137,0.0962618},{89.115,0.0188612},{89.2137,0.04278},{89.3149,0.0147721},{89.4146,0.00564302},{89.5146,0.0647129},{89.6153,-0.00390606},{89.7144,0.0366069},{89.8154,0.0381451},{89.9166,-0.0410749},{90.0157,0.0214114},{90.1161,0.00122263},{90.2161,0.0382576},{90.3169,0.079943},{90.4183,-0.00338674},{90.5168,0.0335765},{90.6174,-0.0349709},{90.7172,-0.00686173},{90.818,-0.0033936},{90.9191,-0.117864},{91.0187,0.0194805},{91.1198,-0.0709443},{91.2194,-0.0316406},{91.319,-0.0548936},{91.4195,-0.108552},{91.5195,-0.0341622},{91.6199,-0.0563115},{91.7203,-0.0976142},{91.8211,-0.0160093},{91.9215,-0.106219},{92.0206,-0.0578895},{92.1208,-0.0591874},{92.2218,-0.0432252},{92.3214,-0.071423},{92.422,-0.0605619},{92.5222,0.0110079},{92.6239,0.0473027},{92.7232,0.00557733},{92.8237,0.0210314},{92.9248,-0.00555508},{93.0241,-0.0188044},{93.1242,0.0522193},{93.2252,0.0136839},{93.3255,-0.0484867},{93.4255,0.00890995},{93.5254,0.0000760234},{93.6256,0.0187633},{93.7273,-0.0508971},{93.8266,0.0108169},{93.9278,0.0161969},{94.0276,-0.0144502},{94.1282,0.00724041},{94.2294,-0.0130664},{94.3287,0.04053},{94.4281,0.0917202},{94.5294,-0.0108698},{94.6304,0.0854767},{94.7308,0.0508835},{94.8304,0.043496},{94.9306,0.096094},{95.0311,0.0425868},{95.1305,0.00981259},{95.2308,0.0876683},{95.3307,0.0227264},{95.4308,0.0550309},{95.5316,-0.00476025},{95.6326,0.0820943},{95.7321,0.0203032},{95.8324,0.0186398},{95.9331,0.0494208},{96.0331,0.0608241},{96.1334,0.0435086},{96.2344,0.032548},{96.3348,0.0403473},{96.4355,0.0635307},{96.5359,0.0483974},{96.6346,0.0725407},{96.735,0.117848},{96.8367,0.0483234},{96.9358,0.0593262},{97.0373,0.0992934},{97.1371,0.0700262},{97.2363,0.100931},{97.3363,0.0700837},{97.437,0.065287},{97.5371,0.0438809},{97.6378,0.0788256},{97.7386,0.0645919},{97.8383,0.0529107},{97.9391,0.0857188},{98.0398,0.00363135},{98.1403,0.0827982},{98.2402,-0.0380434},{98.3403,0.0504304},{98.4404,0.0870947},{98.5405,0.0286105},{98.6405,0.0907113},{98.7412,0.0976311},{98.842,0.0387416},{98.9416,0.0822455},{99.0424,0.0892565},{99.143,0.0105733},{99.2421,0.0435315},{99.3424,0.0243316},{99.4426,0.0955495},{99.5437,0.106561},{99.6442,0.0523241},{99.744,0.0289709},{99.8442,0.0680112},{99.9441,0.0466789},{100.044,0.139357}}

Which gives the following plot with ListPlot:

enter image description here

1) How can I best fit the peak that is around 85-90? 2) How can I find the area of that peak?

Edit: I tried @Antonov's quantile regression function as suggested by @JimB but I still do not know how to focus it only on the 85-90 region and how to obtain the area (I am very new in Mathematica). This is what I get using this method so far:

enter image description here

Is there an easier method perhaps using simply NonLinearFit?

Thank you !

$\endgroup$
2
  • $\begingroup$ I suspect that you'll like and choose a method that identifies the peak the way you see it. If that's true, just take the average height between 85 and 90 and multiply by 5 (=90-85) fir the area. No need to fit a curve. But if you have to fit a curve, try @AntonAntonov 's quantile regression function: mathematica.stackexchange.com/questions/162118/…. $\endgroup$
    – JimB
    May 26, 2020 at 1:00
  • $\begingroup$ Thank you for your suggestion @JimB. I edited the question to reflect what I was able to obtain using this method. Do you know if there is a simpler method simply by using something like NonLinearFit?. And yes, for my purposes it is necessary to do the fit of the peak. $\endgroup$
    – John
    May 26, 2020 at 1:13

1 Answer 1

2
$\begingroup$

To even attempt a fitting, one should consider a long list of caveats regarding the noisiness of your data, how you define your peak and what its functional shape should be, what you expect to be your baseline, etc. Nevertheless, you could try the following, with caution.

The peak is around 85ish, so select a region in the data that has a reasonably flat baseline and includes your "peak":

ListLinePlot[data[[120 ;;]]]

plot in region of interest

Fit a vaguely Gaussian peak shape to that region:

fit = NonlinearModelFit[
       data[[120 ;;]],
       height Exp[-(x - peakposition)^2/peakwidth^2] + baseline,
       {{height, 0.2}, {peakposition, 87}, {peakwidth, 1}, {baseline, 0.04}},
       x
     ];

fit["BestFitParameters"]

(* Out: 
  {height -> 0.209819, peakposition -> 86.7737, 
   peakwidth -> 1.06978, baseline -> 0.038016} 
*)

Plot the points, the fitted curve, and highlight the region of interest:

Show[
  Plot[
    fit[x], {x, data[[120, 1]], data[[-1, 1]]}, 
    PlotRange -> All, PlotStyle -> Black
  ],
  ListPlot[data[[120 ;;]]],
  Graphics[{
    Opacity[0.1],
    Rectangle[
      {peakposition - 3 peakwidth, baseline},
      {peakposition + 3 peakwidth, fit[peakposition]}
    ]
  }]
] /. fit["BestFitParameters"]

results of fit as plot

Now get the area of the peak after subtracting the baseline value:

NIntegrate[
 fit[x] - baseline /. fit["BestFitParameters"],
 {x, peakposition - 3 peakwidth, peakposition + 3 peakwidth} /. 
   fit["BestFitParameters"]
]

(* Out: 0.397838 *)
$\endgroup$
1
  • $\begingroup$ Thank you MarcoB! This works great! I appreciate it ! $\endgroup$
    – John
    May 26, 2020 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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