I have the same problem as the one posted by #soapsuds here. I did not want to ask a duplicate question but when I tried to edit the original question to provide the reproducible example that was missing in the original post my edits got rejected. Since the reproducible example has a lot of elements, I could not write it as a comment to the original question either, so I provide my code and my reproducible data here, as a separate question.
I am trying to compare two models using the likelihood ratio test. From bootstrapping I get a set of 1000 p-values. Here are the numbers I get:
chi2 <- c(41.83803376, 69.23970174, 42.5479637, 50.90208302, 39.18366824, 78.88589665, 28.88469406, 34.99980796, 85.80860848, 66.01750186, 29.06286, 46.43221576, 46.50523792, 59.87362884, 46.17274808, 77.97429928, 48.04404216, 12.88592623, 43.1883816, 33.24251471, 53.27310465, 56.92595147, 47.99838583, 46.0718587, 49.0760042, 29.70866297, 66.80696553, 66.61091741, 37.82375112, 50.19760846, 30.99961864, 27.17687828, 37.46944206, 66.36226432, 48.30737714, 43.64410333, 23.78480451, 42.52842793, 60.49309556, 46.29154, 26.96744296, 32.21561396, 48.20316788, 38.73153704, 67.80328765, 55.00664931, 36.74645735, 23.3647159, 56.35290442, 38.11055268, 58.3316501, 36.00500638, 41.36949956, 49.09067881, 64.42712507, 23.97787069, 54.5394799, 87.02114296, 26.01402166, 50.47426712, 38.58006084, 48.47626864, 22.28809699, 58.87590487, 17.59264288, 33.32650413, 67.77868338, 60.95427815, 37.19931376, 36.23280256, 53.54379697, 70.06479334, 41.3482703, 34.54099647, 55.99585144, 30.60500406, 32.02745276, 37.92670127, 44.23450124, 40.38607671, 44.02263294, 40.89874789, 62.74174279, 50.95137406, 47.12851204, 26.03848394, 36.6202765, 61.06296311, 50.17094183, 35.93242228, 41.8913277, 35.19089913, 38.88574534, 66.075866, 26.34296242, 49.99887059, 42.97123036, 34.89006324, 66.5460019, 67.61855859, 48.52166614, 41.41324193, 46.76294302, 14.87650733, 24.11661382, 62.28747719, 43.94865019, 44.20328393, 41.17756328, 43.74055584, 49.46236395, 38.59558107, 42.85073398, 49.81046036, 36.60331917, 39.85328124, 59.31376822, 61.36038822, 52.56707689, 29.19196892, 46.473958, 39.12904163, 38.75057931, 36.32493909, 49.61088785, 33.42904297, 34.73661836, 33.97736002, 37.44094284, 57.73605417, 43.14773064, 42.78707831, 26.84112684, 48.47832871, 45.94043053, 71.13563773, 46.28614795, 42.33386157, 59.31216832, 46.72946806, 47.76027545, 52.45174304, 49.99459367, 59.00971014, 24.03299408, 17.09453132, 37.44112252, 46.6352525, 60.42442286, 39.35194465, 46.57121135, 56.28622077, 59.20354176, 57.72511864, 41.97053375, 27.97077407, 29.70497125, 46.63976021, 40.24305901, 24.84335714, 36.08600444, 61.619572, 69.31377401, 86.91496878, 44.47955842, 44.1230351, 46.12514671, 43.97381958, 71.99269072, 47.01277643, 50.08167664, 27.01076954, 31.32586466, 40.96782215, 19.07024825, 53.00009679, 43.15397869, 42.49652848, 53.47325607, 43.45891027, 42.57719313, 39.40459925, 42.15077856, 52.23784844, 33.07947933, 45.02462309, 59.187763, 51.9198527, 48.3179841, 76.10501177, 34.95091433, 40.75545034, 31.27034043, 39.83209227, 47.87278051, 46.25057806, 62.84591205, 41.24656655, 68.14749236, 53.11576938, 39.20515676, 61.96116013, 35.64665684, 72.52689101, 54.64239536, 34.14169048, 34.32282338, 49.60786171, 50.32976034, 43.83560386, 57.49367366, 81.65759842, 61.59398941, 37.77960776, 30.74484476, 34.72859511, 32.46631033, 37.41725027, 34.04569722, 54.11932007, 34.62264522, 28.36753913, 30.95379445, 84.06354755, 29.32445434, 56.7720931, 33.23951864, 48.61860157, 39.3563214, 32.44713462, 61.25078174, 32.49661836, 40.38508488, 26.73565294, 58.16191656, 61.12461262, 23.701462, 22.14004554, 57.80213129, 57.15936762, 31.51238062, 44.60223083, 30.60135802, 46.96637333, 42.79517081, 56.85541543, 48.79421654, 29.72862307, 41.61735121, 43.37983393, 41.16802781, 61.69637392, 37.29991153, 39.0936012, 57.39158494, 57.55033901, 50.72878897, 34.82491685, 42.66486539, 34.54565803, 55.04161695, 44.56687339, 53.46745359, 57.22210412, 34.8578696, 28.81098073, 51.4033337, 51.9568532, 60.98717632, 62.98817996, 44.1335128, 33.38418814, 59.71059054, 45.82016411, 29.47178401, 30.64995791, 28.52106318, 53.98066153, 64.22209517, 58.29438562, 39.18280924, 38.1302144, 41.90062316, 28.68650929, 69.42769639, 33.79539164, 26.08549507, 55.29167497, 97.25975259, 63.07957724, 56.59002373, 51.40088678, 71.33491023, 46.24955174, 33.90101761, 38.0669817, 52.50993176, 51.84637529, 39.93642798, 61.9268346, 30.25561485, 49.57396856, 44.70170977, 57.00286149, 40.39009586, 63.23642634, 59.23643766, 55.80521902, 68.58421775, 24.04456631, 51.64338572, 61.14103174, 59.29371792, 46.51493959, 43.48297587, 39.99164284, 44.62589755, 58.89385062, 60.96824416, 54.02310453, 43.54420281, 44.24628098, 47.0991445, 58.9015349, 60.54157696, 34.86277089, 33.79969585, 34.57183642, 47.21383117, 55.3529805, 36.49813553, 44.94388291, 29.43134497, 43.41469037, 43.033338, 63.37329389, 38.22029171, 43.2894392, 23.42769168, 55.18117532, 19.39227876, 28.29656641, 28.56075122, 39.57260362, 65.48606054, 31.05339648, 24.87488959, 61.6027878, 59.56983406, 37.53918879, 28.67095839, 36.51499868, 44.43350204, 53.35842664, 48.30182354, 31.03494822, 45.68689659, 46.11113306, 53.89204524, 29.75548276, 35.60906482, 53.35195594, 56.28657675, 44.77245145, 60.20671942, 41.62253735, 40.34528594, 38.48551456, 27.39317425, 51.05414332, 38.41986986, 75.05074423, 34.16773046, 52.18497954, 49.63059496, 28.7365636, 10.59466471, 38.1033901, 52.20531405, 47.031987, 47.45955635, 44.64312012, 50.32229588, 62.40798968, 37.7455721, 31.97746406, 51.17250147, 45.91231295, 66.58450378, 32.68956686, 34.35845347, 70.34703042, 41.47493453, 53.67684859, 35.66735299, 19.76630329, 35.69026569, 76.57475236, 62.11269107, 37.06632602, 57.91686258, 33.95869501, 55.18034702, 66.09725866, 46.80608564, 46.75623531, 55.49605214, 45.7813294, 22.37612777, 62.40414132, 50.51745906, 46.86535062, 54.4172637, 35.44713601, 45.40918234, 43.83215257, 57.14754799, 24.20941074, 44.8145542, 50.79673435, 42.14561269, 32.73720673, 28.51047028, 32.14753623, 28.43006627, 39.50188334, 58.51806717, 37.96898151, 73.14656287, 48.23605238, 75.31273481, 29.57608972, 43.62952257, 30.47534709, 43.24927262, 43.61475563, 53.48883918, 53.85263136, 41.91477406, 56.16405384, 46.21202327, 55.52602904, 49.88481191, 46.31478116, 72.29722834, 40.48187205, 35.31368051, 40.57713079, 34.15725967, 65.85738596, 32.16093944, 32.07117679, 46.44579516, 53.3243447, 69.35531671, 21.70205174, 44.30678622, 40.13349937, 51.7431728, 43.03690121, 26.53566586, 18.74773427, 25.97768442, 66.68668827, 42.97352559, 31.61567696, 61.57362103, 55.07104736, 25.05950764, 53.04884067, 30.47176616, 43.33249885, 44.48360752, 40.59006165, 44.29759954, 69.71063388, 47.70186943, 51.12166943, 40.15048072, 44.96459746, 56.31842906, 57.79593771, 49.19795057, 33.58506451, 42.67650993, 47.96512915, 57.98722437, 42.08107371, 66.85903821, 45.30286487, 38.39187118, 48.02442004, 35.97047743, 56.71378254, 40.51082047, 43.78022461, 60.33208664, 35.78159098, 40.98937317, 36.20547787, 45.2382906, 47.81497885, 20.44519563, 16.68817267, 38.31035896, 38.60590267, 70.75756511, 31.73001452, 45.85476281, 47.11473565, 31.40248172, 42.94971714, 39.34376633, 21.09018956, 31.45915941, 53.82696054, 73.59824534, 31.5694168, 39.02189966, 46.91790827, 60.66603832, 59.81148782, 20.46813743, 54.95108785, 66.71844123, 49.48461319, 25.10459028, 60.26169536, 21.90344297, 63.56310687, 38.70295559, 58.19794152, 25.68981924, 61.4804908, 41.97067608, 22.77156359, 48.51789441, 50.31845297, 42.36456456, 43.35814281, 41.32891651, 35.17106573, 48.45296117, 30.55292595, 55.26758567, 71.25929921, 34.62580089, 43.89804598, 46.06384675, 30.74209253, 47.99143497, 34.02715801, 37.95367551, 45.14366438, 40.73655716, 45.32116105, 48.17651965, 63.54774876, 16.32237452, 54.22730144, 46.02331286, 45.44633826, 53.56976595, 53.96781286, 19.79116777, 42.05820938, 45.48852278, 37.34932167, 45.134461, 49.60637239, 29.99017683, 35.2785614, 71.54855053, 61.55744768, 55.7627296, 37.72455372, 62.51288842, 48.17063649, 65.26648616, 48.4831201, 33.49833137, 32.10986243, 15.42586026, 41.95660905, 30.07072484, 42.33604863, 53.20660203, 48.27036556, 32.92677161, 33.59521848, 44.04333058, 59.30038922, 48.84064622, 63.31815488, 36.01169023, 44.42967033, 23.14247159, 53.6314237, 42.43225997, 28.18151375, 44.0733306, 55.93530003, 30.86515779, 34.10702034, 59.38495522, 57.79906004, 64.86160093, 56.70670687, 43.24880707, 40.00049219, 44.08430336, 17.50391283, 72.81320114, 41.55481964, 63.461066, 50.81938548, 58.7427594, 35.27822458, 33.5188344, 46.13196979, 56.94022883, 66.96258461, 39.19601268, 21.95750575, 51.67252792, 46.51047909, 30.42289547, 46.47496475, 41.6440483, 42.36900563, 68.29398345, 30.14059255, 38.90124252, 40.87014585, 51.33635945, 51.72908337, 50.8177621, 31.65411733, 56.75197699, 47.76885318, 34.18305356, 52.52137441, 48.39806899, 18.34609209, 32.5461584, 60.15104883, 36.29250847, 39.02418361, 34.68801402, 48.02453889, 31.36738248, 42.44522981, 71.79176852, 34.25588794, 38.46866138, 45.01393624, 63.38509325, 32.44823195, 64.59346474, 53.80793998, 41.2889141, 28.86534461, 34.85039051, 37.04622686, 31.83207726, 36.65410743, 27.66293315, 23.11203257, 41.61059067, 19.97321534, 59.879676, 39.84187157, 47.324581, 38.24903991, 41.0234849, 62.30809429, 48.47191326, 23.26696808, 29.91547934, 78.39181209, 41.86240014, 33.53717515, 39.63756903, 74.86377649, 56.30173648, 40.29403413, 59.12602764, 47.23561802, 51.32370456, 45.44426051, 55.54666292, 58.85362888, 38.30516953, 46.11300177, 37.96931091, 41.01315149, 63.09345867, 26.74145771, 31.37447907, 39.26896396, 65.35880308, 60.0670218, 45.48057201, 29.76683425, 51.39638136, 46.12180705, 60.72093818, 45.01613513, 37.04611291, 31.32979098, 57.82548455, 29.89919764, 38.77980495, 55.71511912, 66.9872235, 48.74616069, 32.87503301, 56.10335632, 28.72445387, 41.00675821, 55.22238115, 38.56391412, 21.82487917, 51.87394855, 41.62740713, 72.32943223, 49.85456187, 41.76869194, 55.686196, 46.18471338, 52.57455653, 23.03383172, 51.460223, 45.88045256, 47.91709836, 53.09464847, 65.17159616, 48.0076358, 42.50038253, 50.57143193, 22.05776575, 25.5770314, 57.41889173, 37.07408252, 69.83286794, 53.31690771, 36.14562381, 35.3626014, 70.74448842, 30.01870438, 41.95755074, 64.41141845, 48.12704663, 29.33183678, 47.45391445, 35.76760392, 17.57864013, 42.66918162, 27.84884911, 37.83419437, 56.38203205, 32.93395446, 19.45549279, 48.49557175, 63.74692618, 48.36501421, 38.45370018, 63.77499738, 43.40984685, 61.28735474, 47.00513455, 31.82012086, 40.85624032, 32.79590137, 43.79441893, 47.93350586, 26.44410209, 22.71480768, 41.74097624, 29.7828174, 35.24077319, 37.1436077, 63.62150539, 35.27952907, 30.9258966, 35.22384343, 45.0069715, 47.38652625, 60.86474384, 53.19528479, 37.61239521, 64.78497877, 39.50008676, 43.11733875, 34.67761458, 55.21401193, 57.22836509, 30.10411603, 30.03903287, 53.62027996, 40.63516283, 50.229386, 39.59707517, 55.53993024, 62.31160356, 48.65142538, 59.51279601, 51.46268896, 36.70086545, 45.73324953, 39.82026282, 51.51657943, 39.9507342, 26.65847555, 18.11032673, 41.57393548, 37.24804734, 59.78878572, 42.18870686, 57.73556775, 29.83442692, 24.27687775, 44.54663257, 48.40426261, 34.13830576, 64.47843419, 53.82888778, 45.77073351, 41.95910655, 56.25654343, 42.44938602, 18.92651056, 62.89841562, 42.28210051, 60.01632343, 56.38799965, 53.56842386, 71.059581, 59.21196097, 72.29678294, 40.0820475, 74.53163756, 46.35508897, 48.65592196, 36.69711286, 54.84914739, 57.62299813, 63.0750109, 25.53592874, 19.43203054, 63.18532427, 54.79806194, 28.75123602, 47.68037559, 36.06887062, 48.53619627, 42.05208952, 14.47366507, 26.25183654, 57.37741978, 24.92962789, 47.85306044, 35.55674275, 43.62606531, 51.98445971, 57.10441923, 45.20539557, 43.22417529, 48.20941756, 37.12416781, 39.54238987, 45.31000358, 24.59001204, 32.61256929, 31.61553515, 55.76617515, 57.82479513, 34.12465645, 52.1634834, 50.140277, 34.5334757, 70.76112738, 47.22161503, 35.44101995, 54.50312705, 47.74706989, 21.04494842, 42.42698916, 57.8551517, 49.67127478, 67.6702045, 30.64335682, 31.87819093, 45.79096976, 42.72129981, 56.22043416, 22.12571532, 31.93377902, 31.9561172, 60.28281847, 37.49005649, 30.63141229, 22.82707918, 29.55804713, 55.79929136, 39.64043613, 31.79538118, 61.92391469, 19.30462724, 37.00041938, 61.26446455, 47.10048686, 34.70929308, 33.34157984, 49.28331646, 39.9565451, 48.80158593, 29.25279435, 49.96980394, 68.7766356, 49.61949286, 18.80600378, 52.93721773, 24.29791779, 67.69568275, 54.22725318, 35.67531845, 58.05037476, 70.54029077, 55.59508174, 42.07974012, 61.62117032, 44.47174079, 40.13197612, 61.19863058, 35.16748823, 54.79320966, 46.40640448, 41.99222891, 53.33216862, 19.04146695, 29.60278169, 38.43089591, 61.22497978, 32.04678119, 30.77915985, 38.02625789, 74.25140223, 30.44626923, 42.69951906, 28.99988779, 49.76041564, 30.86941271, 58.65788956, 62.64967161, 23.5689175, 42.21941421, 54.88455829, 38.10115824, 24.12341961, 32.84464782, 81.72102673, 42.42771851, 37.75191241, 32.05927543, 43.55812503, 64.79161154, 61.05179286, 53.24693267, 36.29056269, 61.49030629, 53.68500702, 65.93501988, 50.7243041, 51.72139759, 64.80610623, 58.2860023, 33.16444766, 42.7872046, 55.14190562, 39.14341079, 36.05577261, 30.03351742, 24.16526837, 47.94163599, 52.55045103, 56.60625705, 61.6878126, 23.13212844, 50.50369148, 47.79873905, 47.01238239, 35.9159739, 53.18067189, 48.42928497, 67.48879213, 37.37609292, 19.7749038, 47.87115046, 48.90378974)
p.values <- c(9.92E-11, 8.72E-17, 6.90E-11, 9.71E-13, 3.86E-10, 6.58E-19, 7.68E-08, 3.30E-09, 1.98E-20, 4.47E-16, 7.01E-08, 9.48E-12, 9.14E-12, 1.01E-14, 1.08E-11, 1.04E-18, 4.17E-12, 0.000331062, 4.97E-11, 8.14E-09, 2.90E-13, 4.53E-14, 4.27E-12, 1.14E-11, 2.46E-12, 5.02E-08, 2.99E-16, 3.31E-16, 7.74E-10, 1.39E-12, 2.58E-08, 1.86E-07, 9.29E-10, 3.75E-16, 3.64E-12, 3.94E-11, 1.08E-06, 6.97E-11, 7.38E-15, 1.02E-11, 2.07E-07, 1.38E-08, 3.84E-12, 4.86E-10, 1.81E-16, 1.20E-13, 1.35E-09, 1.34E-06, 6.06E-14, 6.68E-10, 2.21E-14, 1.97E-09, 1.26E-10, 2.44E-12, 1.00E-15, 9.74E-07, 1.52E-13, 1.07E-20, 3.39E-07, 1.21E-12, 5.26E-10, 3.34E-12, 2.35E-06, 1.68E-14, 2.74E-05, 7.79E-09, 1.83E-16, 5.84E-15, 1.07E-09, 1.75E-09, 2.53E-13, 5.74E-17, 1.27E-10, 4.17E-09, 7.26E-14, 3.16E-08, 1.52E-08, 7.35E-10, 2.91E-11, 2.08E-10, 3.25E-11, 1.60E-10, 2.36E-15, 9.47E-13, 6.65E-12, 3.35E-07, 1.44E-09, 5.53E-15, 1.41E-12, 2.04E-09, 9.65E-11, 2.99E-09, 4.49E-10, 4.34E-16, 2.86E-07, 1.54E-12, 5.56E-11, 3.49E-09, 3.42E-16, 1.98E-16, 3.27E-12, 1.23E-10, 8.01E-12, 0.000114784, 9.07E-07, 2.97E-15, 3.37E-11, 2.96E-11, 1.39E-10, 3.75E-11, 2.02E-12, 5.21E-10, 5.91E-11, 1.69E-12, 1.45E-09, 2.74E-10, 1.34E-14, 4.75E-15, 4.16E-13, 6.56E-08, 9.28E-12, 3.97E-10, 4.82E-10, 1.67E-09, 1.87E-12, 7.39E-09, 3.77E-09, 5.58E-09, 9.42E-10, 3.00E-14, 5.08E-11, 6.10E-11, 2.21E-07, 3.34E-12, 1.22E-11, 3.33E-17, 1.02E-11, 7.69E-11, 1.35E-14, 8.15E-12, 4.82E-12, 4.41E-13, 1.54E-12, 1.57E-14, 9.47E-07, 3.56E-05, 9.42E-10, 8.55E-12, 7.65E-15, 3.54E-10, 8.83E-12, 6.27E-14, 1.42E-14, 3.01E-14, 9.27E-11, 1.23E-07, 5.03E-08, 8.53E-12, 2.24E-10, 6.22E-07, 1.89E-09, 4.17E-15, 8.40E-17, 1.13E-20, 2.57E-11, 3.08E-11, 1.11E-11, 3.33E-11, 2.16E-17, 7.05E-12, 1.47E-12, 2.02E-07, 2.18E-08, 1.55E-10, 1.26E-05, 3.34E-13, 5.06E-11, 7.08E-11, 2.62E-13, 4.33E-11, 6.79E-11, 3.44E-10, 8.45E-11, 4.92E-13, 8.85E-09, 1.95E-11, 1.43E-14, 5.78E-13, 3.62E-12, 2.69E-18, 3.38E-09, 1.73E-10, 2.24E-08, 2.77E-10, 4.55E-12, 1.04E-11, 2.24E-15, 1.34E-10, 1.52E-16, 3.14E-13, 3.82E-10, 3.50E-15, 2.37E-09, 1.65E-17, 1.45E-13, 5.12E-09, 4.67E-09, 1.88E-12, 1.30E-12, 3.57E-11, 3.39E-14, 1.62E-19, 4.22E-15, 7.92E-10, 2.94E-08, 3.79E-09, 1.21E-08, 9.54E-10, 5.38E-09, 1.89E-13, 4.00E-09, 1.00E-07, 2.64E-08, 4.79E-20, 6.12E-08, 4.89E-14, 8.15E-09, 3.11E-12, 3.53E-10, 1.22E-08, 5.02E-15, 1.19E-08, 2.09E-10, 2.33E-07, 2.41E-14, 5.36E-15, 1.12E-06, 2.53E-06, 2.90E-14, 4.02E-14, 1.98E-08, 2.41E-11, 3.17E-08, 7.22E-12, 6.08E-11, 4.69E-14, 2.84E-12, 4.97E-08, 1.11E-10, 4.51E-11, 1.40E-10, 4.01E-15, 1.01E-09, 4.04E-10, 3.57E-14, 3.29E-14, 1.06E-12, 3.61E-09, 6.50E-11, 4.16E-09, 1.18E-13, 2.46E-11, 2.63E-13, 3.89E-14, 3.55E-09, 7.98E-08, 7.52E-13, 5.67E-13, 5.74E-15, 2.08E-15, 3.07E-11, 7.56E-09, 1.10E-14, 1.30E-11, 5.67E-08, 3.09E-08, 9.27E-08, 2.02E-13, 1.11E-15, 2.26E-14, 3.86E-10, 6.62E-10, 9.60E-11, 8.51E-08, 7.93E-17, 6.12E-09, 3.27E-07, 1.04E-13, 6.08E-23, 1.99E-15, 5.37E-14, 7.53E-13, 3.01E-17, 1.04E-11, 5.80E-09, 6.84E-10, 4.28E-13, 6.00E-13, 2.62E-10, 3.56E-15, 3.79E-08, 1.91E-12, 2.29E-11, 4.35E-14, 2.08E-10, 1.83E-15, 1.40E-14, 8.00E-14, 1.22E-16, 9.41E-07, 6.66E-13, 5.31E-15, 1.36E-14, 9.09E-12, 4.28E-11, 2.55E-10, 2.39E-11, 1.66E-14, 5.80E-15, 1.98E-13, 4.14E-11, 2.90E-11, 6.75E-12, 1.66E-14, 7.20E-15, 3.54E-09, 6.11E-09, 4.11E-09, 6.36E-12, 1.01E-13, 1.53E-09, 2.03E-11, 5.79E-08, 4.43E-11, 5.38E-11, 1.71E-15, 6.32E-10, 4.72E-11, 1.30E-06, 1.10E-13, 1.06E-05, 1.04E-07, 9.08E-08, 3.16E-10, 5.85E-16, 2.51E-08, 6.12E-07, 4.20E-15, 1.18E-14, 8.96E-10, 8.58E-08, 1.51E-09, 2.63E-11, 2.78E-13, 3.65E-12, 2.53E-08, 1.39E-11, 1.12E-11, 2.12E-13, 4.90E-08, 2.41E-09, 2.79E-13, 6.26E-14, 2.21E-11, 8.54E-15, 1.11E-10, 2.13E-10, 5.52E-10, 1.66E-07, 8.99E-13, 5.70E-10, 4.59E-18, 5.06E-09, 5.05E-13, 1.86E-12, 8.29E-08, 0.001134145, 6.71E-10, 5.00E-13, 6.98E-12, 5.62E-12, 2.36E-11, 1.30E-12, 2.79E-15, 8.06E-10, 1.56E-08, 8.46E-13, 1.24E-11, 3.35E-16, 1.08E-08, 4.58E-09, 4.97E-17, 1.19E-10, 2.36E-13, 2.34E-09, 8.75E-06, 2.31E-09, 2.12E-18, 3.24E-15, 1.14E-09, 2.73E-14, 5.63E-09, 1.10E-13, 4.29E-16, 7.84E-12, 8.04E-12, 9.36E-14, 1.32E-11, 2.24E-06, 2.80E-15, 1.18E-12, 7.60E-12, 1.62E-13, 2.62E-09, 1.60E-11, 3.58E-11, 4.04E-14, 8.64E-07, 2.17E-11, 1.02E-12, 8.47E-11, 1.05E-08, 9.32E-08, 1.43E-08, 9.71E-08, 3.28E-10, 2.01E-14, 7.19E-10, 1.20E-17, 3.78E-12, 4.02E-18, 5.38E-08, 3.97E-11, 3.38E-08, 4.82E-11, 4.00E-11, 2.60E-13, 2.16E-13, 9.53E-11, 6.67E-14, 1.06E-11, 9.22E-14, 1.63E-12, 1.01E-11, 1.85E-17, 1.98E-10, 2.81E-09, 1.89E-10, 5.08E-09, 4.85E-16, 1.42E-08, 1.49E-08, 9.42E-12, 2.83E-13, 8.22E-17, 3.18E-06, 2.81E-11, 2.37E-10, 6.33E-13, 5.37E-11, 2.59E-07, 1.49E-05, 3.45E-07, 3.18E-16, 5.55E-11, 1.88E-08, 4.26E-15, 1.16E-13, 5.56E-07, 3.25E-13, 3.39E-08, 4.62E-11, 2.56E-11, 1.88E-10, 2.82E-11, 6.87E-17, 4.96E-12, 8.68E-13, 2.35E-10, 2.01E-11, 6.16E-14, 2.91E-14, 2.31E-12, 6.82E-09, 6.46E-11, 4.34E-12, 2.64E-14, 8.76E-11, 2.92E-16, 1.69E-11, 5.79E-10, 4.21E-12, 2.00E-09, 5.04E-14, 1.96E-10, 3.67E-11, 8.01E-15, 2.21E-09, 1.53E-10, 1.78E-09, 1.74E-11, 4.68E-12, 6.14E-06, 4.41E-05, 6.03E-10, 5.19E-10, 4.04E-17, 1.77E-08, 1.27E-11, 6.70E-12, 2.10E-08, 5.62E-11, 3.55E-10, 4.38E-06, 2.04E-08, 2.19E-13, 9.57E-18, 1.92E-08, 4.19E-10, 7.40E-12, 6.76E-15, 1.04E-14, 6.06E-06, 1.24E-13, 3.13E-16, 2.00E-12, 5.43E-07, 8.30E-15, 2.87E-06, 1.55E-15, 4.93E-10, 2.37E-14, 4.01E-07, 4.47E-15, 9.27E-11, 1.82E-06, 3.27E-12, 1.31E-12, 7.58E-11, 4.56E-11, 1.29E-10, 3.02E-09, 3.38E-12, 3.25E-08, 1.05E-13, 3.13E-17, 4.00E-09, 3.46E-11, 1.14E-11, 2.95E-08, 4.28E-12, 5.43E-09, 7.24E-10, 1.83E-11, 1.74E-10, 1.67E-11, 3.90E-12, 1.57E-15, 5.34E-05, 1.79E-13, 1.17E-11, 1.57E-11, 2.50E-13, 2.04E-13, 8.64E-06, 8.86E-11, 1.54E-11, 9.88E-10, 1.84E-11, 1.88E-12, 4.34E-08, 2.86E-09, 2.71E-17, 4.30E-15, 8.18E-14, 8.15E-10, 2.65E-15, 3.91E-12, 6.54E-16, 3.33E-12, 7.13E-09, 1.46E-08, 8.58E-05, 9.33E-11, 4.17E-08, 7.69E-11, 3.00E-13, 3.71E-12, 9.57E-09, 6.79E-09, 3.21E-11, 1.35E-14, 2.78E-12, 1.76E-15, 1.96E-09, 2.64E-11, 1.50E-06, 2.42E-13, 7.32E-11, 1.10E-07, 3.16E-11, 7.49E-14, 2.77E-08, 5.22E-09, 1.30E-14, 2.90E-14, 8.03E-16, 5.06E-14, 4.82E-11, 2.54E-10, 3.15E-11, 2.87E-05, 1.43E-17, 1.15E-10, 1.64E-15, 1.01E-12, 1.80E-14, 2.86E-09, 7.06E-09, 1.11E-11, 4.49E-14, 2.77E-16, 3.83E-10, 2.79E-06, 6.56E-13, 9.11E-12, 3.47E-08, 9.28E-12, 1.09E-10, 7.56E-11, 1.41E-16, 4.02E-08, 4.46E-10, 1.63E-10, 7.78E-13, 6.37E-13, 1.01E-12, 1.84E-08, 4.94E-14, 4.80E-12, 5.02E-09, 4.26E-13, 3.48E-12, 1.84E-05, 1.16E-08, 8.79E-15, 1.70E-09, 4.19E-10, 3.87E-09, 4.21E-12, 2.14E-08, 7.27E-11, 2.39E-17, 4.83E-09, 5.56E-10, 1.96E-11, 1.70E-15, 1.22E-08, 9.21E-16, 2.21E-13, 1.31E-10, 7.76E-08, 3.56E-09, 1.15E-09, 1.68E-08, 1.41E-09, 1.44E-07, 1.53E-06, 1.11E-10, 7.85E-06, 1.01E-14, 2.75E-10, 6.02E-12, 6.23E-10, 1.50E-10, 2.94E-15, 3.35E-12, 1.41E-06, 4.51E-08, 8.45E-19, 9.79E-11, 6.99E-09, 3.06E-10, 5.04E-18, 6.22E-14, 2.18E-10, 1.48E-14, 6.29E-12, 7.83E-13, 1.57E-11, 9.13E-14, 1.70E-14, 6.05E-10, 1.12E-11, 7.19E-10, 1.51E-10, 1.97E-15, 2.33E-07, 2.13E-08, 3.69E-10, 6.24E-16, 9.17E-15, 1.54E-11, 4.87E-08, 7.55E-13, 1.11E-11, 6.58E-15, 1.95E-11, 1.15E-09, 2.18E-08, 2.86E-14, 4.55E-08, 4.74E-10, 8.38E-14, 2.73E-16, 2.91E-12, 9.83E-09, 6.88E-14, 8.34E-08, 1.52E-10, 1.08E-13, 5.30E-10, 2.99E-06, 5.92E-13, 1.10E-10, 1.82E-17, 1.66E-12, 1.03E-10, 8.50E-14, 1.08E-11, 4.14E-13, 1.59E-06, 7.31E-13, 1.26E-11, 4.45E-12, 3.18E-13, 6.87E-16, 4.25E-12, 7.07E-11, 1.15E-12, 2.65E-06, 4.25E-07, 3.52E-14, 1.14E-09, 6.45E-17, 2.84E-13, 1.83E-09, 2.74E-09, 4.07E-17, 4.28E-08, 9.33E-11, 1.01E-15, 3.99E-12, 6.10E-08, 5.63E-12, 2.22E-09, 2.76E-05, 6.48E-11, 1.31E-07, 7.70E-10, 5.97E-14, 9.53E-09, 1.03E-05, 3.31E-12, 1.41E-15, 3.54E-12, 5.61E-10, 1.39E-15, 4.44E-11, 4.93E-15, 7.08E-12, 1.69E-08, 1.64E-10, 1.02E-08, 3.65E-11, 4.41E-12, 2.71E-07, 1.88E-06, 1.04E-10, 4.83E-08, 2.91E-09, 1.10E-09, 1.51E-15, 2.86E-09, 2.68E-08, 2.94E-09, 1.96E-11, 5.83E-12, 6.11E-15, 3.02E-13, 8.63E-10, 8.35E-16, 3.28E-10, 5.16E-11, 3.89E-09, 1.08E-13, 3.88E-14, 4.09E-08, 4.23E-08, 2.43E-13, 1.83E-10, 1.37E-12, 3.12E-10, 9.16E-14, 2.93E-15, 3.06E-12, 1.22E-14, 7.30E-13, 1.38E-09, 1.36E-11, 2.78E-10, 7.10E-13, 2.60E-10, 2.43E-07, 2.08E-05, 1.13E-10, 1.04E-09, 1.06E-14, 8.29E-11, 3.00E-14, 4.71E-08, 8.34E-07, 2.48E-11, 3.47E-12, 5.13E-09, 9.76E-16, 2.19E-13, 1.33E-11, 9.32E-11, 6.36E-14, 7.25E-11, 1.36E-05, 2.18E-15, 7.90E-11, 9.41E-15, 5.95E-14, 2.50E-13, 3.47E-17, 1.42E-14, 1.85E-17, 2.44E-10, 5.97E-18, 9.87E-12, 3.05E-12, 1.38E-09, 1.30E-13, 3.17E-14, 1.99E-15, 4.34E-07, 1.04E-05, 1.88E-15, 1.34E-13, 8.23E-08, 5.02E-12, 1.90E-09, 3.24E-12, 8.89E-11, 0.000142133, 3.00E-07, 3.60E-14, 5.95E-07, 4.59E-12, 2.48E-09, 3.98E-11, 5.59E-13, 4.13E-14, 1.77E-11, 4.88E-11, 3.83E-12, 1.11E-09, 3.21E-10, 1.68E-11, 7.09E-07, 1.12E-08, 1.88E-08, 8.16E-14, 2.87E-14, 5.17E-09, 5.11E-13, 1.43E-12, 4.19E-09, 4.03E-17, 6.34E-12, 2.63E-09, 1.55E-13, 4.85E-12, 4.49E-06, 7.34E-11, 2.82E-14, 1.82E-12, 1.93E-16, 3.10E-08, 1.64E-08, 1.32E-11, 6.31E-11, 6.48E-14, 2.55E-06, 1.60E-08, 1.58E-08, 8.22E-15, 9.19E-10, 3.12E-08, 1.77E-06, 5.43E-08, 8.03E-14, 3.05E-10, 1.71E-08, 3.57E-15, 1.11E-05, 1.18E-09, 4.99E-15, 6.74E-12, 3.83E-09, 7.73E-09, 2.22E-12, 2.60E-10, 2.83E-12, 6.35E-08, 1.56E-12, 1.10E-16, 1.87E-12, 1.45E-05, 3.44E-13, 8.25E-07, 1.91E-16, 1.79E-13, 2.33E-09, 2.55E-14, 4.51E-17, 8.90E-14, 8.76E-11, 4.16E-15, 2.58E-11, 2.37E-10, 5.16E-15, 3.03E-09, 1.34E-13, 9.61E-12, 9.16E-11, 2.82E-13, 1.28E-05, 5.30E-08, 5.67E-10, 5.09E-15, 1.51E-08, 2.89E-08, 6.98E-10, 6.88E-18, 3.43E-08, 6.38E-11, 7.24E-08, 1.74E-12, 2.76E-08, 1.88E-14, 2.47E-15, 1.21E-06, 8.16E-11, 1.28E-13, 6.72E-10, 9.04E-07, 9.98E-09, 1.57E-19, 7.33E-11, 8.03E-10, 1.50E-08, 4.12E-11, 8.33E-16, 5.56E-15, 2.94E-13, 1.70E-09, 4.45E-15, 2.35E-13, 4.66E-16, 1.06E-12, 6.40E-13, 8.26E-16, 2.27E-14, 8.47E-09, 6.10E-11, 1.12E-13, 3.94E-10, 1.92E-09, 4.25E-08, 8.84E-07, 4.39E-12, 4.19E-13, 5.32E-14, 4.02E-15, 1.51E-06, 1.19E-12, 4.72E-12, 7.05E-12, 2.06E-09, 3.04E-13, 3.42E-12, 2.12E-16, 9.74E-10, 8.71E-06, 4.55E-12, 2.69E-12)
While p-values range from 6.08038E-23 to 0.001134145, the bootstrapped p-value I get is 0.4995005 and I don't understand why. I am using the following function to find the bootstrapped p-value:
(1+sum(logit.boot$t[,2] > logit.boot$t0[2]))/(1+logit.boot$R)
where logit.boot$t[,2] takes on values from the p.values vector, logit.boot$t0[2] equals 2.664684e-11 and logit.boot$R = 1000.
EDIT
Here is the code I used for bootstrapping:
logit.bootstrap <- function(data, indices){
d <- data[indices, ]
Mf1 <- glm(Y ~ A + B + C, data = d, family = "binomial")
data.setM1 <- na.omit(d[, all.vars(formula(Mf1))])
M1.io <- glm(Y ~ A + B, data = data.setM1, family = "binomial")
my.test <- lrtest(Mf1, M1.io)
return(c(my.test$"Chisq"[2], my.test$"Pr(>Chisq)"[2]))
}
logit.boot <- boot(data=my.data, statistic=logit.bootstrap, R=1000) # 10'000 samples
In the result of the boot function, t0 should the p value on the original data, and t is some p values which are generated from random resampling/permutation on the original data.
And in your case, you shouldn't use
(1+sum(logit.boot$t[,2] > logit.boot$t0[2]))/(1+logit.boot$R)
to get information from your bootstrapped p values, you may use
quantile(logit.boot$t[,2], c(0.025,0.975))
or something like this to obtain a bootstrapped 95% confidence interval on your p value. This is not very meaningful, since the meaning of p value is already a probability (confidence level), why do you bother to obtain a confidence interval for p value? And the validness of the bootstrap method relies on the correctness of your parametric model. So if you want to use non-parametric approach toward this problem, I think you need to find some other approaches instead of this one.
This is my matrix
func=structure(c(-14.7690673280818, -14.5543581356252, -12.1406211639974,
-10.7200919648493, -9.55507848352318, -9.20790894914246, -8.74647670464071,
-8.26548763467919, -7.3962484443768, -6.94590909664862, -6.63903257406218,
-6.40598087538929, -6.09621085755895, -5.88245015332806, -5.69615454359131,
-5.4543516801245, -5.24485270997044, -5.05729667581875, -4.7660441793448,
-4.39683466679171, -4.30668996362841, -4.0828498417172, -3.95528199743041,
-3.81741171570944, -3.66175435590196, -3.56271256245504, -3.49609868983868,
-3.37586125647396, -3.0034966287813, -2.90517151506904, -2.72993249556762,
-2.66092057836039, -2.4408738658527, -2.36547969703899, -2.09546783234301,
-1.95526398213212, -1.88470374007828, -1.72750243012653, -1.60575660667247,
-1.43542615745848, -1.29362975715702, -1.18449733575892, -0.98947894198681,
-0.853386354928181, -0.63296867063245, -0.527486151545778, -0.361277864998242,
-0.257665212366851, -0.109270291541468, 0, 0.109270291541468,
0.257665212366851, 0.361277864998242, 0.527486151545778, 0.63296867063245,
0.853386354928181, 0.98947894198681, 1.18449733575892, 1.29362975715702,
1.43542615745848, 1.60575660667247, 1.72750243012653, 1.88470374007828,
1.95526398213212, 2.09546783234301, 2.36547969703899, 2.4408738658527,
2.66092057836039, 2.72993249556762, 2.90517151506904, 3.0034966287813,
3.37586125647396, 3.49609868983868, 3.56271256245504, 3.66175435590196,
3.81741171570944, 3.95528199743041, 4.0828498417172, 4.30668996362841,
4.39683466679171, 4.7660441793448, 5.05729667581875, 5.24485270997044,
5.4543516801245, 5.69615454359131, 5.88245015332806, 6.09621085755895,
6.40598087538929, 6.63903257406218, 6.94590909664862, 7.3962484443768,
8.26548763467919, 8.74647670464071, 9.20790894914246, 9.55507848352318,
10.7200919648493, 12.1406211639974, 14.5543581356252, 14.7690673280818,
-13.7079821475458, -13.4498703618915, -11.67838231268, -10.4589486406842,
-8.9432388382521, -8.58312548137122, -8.14102991846389, -7.71079209128989,
-6.95240042017031, -6.66414427349685, -6.40033205538623, -6.13816822549321,
-5.77208382991545, -5.49527630669887, -5.33154964830415, -5.12782641892739,
-4.93206161073643, -4.72556232300793, -4.52080276980657, -4.1694078333758,
-4.03956026669583, -3.90869860153294, -3.79104380757601, -3.69124767313376,
-3.47159857371935, -3.3643163654408, -3.29467696235366, -3.16605701449292,
-2.84435464789616, -2.71650210221017, -2.59690597248341, -2.52388797476942,
-2.34094207608544, -2.20427426100811, -1.83879580218285, -1.72737794398069,
-1.6454056454373, -1.5042411957216, -1.38609220687676, -1.2432788707001,
-1.1225617148797, -1.01318771357089, -0.90038209504245, -0.773284479514442,
-0.640368323748707, -0.555178375238413, -0.377358821158776, -0.230347860323025,
-0.110436162251717, 0, 0.110436162251717, 0.230347860323025,
0.377358821158776, 0.555178375238413, 0.640368323748707, 0.773284479514442,
0.90038209504245, 1.01318771357089, 1.1225617148797, 1.2432788707001,
1.38609220687676, 1.5042411957216, 1.6454056454373, 1.72737794398069,
1.83879580218285, 2.20427426100811, 2.34094207608544, 2.52388797476942,
2.59690597248341, 2.71650210221017, 2.84435464789616, 3.16605701449292,
3.29467696235366, 3.3643163654408, 3.47159857371935, 3.69124767313376,
3.79104380757601, 3.90869860153294, 4.03956026669583, 4.1694078333758,
4.52080276980657, 4.72556232300793, 4.93206161073643, 5.12782641892739,
5.33154964830415, 5.49527630669887, 5.77208382991545, 6.13816822549321,
6.40033205538623, 6.66414427349685, 6.95240042017031, 7.71079209128989,
8.14102991846389, 8.58312548137122, 8.9432388382521, 10.4589486406842,
11.67838231268, 13.4498703618915, 13.7079821475458, -14.358609077878,
-14.1271105147046, -11.9618138886078, -10.6190742201334, -9.31840132054895,
-8.96622474353695, -8.51227248333579, -8.05091545299969, -7.22455526958365,
-6.83691436333096, -6.54669635165921, -6.30238324376159, -5.97082920578328,
-5.73268017960003, -5.55511488901834, -5.32804232266972, -5.12385612117062,
-4.92897229198519, -4.67117775232928, -4.30885942992513, -4.20335651783943,
-4.0154831357938, -3.89174994433905, -3.76860783727992, -3.58819663306074,
-3.48596721027473, -3.41818297549918, -3.29470294456033, -2.94193593581688,
-2.83218876260999, -2.67847401240583, -2.60791242809822, -2.40221737689215,
-2.3031208003073, -1.99617971268181, -1.86711111167336, -1.79213635811389,
-1.64113856670334, -1.52078410227216, -1.36109806339877, -1.22745572081485,
-1.11822984936273, -0.955013720375685, -0.822400646878094, -0.635831069171161,
-0.538198299721656, -0.367498441110635, -0.24709807532094, -0.109721283846771,
0, 0.109721283846771, 0.24709807532094, 0.367498441110635, 0.538198299721656,
0.635831069171161, 0.822400646878094, 0.955013720375685, 1.11822984936273,
1.22745572081485, 1.36109806339877, 1.52078410227216, 1.64113856670334,
1.79213635811389, 1.86711111167336, 1.99617971268181, 2.3031208003073,
2.40221737689215, 2.60791242809822, 2.67847401240583, 2.83218876260999,
2.94193593581688, 3.29470294456033, 3.41818297549918, 3.48596721027473,
3.58819663306074, 3.76860783727992, 3.89174994433905, 4.0154831357938,
4.20335651783943, 4.30885942992513, 4.67117775232928, 4.92897229198519,
5.12385612117062, 5.32804232266972, 5.55511488901834, 5.73268017960003,
5.97082920578328, 6.30238324376159, 6.54669635165921, 6.83691436333096,
7.22455526958365, 8.05091545299969, 8.51227248333579, 8.96622474353695,
9.31840132054895, 10.6190742201334, 11.9618138886078, 14.1271105147046,
14.358609077878, -14.5672256639001, -14.3442603466748, -12.0526932005212,
-10.6704167793823, -9.43869316924387, -9.08906143604798, -8.63130745231583,
-8.15997238138419, -7.31181881941087, -6.89231124997616, -6.59362650222709,
-6.3550370379524, -6.03455479085867, -5.80880119944129, -5.62679869904323,
-5.39223941682433, -5.1853529853784, -4.99419352909143, -4.7193938866676,
-4.35357309705323, -4.255876038818, -4.04972245780601, -3.92404029302206,
-3.79341254883719, -3.62558255722496, -3.52497325621722, -3.4577838613747,
-3.33595188997765, -2.97322433504632, -2.86928245642403, -2.70462793445213,
-2.63485397290467, -2.42186464857093, -2.33481488889686, -2.04664318502277,
-1.91191506158551, -1.8391839961936, -1.68503324864501, -1.56397162198931,
-1.39887553095015, -1.26108886508264, -1.15191048988921, -0.972530768371285,
-0.838149222100249, -0.634376246882453, -0.532753819606308, -0.364336815412981,
-0.252468853112474, -0.109492065710681, 0, 0.109492065710681,
0.252468853112474, 0.364336815412981, 0.532753819606308, 0.634376246882453,
0.838149222100249, 0.972530768371285, 1.15191048988921, 1.26108886508264,
1.39887553095015, 1.56397162198931, 1.68503324864501, 1.8391839961936,
1.91191506158551, 2.04664318502277, 2.33481488889686, 2.42186464857093,
2.63485397290467, 2.70462793445213, 2.86928245642403, 2.97322433504632,
3.33595188997765, 3.4577838613747, 3.52497325621722, 3.62558255722496,
3.79341254883719, 3.92404029302206, 4.04972245780601, 4.255876038818,
4.35357309705323, 4.7193938866676, 4.99419352909143, 5.1853529853784,
5.39223941682433, 5.62679869904323, 5.80880119944129, 6.03455479085867,
6.3550370379524, 6.59362650222709, 6.89231124997616, 7.31181881941087,
8.15997238138419, 8.63130745231583, 9.08906143604798, 9.43869316924387,
10.6704167793823, 12.0526932005212, 14.3442603466748, 14.5672256639001,
-13.6245844768687, -13.3630613956461, -11.6420519179073, -10.4384236674326,
-8.89515033208928, -8.53401963497411, -8.0934438691888, -7.66719491633901,
-6.91751548158816, -6.64199852086489, -6.38157100998465, -6.11711906602055,
-5.74660855271358, -5.46484576488352, -5.30289294897202, -5.10216264876024,
-4.90747729878566, -4.69948913603343, -4.50152763272595, -4.15153286112639,
-4.01856478499323, -3.89501090892983, -3.77813524686729, -3.68133161034538,
-3.45665297878437, -3.34872310204811, -3.27884590260074, -3.14956711773407,
-2.83184663180451, -2.70167333082681, -2.5864505421683, -2.51311768021067,
-2.33308777876224, -2.19160406439047, -1.81862225736669, -1.70946687980764,
-1.6265976326061, -1.48669362532537, -1.36882733539455, -1.22817675030816,
-1.10911635110033, -0.999723362435733, -0.89337938721453, -0.766988745723311,
-0.640949911207503, -0.557354889428034, -0.37862272938278, -0.228200809764493,
-0.110527795707098, 0, 0.110527795707098, 0.228200809764493,
0.37862272938278, 0.557354889428034, 0.640949911207503, 0.766988745723311,
0.89337938721453, 0.999723362435733, 1.10911635110033, 1.22817675030816,
1.36882733539455, 1.48669362532537, 1.6265976326061, 1.70946687980764,
1.81862225736669, 2.19160406439047, 2.33308777876224, 2.51311768021067,
2.5864505421683, 2.70167333082681, 2.83184663180451, 3.14956711773407,
3.27884590260074, 3.34872310204811, 3.45665297878437, 3.68133161034538,
3.77813524686729, 3.89501090892983, 4.01856478499323, 4.15153286112639,
4.50152763272595, 4.69948913603343, 4.90747729878566, 5.10216264876024,
5.30289294897202, 5.46484576488352, 5.74660855271358, 6.11711906602055,
6.38157100998465, 6.64199852086489, 6.91751548158816, 7.66719491633901,
8.0934438691888, 8.53401963497411, 8.89515033208928, 10.4384236674326,
11.6420519179073, 13.3630613956461, 13.6245844768687, -13.7513240158161,
-13.4949850845108, -11.6972632618919, -10.4696154936035, -8.96823049188587,
-8.60864584793023, -8.16576044465774, -7.73344959477095, -6.97053016408726,
-6.67565344738059, -6.41008219291174, -6.14910749861269, -5.78532336166338,
-5.51109109533802, -5.34644256890291, -5.14116391069274, -4.94483810678764,
-4.73911258917317, -4.53082008138683, -4.17869747763421, -4.05047164341461,
-3.91581211159757, -3.79775240187192, -3.6964010627146, -3.47936581711638,
-3.37242020290272, -3.30290438286576, -3.17462683337767, -2.85085507867997,
-2.72420863226898, -2.60233967200701, -2.52948530961352, -2.34502396371101,
-2.21085897720345, -1.84928001732781, -1.73668634525457, -1.65518019199163,
-1.51336068884896, -1.39506478104353, -1.25112746056258, -1.1295492863675,
-1.02018515280999, -0.904021410598258, -0.776556379825624, -0.640066072057238,
-0.554047238235075, -0.376701966557133, -0.231463685042374, -0.110388540236378,
0, 0.110388540236378, 0.231463685042374, 0.376701966557133, 0.554047238235075,
0.640066072057238, 0.776556379825624, 0.904021410598258, 1.02018515280999,
1.1295492863675, 1.25112746056258, 1.39506478104353, 1.51336068884896,
1.65518019199163, 1.73668634525457, 1.84928001732781, 2.21085897720345,
2.34502396371101, 2.52948530961352, 2.60233967200701, 2.72420863226898,
2.85085507867997, 3.17462683337767, 3.30290438286576, 3.37242020290272,
3.47936581711638, 3.6964010627146, 3.79775240187192, 3.91581211159757,
4.05047164341461, 4.17869747763421, 4.53082008138683, 4.73911258917317,
4.94483810678764, 5.14116391069274, 5.34644256890291, 5.51109109533802,
5.78532336166338, 6.14910749861269, 6.41008219291174, 6.67565344738059,
6.97053016408726, 7.73344959477095, 8.16576044465774, 8.60864584793023,
8.96823049188587, 10.4696154936035, 11.6972632618919, 13.4949850845108,
13.7513240158161, -13.5038153563633, -13.2373523390222, -11.5894414578226,
-10.4087012189772, -8.82551281645418, -8.46290889731311, -8.02453396711809,
-7.60406134878737, -6.86699820314081, -6.6099290032563, -6.3544029256183,
-6.08663753750477, -5.70971751250438, -5.42077894932731, -5.26139485499848,
-5.06499864973269, -4.87187647554418, -4.66173225584577, -4.47361508632088,
-4.12564790942336, -3.98816098787005, -3.87518960476143, -3.75944221250401,
-3.66697204643782, -3.43501009186589, -3.32614231903036, -3.2559207639547,
-3.12568790968636, -2.81373363068119, -2.68019961742924, -2.57130991397796,
-2.49752109350884, -2.32171388099973, -2.17325620779303, -1.78940871644707,
-1.68352966297731, -1.59936153416788, -1.46128278798956, -1.34382587758861,
-1.20630719708568, -1.08964596607244, -0.980225481600834, -0.88323868593752,
-0.757871821632761, -0.641792114656659, -0.560506724513046, -0.380453009333927,
-0.225091641300559, -0.110660491161603, 0, 0.110660491161603,
0.225091641300559, 0.380453009333927, 0.560506724513046, 0.641792114656659,
0.757871821632761, 0.88323868593752, 0.980225481600834, 1.08964596607244,
1.20630719708568, 1.34382587758861, 1.46128278798956, 1.59936153416788,
1.68352966297731, 1.78940871644707, 2.17325620779303, 2.32171388099973,
2.49752109350884, 2.57130991397796, 2.68019961742924, 2.81373363068119,
3.12568790968636, 3.2559207639547, 3.32614231903036, 3.43501009186589,
3.66697204643782, 3.75944221250401, 3.87518960476143, 3.98816098787005,
4.12564790942336, 4.47361508632088, 4.66173225584577, 4.87187647554418,
5.06499864973269, 5.26139485499848, 5.42077894932731, 5.70971751250438,
6.08663753750477, 6.3544029256183, 6.6099290032563, 6.86699820314081,
7.60406134878737, 8.02453396711809, 8.46290889731311, 8.82551281645418,
10.4087012189772, 11.5894414578226, 13.2373523390222, 13.5038153563633,
-12.8877947524831, -12.5961340486959, -11.3210853809037, -10.2570925911286,
-8.47030492676585, -8.10018637873416, -7.67303749757961, -7.28202887686486,
-6.60931905266524, -6.44634841642492, -6.21582362929168, -5.93115698481963,
-5.5215432443443, -5.19600239869575, -5.04972087076752, -4.87543206990054,
-4.69028336184037, -4.46914150055587, -4.33123842894087, -3.99361363184664,
-3.833076928421, -3.77408485453713, -3.6640925546724, -3.59372660759739,
-3.32461379011727, -3.21096198541142, -3.13898393694403, -3.00388455382712,
-2.72134261347931, -2.57066623804085, -2.49408041291093, -2.41796583370138,
-2.26369776447253, -2.07966723692233, -1.64375650300888, -1.54786821816088,
-1.46043531083332, -1.33166687876378, -1.21629813646533, -1.09475471308712,
-0.990331188483095, -0.880770453063485, -0.831512873094893, -0.711368103958197,
-0.64608803628934, -0.576583643383317, -0.389788923647592, -0.219325408944189,
-0.101244293663156, 0, 0.101244293663156, 0.219325408944189,
0.389788923647592, 0.576583643383317, 0.64608803628934, 0.711368103958197,
0.831512873094893, 0.880770453063485, 0.990331188483095, 1.09475471308712,
1.21629813646533, 1.33166687876378, 1.46043531083332, 1.54786821816088,
1.64375650300888, 2.07966723692233, 2.26369776447253, 2.41796583370138,
2.49408041291093, 2.57066623804085, 2.72134261347931, 3.00388455382712,
3.13898393694403, 3.21096198541142, 3.32461379011727, 3.59372660759739,
3.6640925546724, 3.77408485453713, 3.833076928421, 3.99361363184664,
4.33123842894087, 4.46914150055587, 4.69028336184037, 4.87543206990054,
5.04972087076752, 5.19600239869575, 5.5215432443443, 5.93115698481963,
6.21582362929168, 6.44634841642492, 6.60931905266524, 7.28202887686486,
7.67303749757961, 8.10018637873416, 8.47030492676585, 10.2570925911286,
11.3210853809037, 12.5961340486959, 12.8877947524831, -12.6000848203634,
-12.2966556390103, -11.1957507602953, -10.1862843945321, -8.30440651819497,
-7.93147284818737, -7.50817793772083, -7.13162491301438, -6.48897104737938,
-6.36994876479492, -6.15110072929745, -5.85854042138457, -5.43365721329602,
-5.09102141962306, -4.95085939235108, -4.78689576531572, -4.60547103236952,
-4.37919276705198, -4.26474198682156, -3.93194755639431, -3.77843705689023,
-3.70907277842741, -3.61955988253518, -3.55951762156004, -3.27305364378077,
-3.15716747633446, -3.08436906473098, -2.94699678899349, -2.67819176248474,
-2.51950911610342, -2.45801068672049, -2.38080987129559, -2.23660157184075,
-2.03595688651075, -1.58836441712333, -1.47187389747016, -1.39555037998287,
-1.27113029247092, -1.15673682064109, -1.0426545765059, -0.943946623196274,
-0.835837575946843, -0.805837349555374, -0.689648730659341, -0.648094429117022,
-0.584092303333525, -0.394149224677363, -0.222824659020402, -0.0906541511144734,
0, 0.0906541511144734, 0.222824659020402, 0.394149224677363,
0.584092303333525, 0.648094429117022, 0.689648730659341, 0.805837349555374,
0.835837575946843, 0.943946623196274, 1.0426545765059, 1.15673682064109,
1.27113029247092, 1.39555037998287, 1.47187389747016, 1.58836441712333,
2.03595688651075, 2.23660157184075, 2.38080987129559, 2.45801068672049,
2.51950911610342, 2.67819176248474, 2.94699678899349, 3.08436906473098,
3.15716747633446, 3.27305364378077, 3.55951762156004, 3.61955988253518,
3.70907277842741, 3.77843705689023, 3.93194755639431, 4.26474198682156,
4.37919276705198, 4.60547103236952, 4.78689576531572, 4.95085939235108,
5.09102141962306, 5.43365721329602, 5.85854042138457, 6.15110072929745,
6.36994876479492, 6.48897104737938, 7.13162491301438, 7.50817793772083,
7.93147284818737, 8.30440651819497, 10.1862843945321, 11.1957507602953,
12.2966556390103, 12.6000848203634, -12.7233949898779, -12.425009683628,
-11.2494681735225, -10.2166322197219, -8.3755092456272, -8.00338523998922,
-7.57923229725886, -7.19608684570266, -6.5405512372713, -6.40269304276938,
-6.17884044516668, -5.8896632980985, -5.47132446137006, -5.13601542532135,
-4.9932306291456, -4.82484171541241, -4.64182091659811, -4.41774407285591,
-4.29324182862204, -3.95837714178017, -3.80090594237893, -3.73788575810611,
-3.6386462286676, -3.57417931862452, -3.29515190899568, -3.18022337150066,
-3.10777656095811, -2.97137842876953, -2.69668587115743, -2.54143464829308,
-2.47346988209172, -2.39673461879726, -2.24821478269518, -2.05469079214647,
-1.61210502089736, -1.50444445385474, -1.42335954097761, -1.29707578786137,
-1.18226432293022, -1.06498427720905, -0.963826675880699, -0.85422851115692,
-0.817708608597364, -0.698957479868998, -0.647234505242058, -0.580874151897233,
-0.392280434624987, -0.221324908501217, -0.0951930012794266,
0, 0.0951930012794266, 0.221324908501217, 0.392280434624987,
0.580874151897233, 0.647234505242058, 0.698957479868998, 0.817708608597364,
0.85422851115692, 0.963826675880699, 1.06498427720905, 1.18226432293022,
1.29707578786137, 1.42335954097761, 1.50444445385474, 1.61210502089736,
2.05469079214647, 2.24821478269518, 2.39673461879726, 2.47346988209172,
2.54143464829308, 2.69668587115743, 2.97137842876953, 3.10777656095811,
3.18022337150066, 3.29515190899568, 3.57417931862452, 3.6386462286676,
3.73788575810611, 3.80090594237893, 3.95837714178017, 4.29324182862204,
4.41774407285591, 4.64182091659811, 4.82484171541241, 4.9932306291456,
5.13601542532135, 5.47132446137006, 5.8896632980985, 6.17884044516668,
6.40269304276938, 6.5405512372713, 7.19608684570266, 7.57923229725886,
8.00338523998922, 8.3755092456272, 10.2166322197219, 11.2494681735225,
12.425009683628, 12.7233949898779, -12.9701665831908, -12.6818752140478,
-11.3569688906404, -10.2773650952434, -8.51780191626772, -8.14868819459235,
-7.72003821070641, -7.32508978114711, -6.64377488616525, -6.46822176338875,
-6.23435390289731, -5.95194722735932, -5.54670516078474, -5.22605862710606,
-5.07802507599128, -4.90078016073291, -4.71456527242172, -4.49489397213016,
-4.35027647059818, -4.01126873151645, -3.85381415345849, -3.78760418054142,
-3.67684233255883, -3.6035206970325, -3.33937554552141, -3.22636344257365,
-3.15462026543263, -3.02017161524238, -2.73369677368098, -2.58531260689116,
-2.50440723533775, -2.42860364735808, -2.27145544935968, -2.09218158273497,
-1.66032132882236, -1.56891953844307, -1.47901197414181, -1.34899860381407,
-1.23335063996306, -1.10967106859385, -1.00361116644947, -0.894069184830091,
-0.838429443534018, -0.717586396553344, -0.645513602695347, -0.574433901587114,
-0.388540562231589, -0.218323567844169, -0.104276269037671, 0,
0.104276269037671, 0.218323567844169, 0.388540562231589, 0.574433901587114,
0.645513602695347, 0.717586396553344, 0.838429443534018, 0.894069184830091,
1.00361116644947, 1.10967106859385, 1.23335063996306, 1.34899860381407,
1.47901197414181, 1.56891953844307, 1.66032132882236, 2.09218158273497,
2.27145544935968, 2.42860364735808, 2.50440723533775, 2.58531260689116,
2.73369677368098, 3.02017161524238, 3.15462026543263, 3.22636344257365,
3.33937554552141, 3.6035206970325, 3.67684233255883, 3.78760418054142,
3.85381415345849, 4.01126873151645, 4.35027647059818, 4.49489397213016,
4.71456527242172, 4.90078016073291, 5.07802507599128, 5.22605862710606,
5.54670516078474, 5.95194722735932, 6.23435390289731, 6.46822176338875,
6.64377488616525, 7.32508978114711, 7.72003821070641, 8.14868819459235,
8.51780191626772, 10.2773650952434, 11.3569688906404, 12.6818752140478,
12.9701665831908), .Dim = c(99L, 11L))
Each column is a function for me that I want to integrate, and put the values in my integr matrix:
integr=matrix(0,11)
for (t in 1:11){
integrating = approxfun(thau,func[,t],rule=2)
integr[t,1]=integrate(integrating, lower = 0.01, upper = 0.5,subdivisions = 1000)$value
}
I have this error message:
Error in integrate(integrating, lower = 0.01, upper = 0.5, subdivisions = 1000) :
extremely bad integrand behaviour
How do I get around this problem and continue to use the function integrate in R. Will I need to do some non-linear approach? If so, how can I do it?
Many thanks.
First, it is very interesting to see quite a few numerical integration question regarding quantile function in the last 10 days or so. For example:
Building a function by defining X and Y and then Integrating in R
Standard Normal Quantile Function Integration in R
Understanding and implementing numerical integration with a quantile function in R
Note how this question is similar to the first one. Although you did not mention what thau is, I believe it is thau <- seq(0.01, 0.99, 0.01). Let's have sketch your func matrix against thau:
matplot(thau, func, type = "l")
Also, let's verify that all columns of func are monotonically increasing:
all(diff(func) > 0)
# [1] TRUE
Basically, your question is using the answer I provided in the 1st linked question (the justification of rule = 2 is given in the 3rd linked question, though). But thanks to your question; I now realize there are some potential numerical flaw behind.
It is sophisticated for me to understand the mathematics behind Adaptive Quadrature in a limited time as I am not an expert in the field. But it is rather surprising to me that it would fail sometime on such a trivial task.
As I mentioned in the 2nd linked question, we can even use trapezoidal rule.
When I test integrate, it is the 1st column of func rather than the 5th as you reported that fails.
## get interpolation function for all columns in a list
flst <- lapply(1:ncol(func), function (i) approxfun(thau, func[,i], rule = 2))
## all OK excluding the 1st column
sapply(flst[-1], function (fun) integrate(fun, 0.01, 0.5)$value)
# [1] -2.010421 -2.088981 -2.114083 -2.000653 -2.015932 -1.986130 -1.912076
# [8] -1.877459 -1.892291 -1.921983
## the 1st one fails
integrate(flst[[1]], 0.01, 0.5)
# extremely bad integrand behaviour
As said earlier, I believe this failure artificial due to the problem's simple nature. In fact, let's consider
integrate(flst[[1]], 0.01 + .Machine$double.eps ^ 0.25, 0.5)
# -2.13653 with absolute error < 8.7e-05
integrate(flst[[1]], 0, 0.5)
# -2.286034 with absolute error < 0.00027
They all work.
As far as I can explore, the integrate function is using two Fortran subroutines:
dqags for definite integral, capable to deal with end-points singularity;
dqagi for indefinite integral.
R documentation for integrate does not explain much on the error handling of those routines, but the Fortran page does a little. Unfortunately, it is still not extremely clear what the "bad behaviour" is. But it is clear enough to see that regardless what error code is, those Fortran subroutines will always return integration result.
A look at the source code of integrate verifies this. Integration result is stored in variable wk, then a swtich statement is used to interpret the integer error code stored in wk$ierr:
res$message <- switch(wk$ierr + 1L, "OK", "maximum number of subdivisions reached",
"roundoff error was detected", "extremely bad integrand behaviour",
"roundoff error is detected in the extrapolation table",
"the integral is probably divergent", "the input is invalid")
if (wk$ierr == 6L || (wk$ierr > 0L && stop.on.error))
stop(res$message)
The if statement following this switch decides whether we want to ignore any error. Note there is an stop.on.error argument in integrate; if we set it FALSE instead of the default TRUE, integrate will always work. Therefore, let's do
z <- integrate(flst[[1]], 0.01, 0.5, stop.on.error = FALSE)
str(z)
# $ value : num -2.14
# $ abs.error : num 0.000446
# $ subdivisions: int 69
# $ message : chr "extremely bad integrand behaviour"
# $ call : language integrate(f = flst[[1]], lower = 0.01, upper = 0.5, stop.on.error = FALSE)
# - attr(*, "class")= chr "integrate"
z$value
# [1] -2.138348
This is all I can do at the moment. I believe there will be an opportunity for me to read around Adaptive Quadrature in the near future.