Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

gaussian - R Find Full width at half maximum for a gausian density distribution

I have a data set (come from reality) like

a<-c(12.4314579038074, 30.1197692762127, 31.8986680511062, 21.5000657793742, 
24.2201952026304, 21.4083286311931, 30.543892400514, 11.3243039196637, 
18.6629847817322, 68.5846251690826, 8.15853135278713, 20.0269675183568, 
23.761746451965, 15.7934365856289, 20.2308964167179, 16.1739058219803, 
16.80324393405, 17.8825865979249, 11.4033338599819, 24.6766819397457, 
21.6401012626284, 34.9473576269376, 21.2387163543256, 38.8393540982342, 
11.1324409747932, 27.9691456747847, 35.0247764515163, 25.2955953655814, 
20.1144847120957, 21.601935342838, NA, 37.0382391253826, 23.0768070922688, 
29.7978557208652, 25.5629412341385, 52.3688195218551, 24.3278804498841, 
24.5473987167943, 18.7003825260279, 7.59034179685435, 30.3494564815945, 
11.9464422720518, 31.1286124512956, 35.6013073091488, 59.7732211526442, 
18.1103630173406, 23.6991128199505, 35.0041638638631, 32.3290441334575, 
9.96009633874818, 31.9439199749795, 17.2338813393175, 19.4703069779573, 
40.0710364677356, 21.9784578364056, 14.8391748404154, 36.699595515976, 
8.23000952339805, 29.3936574804397, 16.608043366678, 31.8893140469488, 
25.0034860781714, 5.85410045445957, 33.6738722502197, 19.8719119513059, 
16.5220779562036, 18.5998514048289, 26.2005902882878, NA, 24.6566247442218, 
27.0333844562812, 14.886428829687, 17.5724702275547, 26.2137775245073, 
19.0507021982012, 10.9566296835514, 26.6958883379168, 7.96499401119146, 
26.1859738026908, 17.660793443073, 24.2581780545893, 13.2116252996823, 
20.8404415084083, 13.9759556218075, 8.08290201929875, 19.577431906635, 
30.8617872452287, 17.659162045328, 19.6553312413463, 54.5228181855605, 
8.61384429381566, 8.57902103633537, 14.3833198356842, 44.6520928899702, 
50.1684992597442, 19.1839092769506, 14.1859756348872, 22.319616459382, 
7.04281719040295, 19.9734034824111, 26.5179176521408, 13.1611965717225, 
16.9098287156019, 28.9883554716117, 26.0468146958332, 29.6763235030978, 
48.7345046631538, 38.4339027762459, 31.2090734875574, 15.9385304470886, 
12.8921108018056, 10.9673039456914, 10.3743768429606, 25.9387376803067, 
NA, 11.5544889726556, 18.7480106738499, 13.2374072159457, 16.0463683223854, 
13.6394902895386, 19.6499476784153, 19.6653905961478, 22.6713289483346, 
30.0530150121339, 39.2413167843811, 29.7476825791523, 67.017937817938, 
6.75394239192403, 13.8315465658099, 15.6479984367677, 11.6595078158563, 
16.6153046740276, 29.1944136335659, 20.0699193532974, 23.0964604145297, 
16.4642724437565, 31.4384175748718, 24.9125640407848, 25.0969240666473, 
32.7585005489893, 28.2005135471151, 11.6928832972854, 29.0925157165188, 
27.1449795674534, 19.7174609825609, 11.3155221077222, 13.8725373098617, 
10.4058292934838, 20.5471528311623, 24.593775927458, 24.5992797334339, 
25.7621705532288, 19.429523059737, 23.7267657702523, 26.8378886664471, 
33.0405101400995, 33.8244308994044, 23.923384237542, 10.1422998835261, 
8.36171095318636, 31.7070531272099, 29.7732770732215, 24.8822351146394, 
5.02000303147286, 12.8561338422933, 19.9693656971446, 19.599345558469, 
22.1630854796563, 22.3226724168097, 32.0046288304837, 9.97036087568324, 
17.9532401992864, 27.5200598557606, 18.2493582809349, 19.516614679827, 
8.73100033494884, 9.92568752683278, 36.111580524921, 26.5447538548956, 
31.5801048764258, 30.7784315713327, 43.9917658205537, 5.88518831155849, 
38.6914615372257, 22.4450167569794, 38.471255777786, 17.8759146100263, 
42.1237669506763, 40.8120103320423, 50.9620878359755, 24.8723162387534, 
28.281137488787, 21.1047200631107, NA, 35.6445176565107, NA, 
22.4329601563967, 17.1865147962927, 34.6207419910748, 27.488098898296, 
40.647159426457, 49.0566470559664, 25.2404304347901, 28.9937264113381, 
14.0652751682648, 16.8982448551594, NA, NA, 38.7092724982844, 
51.3923484671426, 56.2948963516975, 17.6784549803966, 21.346370069203, 
40.5568626421931, 11.5473392102776, 29.8901196029765, 55.8045368249135, 
32.5629692658593, 15.7151398771352, 50.69539004787, 28.6630956503548, 
NA, 33.745363485143, 30.1793575796192, 31.5239871763176, 23.413715020835, 
28.4068815777865, 26.628933941261, 28.8040299272661, 38.7590176170059, 
28.5895707604946, 27.3163626291958, 22.4432050319593, 22.8717709770244, 
15.5769117905467, 16.6205562869212, 19.6461009184912, 28.112145862862, 
22.4817869475301, 11.9911595195158, 27.7864754526246, 32.110827889238, 
38.6601905078103, 26.5431928219843, 37.5022713181254, 20.1507313327997, 
26.1701491671608, 13.5713776019221, 24.9836498596017, 21.2698715590683, 
25.0155871471049, 33.7177860466273, NA, 13.9496573767241, 16.1150625739034, 
16.6382037385219, 38.0327684962353, 15.4336346869134, 28.2741877552971, 
18.3988010783219, 46.8872039734549, 39.6400155384279, 42.2346150067755, 
23.8766379243586, 20.6388991126635, 13.4323233360809, 25.7328268912762, 
18.5198704804179, 35.1253893334279, 50.4960266232654, 22.8606920846386, 
16.1816315814691, 24.404001970632, 12.7156971608144, 16.1868830629463, 
30.2499403084286, 49.7785508137954, 33.2123299816736, NA, 12.9230946451066, 
7.08427169664578, 10.0671158815277, 19.7294071616146, 30.8425354787526, 
38.3145455434934, 16.7030543796463, 12.1822921506718, 24.8419226234385, 
NA, 19.6863906566313, 24.8415166763613, 27.2222764218966, 25.4530639943619, 
24.3584061455177, 21.6932253013582, 26.6862568289173, 10.4439641151796, 
8.16828313448626, 24.7764905211242, 24.0153889448978, 42.27494669877, 
23.1024890766068, 12.5421984383058, 28.126105527251, 11.7477790609559, 
37.8210140575854, 16.2510203840877, 29.5179896530944, 19.767113140873, 
21.180255311345, 50.1326402088336, 46.9411426142246, 22.1825770399621, 
38.3217563655723, 32.8198922751461, 18.1215432904772, 36.7957509446084, 
31.0953183824079, 41.2683134903454, 27.3369679280893, 18.6814450240623, 
40.9365261829113, 31.3995794910782, 45.3773497997797, 29.7809299163648, 
25.6494347188067, 12.2371700316698, 24.028235743912, 20.2190137194663, 
63.5048123597575, 19.4212679708406, 28.2540327945574, 15.6824059299007, 
26.4502584835429, 25.6747019832926, 21.3448542479901, 21.5398949527062, 
15.0453039478043, 15.435237823288, 21.9433429596872, 22.4942864667832, 
19.2699097293276, 13.7352833513297, 17.2542472110831, 47.1631828020397, 
43.0112020075035, 16.3372108879913, 24.2918076279655, 26.4439880171655, 
23.1117247311131, 36.6759437723188, 43.6176498793953, 32.0130676806535, 
30.6326404095052, 10.8268556221906, 52.7653604760821, 8.91595447346234, 
13.193539457832, 7.68418008204124, 15.449010979906, 30.9584089126334, 
51.9422244686175, 15.8458479496976, 14.1047956442756, 17.5191070473658, 
31.7011704471313, 14.8239075593942, 26.6479556968534, 12.7304068904724, 
21.6484498326962, 18.5454691264783, 19.7417604612319, 17.4178392306296, 
18.6961734797299, 16.6762708630409, 25.5769497729958, 20.4324858725377, 
48.0108296588978, 22.3873783217253, 61.8180303957998, 60.9275917236957, 
33.6030207132321, NA, 35.5927559357877, 20.7557420025042, 45.0952627270979, 
33.7073022209601, 23.7276388907278, 44.0279966951556, 18.4465734471124, 
35.376096916925, 11.049064991332, 6.38266176887074, 27.770464922835, 
14.3280667570411, 18.2895352437716, 11.8697485564632, 11.9115403522214, 
23.8995147554712, 22.9524551093465, 41.5537350356802, 8.32663490566077, 
41.2800566378259, 37.616909008102, 13.9220837749745, 53.4996016880608, 
38.0527622385737, 36.2584535594006, 31.3674093196625, 24.2902569424465, 
21.440394745746, 32.2127828476281, 22.1521432796998, 16.4186950681111, 
10.4937514476589, 32.4071007810483, 24.498045100507, 25.4241096355652, 
9.73946952507465, 21.4041253422142, 28.8926165924432, 34.512959841434, 
30.0571573052611, 22.4907629383951, 20.2211187443641, 16.8118098933704, 
23.5285775050765, 39.4440966466874, 33.2825067066343, 36.8830992125003, 
21.1282934201697, 18.6272972241037, 15.3140799736706, 40.0011498958142, 
10.0182747888065, 15.3706553616215, 41.9509134815123, 22.303622817723, 
19.2424468127472, 35.0099989943938, 16.6900077828908, 23.4847012508485, 
22.9601479739565, 13.7682136158064, 20.0454049113627, 27.7179470144016, 
43.7485548044574, 27.7379261226753, 32.1756980668739, 32.8029836110017, 
30.2392324390705, 31.3156918552083, 32.1847331854615, 20.5297104164335, 
50.9569341153107, 42.6081618367459, 18.636321910844, 12.4308178035891, 
26.6917378844734, 5.76426461481125, 25.0767930273219, 24.2457959380206, 
11.3931924451717, 19.077483646119, 12.0287714622052, 13.8729173763677, 
15.940072198383, 31.9320584106662, 16.1008550559317, 35.8212131776284, 
15.2435052118809, 3.44730091866671, 13.2863037128651, 33.2528958365812, 
23.0426972188497, 31.9040632994659, 21.2588079706295, 9.56009250089547, 
37.0841912585872, 21.7862379679352, 12.5945799997629, 11.9204901690358, 
34.2003866802345, 22.1076801376058, 14.7504409350283, 12.2988895790339, 
37.4743876245349, 4.40070781544351, 27.47718305659, 45.3352312111182, 
44.7238582623121, 30.1074154853725, 25.3584692242304, 18.2894817200095, 
39.6668104206319, 15.1780135384362, 8.90023187782675, 12.695608490357, 
7.97231909106364, 18.0254627826149, 37.1330399717644, 40.3814619400626, 
15.7530424414729, 26.4871843271195, 11.3849905569825, 14.4310436716623, 
15.7889776729542, 15.3189979064802, 8.14775366334019, 21.3763917473048, 
19.4271587027591, 8.17415804490136, 8.56927307423665, 9.9955524608618, 
15.5450134422331, 10.823091946932, 8.44824243438286, 4.43490646514755, 
5.47934855653405, 7.23626623411468, 25.3530745380911, 24.3179916472365, 
18.7488727821045, 32.190181880216, 20.3023247566628, 16.5179670640049, 
13.5756284381254, 16.6579681190254, 31.1737441837392, 26.4445566581656, 
19.0657083835412, 9.02756346026971, 13.8198542042488, 19.5572751031157, 
15.9815268564019, 21.2096031612745, 23.1965642826673, 22.9413587497691, 
54.0401136217987, 14.3385183237915, 9.56798831205209, 16.8699681496442, 
15.9839479181869, 13.6433809778083, 11.6657052013993, 33.293408496818, 
22.5090700291058, 19.3612583830867, 14.4092661794021, 17.9685233644732, 
5.41812657103551, 5.85301279046166, 16.4916538514991, 32.8886078034163, 
42.5319945344839, 6.96221532796392, 10.8250789766828, 14.0362434679265, 
13.4236572258544, 8.18430437430949, 8.49810493010364, 19.9805220462551, 
7.99530774694417, 7.7257996525705, 29.0351171682388, 4.33760495695362, 
17.6928347163945, 10.1142902669032, 6.06249165375458, 4.74850565714552, 
17.9833699614403, 67.2065822391264, 17.3347810074396, 16.5017818986004, 
23.7514924365845, 37.1851342775933, 21.5618045488646, 30.6788445864795, 
17.1035593022782, 8.42714630237048, 13.4006384220441, 22.1238974112126, 
4.48001569435593, 23.9658029257865, 6.23907173530781, 26.877146564602, 
15.3003261751959, 12.0485155125301, 4.32690092924821, 7.01214075444578, 
16.1791317461962, 13.0728785273578, 7.63109083309118, 16.9972980214674, 
8.30295245274037, 8.7770203067377, 5.67480760942735, 21.3961492360836, 
13.9550988566784, 11.0242554066141, 19.4382013687556, 8.62975825045164, 
11.4164507143039, 8.34586383704729, 3.72091720855698, 8.97296101792361, 
29.8903858240922, 2.32504604168462, 25.8164695705562, 22.061057520145, 
3.4803762605344, 48.3170810944539, 80.6701146444289, 15.0833362411301, 
10.8924796349525, 17.4918647333209, 12.6115824242011, 34.3062414327012, 
8.287617251304, 15.4831104293005, 15.1485432894085, 4.5184565189416, 
3.59999333029852, 3.66865483560892, 29.9677778375668, 34.4509226015574, 
32.5918276015502, 10.6060279795247, 19.7913453571932, 28.266459587366, 
19.6122992848655, 9.57523706552828, 9.04738999444933, 5.25824593606435, 
6.55473931337678, 18.7449471987719, 9.27943740426736, 9.54703445889029, 
3.43647048217306, 17.6920729261708, 25.3789409935332, 43.0995071399241, 
15.7776713016551, 5.96178566715426, 7.04629857379702, 40.3659823950032, 
20.3090509981183, 14.0833358445997, 16.9522805698219, 40.8824485009689, 
21.6424431028975, 11.0653580862889, 9.52636056796406, 13.2093186951614, 
11.180272835061, 28.7154955728657, NA, 8.29026375

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That plot doesn't look like a normal distribution at all to me. The distribution looks right-skewed. Anyway, that's not relevant:

d <- density(na.omit(a), n=1e4)
plot(d)
xmax <- d$x[d$y==max(d$y)]

x1 <- d$x[d$x < xmax][which.min(abs(d$y[d$x < xmax]-max(d$y)/2))]
x2 <- d$x[d$x > xmax][which.min(abs(d$y[d$x > xmax]-max(d$y)/2))]

points(c(x1, x2), c(d$y[d$x==x1], d$y[d$x==x2]), col="red")

enter image description here

FWHM <- x2-x1
#[1] 25.71115

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...