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.
Related
I'm using MATLAB's crosscorr function and R's ccf. For the same data, the results differ. It appears that the lag axis is flipped in one of them. Why is this happening?
I've reproduced the crosscorr documentation example in both platforms and this is what I see. Any help will be appreciated.
R Studio
MATLAB
The data for the example can be found here:
R data:
xx <- c(-0.649013765191241, 1.18116604196553, -0.758453297283692, -1.10961303850152, -0.845551240007797, -0.572664866457950, -0.558680764473972, 0.178380225849766, -0.196861446475943, 0.586442621667069, -0.851886969622469, 0.800320709801823, -1.50940472473439, 0.875874147834533, -0.242789536333340, 0.166813439453503, -1.96541870928278, -1.27007139263854, 1.17517126546302, 2.02916018474976, -0.275157240675694, 0.603658445825815, 1.78125189324250, 1.77365832632615, -1.86512257453063, -1.05110705924059, -0.417382047996795, 1.40216228633781, -1.36774699097611, -0.292534999151874, 1.27084843418894, 0.0660093412882059, 0.451290213630776, -0.322209718011896, 0.788409216227425, 0.928736046813314, -0.490790376269763, 1.79720058425494, 0.590696551205452, -0.635785737847226, 0.603346612845761, -0.535247967775900, -0.155080385492789, 0.612122370772160, -1.04434349451734, -0.345631908307050, -1.17140482049761, -0.685586780437283, 0.926216394168962, -1.48167521167231, -0.558057808685045, -0.0284531115706568, -1.47629235201010, 0.258899957160403, -2.01869095243834, 0.199740262298379, 0.425864319131210, -1.27004345059705, -0.485218835743043, 0.594307616829848, -0.276464906639256, -1.85758288592737, 0.0407308117494288, 0.282970177161990, 0.0635612193024994, 0.433430065111595, 0.422860364487685, 1.29952829655200, -1.04979323447507,-1.78641172211092,0.816043081031918, -0.328208543142512, -1.21456561358767,1.11183287253465, -0.507496954829846, 0.898730486034072, 0.377215659958544, 1.45239164558790, 0.446945073178942, 0.645824788453030, -0.623677409296163, -0.595236431548712, 1.61132368718055, -0.348998045314167, 0.164167484938754, -1.63657708517891, 0.581365555343623, -0.128905996910632, 0.432858634222399, -0.245109040039237, -1.08543038934632, 1.68080151955536, 0.176411940863882, -2.07143962693628, 0.211089334851037, -0.582847822547194, 0.0181688430923922, 1.49477799287395, -0.424796733441211, 1.68624315536028)
yy <- c(0, 0, 0, 0, -0.649013765191241, 1.18116604196553, -0.758453297283692, -1.10961303850152, -0.845551240007797, -0.572664866457950, -0.558680764473972, 0.178380225849766, -0.196861446475943, 0.586442621667069, -0.851886969622469, 0.800320709801823, -1.50940472473439, 0.875874147834533, -0.242789536333340, 0.166813439453503,-1.96541870928278, -1.27007139263854, 1.17517126546302, 2.02916018474976,-0.275157240675694, 0.603658445825815, 1.78125189324250, 1.77365832632615, -1.86512257453063, -1.05110705924059,-0.417382047996795, 1.40216228633781,-1.36774699097611, -0.292534999151874, 1.27084843418894, 0.0660093412882059, 0.451290213630776, -0.322209718011896, 0.788409216227425, 0.928736046813314, -0.490790376269763, 1.79720058425494, 0.590696551205452, -0.635785737847226, 0.603346612845761, -0.535247967775900, -0.155080385492789, 0.612122370772160,-1.04434349451734, -0.345631908307050,-1.17140482049761, -0.685586780437283, 0.926216394168962, -1.48167521167231,-0.558057808685045, -0.0284531115706568, -1.47629235201010, 0.258899957160403, -2.01869095243834, 0.199740262298379, 0.425864319131210, -1.27004345059705, -0.485218835743043, 0.594307616829848, -0.276464906639256, -1.85758288592737, 0.0407308117494288, 0.282970177161990, 0.0635612193024994, 0.433430065111595, 0.422860364487685, 1.29952829655200, -1.04979323447507, -1.78641172211092, 0.816043081031918, -0.328208543142512, -1.21456561358767, 1.11183287253465, -0.507496954829846, 0.898730486034072, 0.377215659958544, 1.45239164558790, 0.446945073178942, 0.645824788453030, -0.623677409296163, -0.595236431548712, 1.61132368718055, -0.348998045314167, 0.164167484938754, -1.63657708517891, 0.581365555343623, -0.128905996910632, 0.432858634222399, -0.245109040039237, -1.08543038934632, 1.68080151955536, 0.176411940863882, -2.07143962693628, 0.211089334851037,-0.582847822547194)
ccf (xx, yy)
Matlab data & code:
x = [-0.649013765191241
1.18116604196553
-0.758453297283692
-1.10961303850152
-0.845551240007797
-0.572664866457950
-0.558680764473972
0.178380225849766
-0.196861446475943
0.586442621667069
-0.851886969622469
0.800320709801823
-1.50940472473439
0.875874147834533
-0.242789536333340
0.166813439453503
-1.96541870928278
-1.27007139263854
1.17517126546302
2.02916018474976
-0.275157240675694
0.603658445825815
1.78125189324250
1.77365832632615
-1.86512257453063
-1.05110705924059
-0.417382047996795
1.40216228633781
-1.36774699097611
-0.292534999151874
1.27084843418894
0.0660093412882059
0.451290213630776
-0.322209718011896
0.788409216227425
0.928736046813314
-0.490790376269763
1.79720058425494
0.590696551205452
-0.635785737847226
0.603346612845761
-0.535247967775900
-0.155080385492789
0.612122370772160
-1.04434349451734
-0.345631908307050
-1.17140482049761
-0.685586780437283
0.926216394168962
-1.48167521167231
-0.558057808685045
-0.0284531115706568
-1.47629235201010
0.258899957160403
-2.01869095243834
0.199740262298379
0.425864319131210
-1.27004345059705
-0.485218835743043
0.594307616829848
-0.276464906639256
-1.85758288592737
0.0407308117494288
0.282970177161990
0.0635612193024994
0.433430065111595
0.422860364487685
1.29952829655200
-1.04979323447507
-1.78641172211092
0.816043081031918
-0.328208543142512
-1.21456561358767
1.11183287253465
-0.507496954829846
0.898730486034072
0.377215659958544
1.45239164558790
0.446945073178942
0.645824788453030
-0.623677409296163
-0.595236431548712
1.61132368718055
-0.348998045314167
0.164167484938754
-1.63657708517891
0.581365555343623
-0.128905996910632
0.432858634222399
-0.245109040039237
-1.08543038934632
1.68080151955536
0.176411940863882
-2.07143962693628
0.211089334851037
-0.582847822547194
0.0181688430923922
1.49477799287395
-0.424796733441211
1.68624315536028]
yy = [0
0
0
0
-0.649013765191241
1.18116604196553
-0.758453297283692
-1.10961303850152
-0.845551240007797
-0.572664866457950
-0.558680764473972
0.178380225849766
-0.196861446475943
0.586442621667069
-0.851886969622469
0.800320709801823
-1.50940472473439
0.875874147834533
-0.242789536333340
0.166813439453503
-1.96541870928278
-1.27007139263854
1.17517126546302
2.02916018474976
-0.275157240675694
0.603658445825815
1.78125189324250
1.77365832632615
-1.86512257453063
-1.05110705924059
-0.417382047996795
1.40216228633781
-1.36774699097611
-0.292534999151874
1.27084843418894
0.0660093412882059
0.451290213630776
-0.322209718011896
0.788409216227425
0.928736046813314
-0.490790376269763
1.79720058425494
0.590696551205452
-0.635785737847226
0.603346612845761
-0.535247967775900
-0.155080385492789
0.612122370772160
-1.04434349451734
-0.345631908307050
-1.17140482049761
-0.685586780437283
0.926216394168962
-1.48167521167231
-0.558057808685045
-0.0284531115706568
-1.47629235201010
0.258899957160403
-2.01869095243834
0.199740262298379
0.425864319131210
-1.27004345059705
-0.485218835743043
0.594307616829848
-0.276464906639256
-1.85758288592737
0.0407308117494288
0.282970177161990
0.0635612193024994
0.433430065111595
0.422860364487685
1.29952829655200
-1.04979323447507
-1.78641172211092
0.816043081031918
-0.328208543142512
-1.21456561358767
1.11183287253465
-0.507496954829846
0.898730486034072
0.377215659958544
1.45239164558790
0.446945073178942
0.645824788453030
-0.623677409296163
-0.595236431548712
1.61132368718055
-0.348998045314167
0.164167484938754
-1.63657708517891
0.581365555343623
-0.128905996910632
0.432858634222399
-0.245109040039237
-1.08543038934632
1.68080151955536
0.176411940863882
-2.07143962693628
0.211089334851037
-0.582847822547194]
[XCF,lags,bounds] = crosscorr(xx,yy);
Good afternoon. I have a vector 'a' containing 16000 values. I get the descriptive statistics with the help of the following:
library(pastecs)
library(timeDate)
stat.desc(a)
skewness(a)
kurtosis(a)
Especially skewness=-0.5012, kurtosis=420.8073 (1)
Then I build a histogram of my empirical data:
hist(a, col="lightblue", breaks = 140, border="white", main="",
xlab="Value",xlim=c(-0.001,0.001))
After this I try to fit a theoretical distribution to my empirical data. I choose Variance-Gamma distribution and try to get its parameter estimates on my data:
library(VarianceGammma)
a_VG<-vgFit(a)
The parameter estimates are the following:
vgC=-11.7485, sigma=0.4446, theta=11.7193, nu=0.1186 (2)
Further, I create a sample from the Variance-Gamma distribution with the parameters from (2)
and build a histogram of created theoretical values:
VG<-rvg(length(a),vgC=-11.7485,sigma=0.4446,theta=11.7193,nu=0.1186)
hist(VG,breaks=140,col="orange",main="",xlab="Value")
Bu the second histogram differs absolutely from the first (empirical) histogram. Moreover, it is built on the basis of the parameters (2), which I got on the empirical data.
What's wrong with my code? How can I fix it?
P.S. When I type dput(a[abs(a) > 5e-4]) I get:
c(0.000801110480004752, 0.000588162271316861, 0.000555169128569233,
0.000502563410256229, 0.000854633994686438, 0.00593622112246628,
-0.000506168123513007, -0.000502909585836875, 0.000720924373137422,
0.00119141739181039, 0.000548159382141478, -0.000516511318695123,
-0.000744590777740584, 0.000595213912401249, 0.000514055190913965,
-0.000589061375421807, -0.00175392114572581, 0.000745548313668465,
-0.00075910234096277, -0.00059987613053103, 0.000583568488865538,
0.00426484136013094, 0.000610760059768012, 0.000575522836335551,
0.000823785810599276, 0.00181936036509178, -0.00073316272551871,
-0.00184238143420679, -0.000519146793923397, -0.00120324664043103,
-0.000882469414168696, -0.00148118339830283, 0.000929612782487155,
0.000565364610238817, 0.000578158613453894, 0.00060479145432879,
-0.00520576206828594, 0.000708404040882016, 0.00105224485893451,
0.000636486872540587, -0.00359655507585543, 0.000769164650506582,
0.000635701125126786, 0.000570489501935612, -0.000641260260277221,
0.000735092947873994, 0.000757195823062773, 0.000556002742616357,
-0.00207489740356159, -0.000553386431560554, 0.000511326871983186,
0.000504591469525195, -0.000749886905655472, -0.0013939718643865,
-0.000513742626250036, -0.00105021597423516, -0.00156667292147716,
0.000864563166150134, 0.00433724128055069, 0.00053855648931922,
-0.00150732363190365, 0.00052621785349416, 0.000987781100809215,
0.000560725818171903, 0.00176012436713435, -0.000594895431092368,
-0.000686229580335151, 0.00138682284509528, -0.000531964338888358,
-0.00179959148771403, 0.000574543871314503, -0.000686996216439084,
-0.000559043343629995, 0.00055881173674166, -0.000636332688477736,
-0.000623778186703561, -0.00173834148094443, -0.000567224129968125,
-0.00122578683434504, 0.00130960156515414, -0.000548203197176633,
-0.000522749285863711, -0.000820371086264871, 0.000756014225812507,
-0.000714081490558627, -0.000617600335221624, 0.000523639760748651,
-0.000578502663833191, 0.00107478825239227, 0.000612725356974764,
-0.00065509337422931, 0.000505887803587513, -0.000566716376848575,
0.000511727090058756, 0.000572807738912218, -0.000756026937699161,
0.000547948751494332, 0.000628323894238392, -0.000541350489317693,
-0.00133529454372372, -0.000590618859845904, -0.000700581963648972,
0.000735987224462775, 0.000528958898682319, 0.000838250041022448,
-0.000519084424130511, -0.00052258402856431, -0.000538130765869838,
-0.000631819887885854, 0.00054800880764283, 0.00266115500510899,
-0.000839092093771754, 0.000559253571783103, -0.000801028189803432,
-0.000608879021022801, -0.000538018076854385, -0.000689859734395171,
0.00329650346269972, 0.000765494493951024, -0.000689450477848297,
-0.000560199139975737, 0.00159082699266122, -0.00208548663121455,
-0.000598493596793759, 0.000563544422691464, 0.000626996183768824,
-0.000653166846808162, -0.000851350174739807, -0.00140687473245116,
-0.000887003220306326, -0.000765614651347946, -0.00100676206277761,
0.000724714394852555, 0.00108872127644233, -0.000678558537305918,
-0.000705087556212902, 0.000544828152248655, -0.000791700964308362,
0.000606125736727137, -0.00119335967326073, 0.00075413211796338,
0.000526038939010931, 0.00086543737231537, -0.000817788712950573,
-0.000584070926663571, 0.000619657281937691, 0.000680783312420274,
-0.000513831718574664, -0.00050972403875349, -0.00114542220685365,
-0.00070564389723593, -0.01057964950882, -0.000610357922434801,
0.000818264221596365, 0.000940825400308043, -0.000726555639413817,
-0.000591089505560305, 0.000564738888193972, -0.00068515060569041,
0.000668920238348747, -0.00110103375121717, -0.0015480433031172,
0.000663030855223568, 0.000500097431997304, -0.000600730311271391,
-0.000672397772962796, -0.000607852365856587, 0.000536711920570809,
0.000595055206488837, 0.000523123873687581, 0.000977280737528119,
0.000616410821629998, 0.000788593666889881, -0.000671642905915704,
0.000717328711735021, -0.000551853104219902, -0.000565153434708421,
-0.000802585212152707, 0.000536342062561701, 0.000682048510343591,
-0.000541902545439399, 0.000779676683974273, 0.000698841439971787,
0.000559313965908359, -0.00064986819016255, 0.000795421518319017,
0.00364973919549527, 0.000669658692276087, 0.00109045476974678,
0.000514411572742901, 0.000503832507211754, -0.000507376233564116,
0.001232871590787, 0.000561820312542594, -0.000501190337518054,
-0.000769036505996468, -0.000695537959007453, -0.000572065848166048,
-0.00167929926328192, 0.000597078186826749, 0.00710238430870014,
0.000745192112519888, -0.00116091022028009, -0.000791139281769659,
-0.00148898466632552, 0.000565144038962018, -0.000514019821833855,
-0.00148427996685285, -0.000822717245339888, -0.00062922111212238,
-0.000636011367371125, 0.00119640327632808, 0.000548455410294579,
0.000652678152560426, 0.000509244387833618, 0.000961872348987924,
0.000662064072514568, -0.00068116858054168, -0.000569930302445343,
0.00188358126928101, 0.00130560555273895, 0.000593470885775105,
0.00160093110088155, 0.000785262438315115, -0.000912313442922752,
0.000609996052359563, 0.000720137994393966, 0.000568163899000496,
0.00128685533068307, -0.000756787473447318, 0.000765932134255465,
0.00064884753100003, 0.000687571386270847, -0.000582094290400903,
-0.000693177295971736, -0.000601776208094762, 0.000503616387996786,
-0.000615095866544735, -0.000799593899689199, 0.000773750859128342,
-0.000522576090260074, 0.000503578107212022, -0.00104492224837571,
0.000547928732299141, 0.00310304337507183, 0.000893382870797765,
-0.000577792878910799, -0.000647710366578735, -0.00061992948706191,
0.000825702487162516, 0.000606579510524341, 0.000552792484727505,
0.000688600840895504, 0.000505093563534231, -0.000728420573667066,
-0.00157924525963438, -0.000603846616019865, -0.000521941317177976,
0.00150498158245682, -0.000584572670337735, 0.000713757870583365,
0.000524287801789924, 0.00107217649464886, 0.00213147531822244,
0.000566012832157625, -0.00069828890607937, 0.000641567963736378,
-0.000509531713644762, -0.000547564140049417, -0.00115275240244728,
0.000560465768010943, -0.000651807371497171, -0.00096487058986483,
0.000753687665266511, -0.000665599418910645, -0.000691278087025182,
-0.000578010050725553, -0.000685833148198256, 0.000698470819832764,
0.00102943368139208, -0.000725840586788706, 0.00125882415960632,
-0.000630791474954151, -0.000764813558678412, -0.000638539347184164,
0.000654486496518558, 0.000547453642294471, 0.000572020020495501,
-0.000605791001705214, 0.00660211658324172, 0.00114928683282756,
0.000985676480677711, -0.000694668292547718, -0.000528955637964401,
0.000647975568638159, 0.00116454536417443, 0.000506748841724303,
-0.000500925156604382, -0.000567015088082101, 0.00128711230206946,
0.000533633762033858, 0.00505991432758357, 0.000518058378462527,
-0.000592822519784875, 0.00177414999018666, 0.00059845426944527,
-0.000511614433724716, 0.0016614697907098, 0.000852196464322219,
0.00241689725305427, -0.000614317948913978, -0.000729717143318709,
-0.000612900648802039, -0.000727983564232204, -0.000694965869158182,
-0.000527752006066251, -0.000584233784708843, 0.000522097476268968,
0.000543092880677776, 0.000947121210698398, -0.00241810275096377,
0.00181893137435019, 0.000931873879297385, 0.000512116215015013,
0.000724985702444059, -0.000566713495050664, 0.000603953591362227
)
After fitting the data look like the following (empirical histogram-blue, theoretical histogram-orange):
The same when include freq=FALSE in hist
This will all be due to anomalous values in a not represented by the histogram you've shown. This could be the cause of both the very high kurtotsis, and the vgFit() algorithm failing to find a good fit.
Type dput(a[abs(a) > 5e-4]) in the console and copy the output into your question. People then may be able to recreate aomething like the vector a without having to get all 16000 values and debug the vgFit issue.
Thanks for the extra data. There are some extreme values in there, but I don;t think those are what is causing the problem in vgFit. Fitting 4 parameters which can be almost any value is difficult, but you can help it along by rescaling your data to something typical. Try this:
b <- (a-mean(a))/sd(a)
vgf <- vgFit(b)
vgf$param
VG <- rvg(16000, param = vgf$param)
VG_rescaled <- VG*sd(a)+mean(a)
hist(VG_rescaled, breaks=140, col="orange", main="", xlab="Value")
and see if the two histograms are close enough now.
I have the following data:
479117.562500000 -100.366333008
479117.625000000 -100.292800903
479117.687500000 -100.772460937
479117.750000000 -101.344261169
479117.812500000 -102.828948975
479117.875000000 -103.842330933
479117.937500000 -102.289733887
479118.000000000 -101.856155396
479118.062500000 -101.972282410
479118.125000000 -101.272254944
479118.187500000 -101.042846680
479118.250000000 -101.957427979
479118.312500000 -101.363922119
479118.375000000 -101.065864563
479118.437500000 -99.710098267
479118.500000000 -98.789115906
479118.562500000 -99.854644775
479118.625000000 -100.956558228
479118.687500000 -100.456512451
479118.750000000 -100.779090881
479118.812500000 -101.598800659
479118.875000000 -100.329147339
479118.937500000 -100.486946106
479119.000000000 -102.275772095
479119.062500000 -103.128715515
479119.125000000 -103.075996399
479119.187500000 -103.266349792
479119.250000000 -102.390190125
479119.312500000 -101.386428833
479119.375000000 -102.008850098
479119.437500000 -103.579475403
479119.500000000 -103.382720947
479119.562500000 -100.842361450
479119.625000000 -98.478569031
479119.687500000 -98.745864868
479119.750000000 -99.653961182
479119.812500000 -100.032035828
479119.875000000 -99.955345154
479119.937500000 -99.842536926
479120.000000000 -100.187896729
479120.062500000 -100.456726074
479120.125000000 -101.258850098
479120.187500000 -102.649017334
479120.250000000 -104.833518982
479120.312500000 -102.760551453
479120.375000000 -101.653732300
479120.437500000 -102.729179382
479120.500000000 -102.752014160
479120.562500000 -103.103675842
479120.625000000 -102.842521667
479120.687500000 -102.692077637
479120.750000000 -102.499221802
479120.812500000 -101.806587219
479120.875000000 -102.124893188
479120.937500000 -101.700584412
479121.000000000 -101.385307312
479121.062500000 -101.242889404
479121.125000000 -100.172935486
479121.187500000 -100.230110168
479121.250000000 -100.861007690
479121.312500000 -101.013366699
479121.375000000 -100.585502625
479121.437500000 -100.897743225
479121.500000000 -101.453987122
479121.562500000 -102.233383179
479121.625000000 -102.231163025
479121.687500000 -99.512817383
479121.750000000 -97.662391663
479121.812500000 -97.647987366
479121.875000000 -100.217674255
479121.937500000 -102.411224365
479122.000000000 -101.892311096
479122.062500000 -102.475875854
479122.125000000 -103.164466858
479122.187500000 -103.406997681
479122.250000000 -104.319549561
479122.312500000 -102.138801575
479122.375000000 -99.946632385
479122.437500000 -100.355888367
479122.500000000 -101.683120728
479122.562500000 -101.582458496
479122.625000000 -99.907981873
479122.687500000 -100.329666138
479122.750000000 -100.243255615
479122.812500000 -100.713218689
479122.875000000 -102.436210632
479122.937500000 -103.173072815
479123.000000000 -103.720008850
479123.062500000 -105.225852966
479123.125000000 -104.841903687
479123.187500000 -103.589698792
479123.250000000 -101.543907166
479123.312500000 -101.051879883
479123.375000000 -103.181671143
479123.437500000 -104.825492859
479123.500000000 -103.848281860
479123.562500000 -102.969032288
479123.625000000 -101.002128601
479123.687500000 -100.698005676
479123.750000000 -102.078453064
479123.812500000 -103.582519531
479123.875000000 -105.085006714
479123.937500000 -103.349472046
479124.000000000 -100.479156494
479124.062500000 -100.558197021
479124.125000000 -101.563316345
479124.187500000 -101.261054993
479124.250000000 -102.108535767
479124.312500000 -104.861206055
479124.375000000 -105.044944763
479124.437500000 -105.712318420
479124.500000000 -105.045219421
479124.562500000 -104.131736755
479124.625000000 -104.060478210
479124.687500000 -103.435829163
479124.750000000 -103.167121887
479124.812500000 -102.186767578
479124.875000000 -101.180900574
479124.937500000 -101.686195374
479125.000000000 -102.167709351
479125.062500000 -102.771011353
479125.125000000 -103.367576599
479125.187500000 -103.127212524
479125.250000000 -103.924591064
479125.312500000 -103.187667847
479125.375000000 -102.220222473
479125.437500000 -102.674034119
479125.500000000 -101.717445374
479125.562500000 -100.879615784
479125.625000000 -100.964996338
479125.687500000 -102.864616394
479125.750000000 -102.009140015
479125.812500000 -99.761398315
479125.875000000 -99.798591614
479125.937500000 -101.713653564
479126.000000000 -103.273422241
479126.062500000 -102.664245605
479126.125000000 -101.682983398
479126.187500000 -101.853103638
479126.250000000 -103.193588257
479126.312500000 -104.359184265
479126.375000000 -105.037651062
479126.437500000 -104.446434021
479126.500000000 -103.674736023
479126.562500000 -103.374031067
479126.625000000 -102.921363831
479126.687500000 -103.374008179
479126.750000000 -104.299362183
479126.812500000 -104.015937805
479126.875000000 -103.758834839
479126.937500000 -103.698440552
479127.000000000 -103.501396179
479127.062500000 -101.677307129
479127.125000000 -101.010841370
479127.187500000 -103.159111023
479127.250000000 -105.232284546
479127.312500000 -105.949432373
479127.375000000 -104.999694824
479127.437500000 -104.207763672
479127.500000000 -103.822082520
479127.562500000 -103.189147949
479127.625000000 -102.943603516
479127.687500000 -102.586914062
479127.750000000 -102.973297119
479127.812500000 -104.049942017
479127.875000000 -106.436325073
479127.937500000 -105.395500183
479128.000000000 -106.032653809
479128.062500000 -106.538482666
479128.125000000 -105.961471558
479128.187500000 -106.049240112
479128.250000000 -104.937507629
479128.312500000 -104.842300415
479128.375000000 -104.720268250
479128.437500000 -105.791313171
479128.500000000 -106.022468567
479128.562500000 -103.848289490
479128.625000000 -103.887428284
479128.687500000 -104.258583069
479128.750000000 -105.152420044
479128.812500000 -107.673591614
479128.875000000 -107.705734253
479128.937500000 -105.925376892
479129.000000000 -105.528671265
479129.062500000 -106.021476746
479129.125000000 -107.750610352
479129.187500000 -108.693489075
479129.250000000 -108.675323486
479129.312500000 -109.919746399
479129.375000000 -110.940391541
479129.437500000 -109.279312134
479129.500000000 -108.321495056
479129.562500000 -107.995155334
479129.625000000 -109.164222717
479129.687500000 -111.977653503
479129.750000000 -113.194961548
479129.812500000 -114.239585876
479129.875000000 -115.780212402
479129.937500000 -116.979713440
479130.000000000 -117.042602539
479130.062500000 -116.658126831
479130.125000000 -116.624031067
479130.187500000 -116.923446655
479130.250000000 -118.727882385
479130.312500000 -120.354904175
479130.375000000 -121.513587952
479130.437500000 -121.322601318
479130.500000000 -121.338325500
479130.562500000 -120.500923157
479130.625000000 -116.656593323
479130.687500000 -113.295486450
479130.750000000 -111.713729858
479130.812500000 -111.394592285
479130.875000000 -109.731071472
479130.937500000 -108.571876526
479131.000000000 -109.059860229
479131.062500000 -106.810707092
479131.125000000 -106.095306396
479131.187500000 -106.258293152
479131.250000000 -106.243156433
479131.312500000 -106.613525391
479131.375000000 -105.910820007
479131.437500000 -104.405731201
479131.500000000 -102.325592041
479131.562500000 -101.502128601
479131.625000000 -103.445144653
479131.687500000 -105.970573425
479131.750000000 -105.379684448
479131.812500000 -102.992294312
479131.875000000 -100.679176331
479131.937500000 -99.553001404
479132.000000000 -100.532035828
479132.062500000 -102.480346680
479132.125000000 -104.630592346
479132.187500000 -103.669296265
479132.250000000 -101.364990234
479132.312500000 -100.193199158
479132.375000000 -98.483375549
479132.437500000 -98.084083557
479132.500000000 -100.955741882
479132.562500000 -102.788536072
479132.625000000 -102.540054321
479132.687500000 -102.550140381
479132.750000000 -101.182907104
479132.812500000 -100.926239014
479132.875000000 -100.933807373
479132.937500000 -101.358642578
479133.000000000 -100.544723511
479133.062500000 -99.536102295
479133.125000000 -99.533355713
479133.187500000 -100.520698547
479133.250000000 -99.944213867
479133.312500000 -100.118461609
479133.375000000 -101.425323486
479133.437500000 -102.523521423
479133.500000000 -102.540794373
479133.562500000 -101.491882324
479133.625000000 -100.919067383
479133.687500000 -100.623329163
479133.750000000 -99.431541443
479133.812500000 -99.252487183
479133.875000000 -101.166763306
479133.937500000 -102.311378479
479134.000000000 -101.306701660
479134.062500000 -100.665534973
479134.125000000 -100.248069763
479134.187500000 -99.179161072
479134.250000000 -100.506088257
479134.312500000 -101.349990845
479134.375000000 -101.028564453
479134.437500000 -101.089591980
479134.500000000 -100.819961548
479134.562500000 -100.899681091
479134.625000000 -102.236335754
479134.687500000 -101.911392212
479134.750000000 -101.253051758
479134.812500000 -102.417984009
479134.875000000 -101.647750854
479134.937500000 -100.494926453
479135.000000000 -99.920089722
479135.062500000 -101.046142578
479135.125000000 -102.893470764
479135.187500000 -102.895072937
479135.250000000 -103.607261658
479135.312500000 -104.568321228
479135.375000000 -104.253341675
479135.437500000 -102.952842712
479135.500000000 -101.928634644
479135.562500000 -101.746994019
479135.625000000 -102.218338013
479135.687500000 -102.627662659
479135.750000000 -102.185234070
479135.812500000 -103.266464233
479135.875000000 -104.480552673
479135.937500000 -102.991035461
479136.000000000 -101.333572388
479136.062500000 -102.019165039
479136.125000000 -100.434211731
479136.187500000 -99.072113037
479136.250000000 -100.616592407
479136.312500000 -101.648803711
479136.375000000 -102.449073792
479136.437500000 -103.141990662
479136.500000000 -101.611976624
479136.562500000 -101.742187500
479136.625000000 -102.974266052
479136.687500000 -101.894943237
479136.750000000 -101.637077332
479136.812500000 -101.545288086
479136.875000000 -101.042068481
479136.937500000 -101.836784363
479137.000000000 -103.539382935
479137.062500000 -105.681159973
479137.125000000 -102.126953125
479137.187500000 -98.450904846
479137.250000000 -98.859046936
479137.312500000 -102.353157043
479137.375000000 -105.606437683
479137.437500000 -104.589866638
479137.500000000 -103.607994080
479137.562500000 -102.202362061
479137.625000000 -101.861511230
479137.687500000 -101.010215759
479137.750000000 -100.456481934
479137.812500000 -101.639465332
479137.875000000 -102.876907349
479137.937500000 -103.880729675
479138.000000000 -105.811225891
479138.062500000 -106.915206909
479138.125000000 -108.233901978
479138.187500000 -106.625434875
479138.250000000 -103.686866760
479138.312500000 -102.977874756
479138.375000000 -105.153343201
479138.437500000 -106.966751099
479138.500000000 -104.752532959
479138.562500000 -104.894256592
479138.625000000 -105.125381470
479138.687500000 -102.721633911
479138.750000000 -102.299125671
479138.812500000 -102.762176514
479138.875000000 -101.316398621
479138.937500000 -100.695121765
479139.000000000 -101.257949829
479139.062500000 -102.382209778
479139.125000000 -104.331405640
479139.187500000 -106.033081055
479139.250000000 -105.467399597
479139.312500000 -104.492301941
479139.375000000 -104.413681030
479139.437500000 -103.263702393
479139.500000000 -103.199569702
479139.562500000 -104.447860718
479139.625000000 -104.169952393
479139.687500000 -105.357246399
479139.750000000 -105.624694824
479139.812500000 -104.329673767
479139.875000000 -104.890480042
479139.937500000 -103.739471436
479140.000000000 -102.343170166
479140.062500000 -102.630371094
479140.125000000 -103.861930847
479140.187500000 -102.614120483
479140.250000000 -102.544586182
479140.312500000 -103.947563171
479140.375000000 -104.194770813
479140.437500000 -103.187141418
479140.500000000 -102.442695618
479140.562500000 -103.064849854
479140.625000000 -104.047111511
479140.687500000 -103.641082764
479140.750000000 -104.192665100
479140.812500000 -105.001426697
479140.875000000 -106.180221558
479140.937500000 -106.504646301
479141.000000000 -104.772674561
479141.062500000 -104.167114258
479141.125000000 -102.925132751
479141.187500000 -102.731872559
479141.250000000 -104.101806641
479141.312500000 -104.532470703
479141.375000000 -103.677726746
479141.437500000 -103.467483521
479141.500000000 -104.314605713
479141.562500000 -106.088348389
479141.625000000 -105.849678040
479141.687500000 -104.784294128
479141.750000000 -104.685859680
479141.812500000 -102.816184998
479141.875000000 -103.009178162
479141.937500000 -105.581695557
479142.000000000 -104.964607239
479142.062500000 -103.978279114
479142.125000000 -104.709609985
479142.187500000 -105.373786926
479142.250000000 -105.477348328
479142.312500000 -107.076698303
479142.375000000 -108.599830627
479142.437500000 -107.518699646
To which I want to fit the function
While the formula is kind of a beast, it has physical meaning, so I would like to not change it.
I have the following code:
index_min <- which(mydf[,2] == min(mydf[,2]))[1]
n0start <- -119
n1start <- 16
df0start <- 120
df1start <- 1
f0start <- mydf[index_min,1]
f1start <- mydf[index_min,1]
plot(x=mydf[,1],y=mydf[,2])
eq = function(f,n0, n1, f0, f1, df0, df1){ n0+n1*4*(f-f1)^2/(4*(f-f1)^2+(4*((f-f0)/df0)*(f-f1)-df1)^2)}
lines(mydf[,1], eq(mydf[,1],n0start, n1start, f0start, f1start, df0start, df1start), col="red" )
res <- try(nlsLM( y ~ n0+n1*4*(f-f1)^2/(4*(f-f1)^2+(4*((f-f0)/df0)*(f-f1)-df1)^2),
start=c(n0=n0start, n1=n1start,f0=f0start,df0=df0start,f1=f1start,df1=df1start) , data = mydf))
coef(res)
As you can see, the starting values look rather decent, but I get the "singular gradient matrix at initial parameter estimates" error. I have looked through all the other posts, however, I don't see why my formula is overdetermined or why the starting values should be bad.
Okay, I figured out the mistake. nlsLM requires data to be a data-frame and not just a bare matrix. The error message is simply misleading.
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.
My question is pretty simple: the cut() function allows to choose the breaks along which I can divide the range of my vector into intervals. I would like to be able to control for the number of observations within the newly created interval, in a way similar to what could be obtained with a quantile argument in the cut() function call. However I don't want to be using the quantile argument because I would like for the intervals to be chosen fixed, so that I can match them between different databases for further comparison, and I want the same discrete values to be found in the labels of the newly cut vectors.
I used to use this for the quantile approach:
df$z<-cut(df$x, quantile(x, (0:10)/10), include.lowest=TRUE)
Which is fairly simple. My new approach is even simpler, so it resembles this for example:
df$z<-cut(df$x, c(0.04,0.055,0.06,0.065,0.07,0.075,0.08,0.085,0.09,0.095,0.11), include.lowest=T)
I then have another variable which I want to calculate some statistics on, according to the levels of the discrete variable.
So it would go something like this :
df$conf.intx<-ifelse(df$z=="1",t.test(df[df$z=="1",]$y)$conf.int[1],
ifelse(df$z=="2",t.test(df[df$z=="2",]$y)$conf.int[1],
ifelse(df$z=="3",t.test(df[df$z=="3",]$y)$conf.int[1],
ifelse(df$z=="4",t.test(df[df$z=="4",]$y)$conf.int[1],NA))))
But for me to be able to calculate this kind of t-test confidence interval on each of the 'pools' of the y values (which number in the same amount as the observations within the intervals of the discrete variable), I need to be able to control for the number of values within each created interval for z, so that my test remains valid, at least as far as the number of observations is concerned.
Simply put, I'd need an automated procedure that would create the vector of breaks for the z variable so that each of them contains a minimum number of observations. As an added complication, it should be the same breaks for two different databases, which I don't know if it's possible.
Any help on the matter would be welcome, thank you in advance.
EDIT: here is a sample of my data for x.
structure(list(x = c(5.319125, 7.3036667, 5.5166167, 7.0308333,
5.6812917, 6.5496583, 5.6621833, 6.4682, 5.4897417, 7.185175,
6.44905, 7.2055833, 7.629375, 6.2282833, 6.6813917, 7.7976, 6.683975,
5.5089083, 7.307475, 7.3958667, 6.2036583, 6.2488833, 5.9372,
6.6180167, 6.4167833, 5.640275, 8.7416917, 8.3134167, 6.8996833,
5.1161917, 7.0606333, 5.2622667, 6.780925, 5.4615417, 6.48185,
5.51585, 6.2224333, 5.3660667, 7.196525, 6.2984083, 7.0137833,
7.4490083, 5.9712333, 6.4287833, 7.6693917, 6.4406417, 5.4135083,
7.16245, 7.2267, 5.820325, 6.066175, 5.760975, 6.4775, 6.2625,
5.5182583, 8.446625, 8.19025, 6.7955333, 4.7899583, 6.5680167,
4.5965917, 6.3539333, 4.6639, 6.0489667, 4.9047833, 5.353625,
4.711425, 6.6268833, 5.5458083, 6.3271917, 6.4591417, 5.1843917,
5.6117167, 7.1828417, 5.6956917, 5.0271917, 6.741875, 6.68305,
4.7859667, 5.3068667, 5.3245, 5.745675, 5.7518917, 5.37945, 8.0030417,
7.7064583, 6.2935333, 5.1838667, 6.9369333, 4.9734583, 6.7257167,
5.0510333, 6.4257667, 5.2858083, 5.7285167, 5.084, 7.0092833,
5.905875, 6.6893417, 6.8319583, 5.5558083, 5.9854833, 7.5552167,
6.064625, 5.3990333, 7.115175, 7.0600167, 5.1644833, 5.6848667,
5.7014417, 6.1051, 6.1186333, 5.7217667, 8.3685417, 8.071325,
6.6547333, 5.5972417, 7.4226, 5.539725, 7.26335, 5.645975, 6.87475,
5.8486167, 6.3001667, 5.5997833, 7.4353167, 6.5089583, 7.213625,
7.3125667, 6.12095, 6.5410083, 8.0639083, 6.6505167, 5.8886417,
7.6301167, 7.5850417, 5.7693667, 6.2480167, 6.1847167, 6.6896167,
6.6323917, 6.1972167, 8.8560333, 8.5501083, 7.1036167, 4.9929583,
6.9839583, 5.3847417, 6.8814417, 5.59555, 6.7867167, 5.7831333,
6.9370917, 5.7400917, 7.6922, 6.3151, 7.084725, 7.0414417, 5.95435,
6.4274167, 7.6692167, 6.9159, 6.0856083, 7.3079583, 7.1937667,
5.744675, 5.946525, 6.0651833, 6.8488833, 6.5924333, 5.772025,
8.3281167, 8.5475917, 6.7952917, 8.248525, 5.1931083, 7.0688917,
5.4793583, 7.0091583, 5.7593, 7.1053333, 5.9382583, 7.1765417,
6.003075, 7.7699833, 6.2757333, 7.2446583, 7.179275, 6.0013083,
6.447975, 7.7845833, 6.9071083, 6.1009, 7.425425, 7.4619083,
5.9380667, 6.2116, 6.13315, 7.0852, 7.0047417, 6.0763917, 8.5926583,
8.7468417, 7.2485167, 8.5096833, 5.1541, 7.0479917, 5.43065,
6.9689083, 5.7356, 7.0842917, 5.9051667, 7.1283333, 5.9666667,
7.7295583, 6.249925, 7.21005, 7.1427167, 5.9675583, 6.4135667,
7.7448583, 6.874275, 6.0679333, 7.388675, 7.429025, 5.911225,
6.1757167, 6.095225, 7.045775, 6.9870833, 6.0567333, 8.5771167,
8.7541917, 7.3187333, 8.5092083, 5.5746, 7.342925, 5.8561667,
7.4704667, 5.922225, 6.9787, 6.1564167, 7.6059667, 5.9122917,
7.7848833, 6.6192, 7.34055, 7.2352417, 5.9776083, 6.5197583,
7.4891583, 7.2185667, 6.4710167, 7.70945, 7.5078083, 6.1470417,
6.66115, 6.6899333, 7.4454083, 7.2270917, 6.350075, 8.3156667,
8.9007917, 6.7578083, 8.3258083, 5.1996, 6.9688833, 5.3592917,
6.7583417, 5.5623583, 6.756375, 5.7361, 7.120425, 5.6567, 7.6174667,
6.1474833, 7.1442167, 6.74475, 5.5820333, 6.0106, 7.142675, 6.667475,
5.9067917, 7.2392, 7.058675, 5.6394417, 5.9119167, 5.8367333,
6.798025, 6.694675, 5.8565917, 8.6035083, 8.912375, 7.0501083,
8.38045, 4.8478083, 6.7493167, 5.3686667, 6.5152333, 5.282025,
6.5464333, 5.5085583, 6.870975, 5.4757667, 7.318, 5.92225, 6.9300417,
6.5758083, 5.4233083, 5.8295583, 7.0451, 6.4790083, 5.68255,
6.9632833, 6.9965833, 5.5005667, 5.717725, 5.5938083, 6.5309,
6.4824583, 5.4429833, 8.072575, 8.3635, 6.5797167, 8.0352333,
4.6289833, 6.64105, 4.8883833, 6.2025833, 5.2291833, 6.4814667,
5.2211083, 6.5780083, 5.196275, 7.030725, 5.6001583, 6.620475,
6.2858333, 5.114375, 5.5424417, 6.7784917, 6.1561333, 5.339375,
6.6249083, 6.6248583, 5.139775, 5.4195, 5.4531833, 6.3348583,
6.4041417, 5.292, 7.6243833, 7.9624583, 6.3226417, 7.761175,
4.8419083, 6.8384083, 5.3500417, 6.5903333, 5.33275, 6.732575,
5.4486, 6.8069417, 5.4569583, 7.26275, 5.835525, 6.8680333, 6.6712333,
5.4720417, 5.904325, 7.1506917, 6.4746833, 5.638675, 6.9570667,
7.0017333, 5.5033667, 5.6859333, 5.651875, 6.5903, 6.529725,
5.4819667, 7.971975, 8.2337833, 6.5815333, 7.9736583, 5.7711917,
7.543325, 5.8986917, 7.5081333, 6.2920333, 7.5321667, 6.4908917,
7.7616583, 6.4509417, 8.08035, 6.8219, 7.7939167, 7.6491333,
6.4773583, 6.9338667, 8.1865583, 7.3998917, 6.572125, 7.9198417,
8.0568, 6.5880333, 6.8299667, 6.7399833, 7.6436, 7.509275, 6.5139833,
9.1520167, 9.3580667, 7.65415, 9.0725167, 5.7483583, 7.5230417,
5.89105, 7.4808833, 6.1969667, 7.4923583, 6.4092583, 7.70695,
6.3970833, 8.0971333, 6.7949083, 7.76445, 7.6170167, 6.4494333,
6.8997, 8.1575333, 7.3728417, 6.544075, 7.888, 8.0215, 6.5484,
6.7911667, 6.7121917, 7.6179083, 7.4731167, 6.4629167, 9.1226333,
9.3307083, 7.6230583, 9.024875, 5.543925, 7.1460833, 5.6575583,
7.5986083, 6.027075, 7.4386167, 6.3500333, 7.6694833, 6.3682583,
8.0843333, 6.7181083, 7.7376, 7.5818583, 6.4010667, 6.8440083,
8.1217917, 7.3290833, 6.5187333, 7.8591667, 7.9898583, 6.5051,
6.7251167, 6.6881333, 7.477675, 7.3571333, 6.3351833, 8.881575,
9.12315, 7.3851, 8.8008667, 5.3437833, 7.1560417, 5.5748, 7.4622583,
5.9412417, 7.3428667, 6.2594167, 7.5839167, 6.28685, 8.0270917,
6.6388333, 7.6611, 7.50065, 6.3217167, 6.7594417, 8.0401167,
7.252425, 6.444, 7.77975, 7.9104167, 6.42495, 6.6421667, 6.6103333,
7.3489417, 7.23205, 6.2059333, 8.726725, 8.994625, 7.2460917,
8.660125, 5.2502833, 7.2591, 5.6425417, 6.889925, 5.353675, 6.50635,
6.260675, 7.4236583, 5.9076417, 7.3915, 6.2134917, 7.1645333,
6.922675, 6.0295417, 6.1687917, 7.2771083, 6.6152333, 6.3299417,
7.167325, 6.647275, 5.726475, 5.93905, 6.2888583, 6.7497167,
6.4364083, 5.8906583, 7.6052917, 8.039425, 6.5672833, 7.8754667,
6.3086333, 5.352025, 7.2849417, 5.7184833, 6.9675917, 5.5615333,
6.6157917, 6.3505417, 7.4881, 6.0007417, 7.5110583, 6.35525,
7.254075, 7.0289083, 6.1994417, 6.2860833, 7.372575, 6.735975,
6.4628917, 7.3102167, 6.8619417, 5.9123667, 6.1611917, 6.4854083,
6.8942417, 6.563625, 6.0610083, 7.941625, 8.6969167, 6.66075,
8.1197167, 6.2802, 3.9638, 5.870825, 4.1852, 5.5841417, 4.3007583,
5.2352167, 4.4281417, 5.819425, 4.1990917, 5.9338917, 4.89765,
5.7204333, 5.6546833, 4.5632167, 4.9803333, 5.6962417, 5.247725,
4.7092583, 6.0145417, 5.6403917, 4.4016917, 4.7181, 4.5007833,
5.2828917, 5.1314167, 4.7492, 6.777575, 6.9040083, 4.9760583,
6.4471917, 5.0952833, 3.712725, 5.8215333, 4.025725, 5.5635,
4.2354083, 5.143525, 4.4900083, 5.6802417, 4.1214333, 5.8128,
4.7525583, 5.6412583, 5.5534917, 4.487475, 4.8237833, 5.6156917,
5.0573, 4.5755417, 5.8096083, 5.5252083, 4.3145583, 4.5437417,
4.194675, 5.0100833, 4.8972333, 4.590025, 6.6441417, 6.5789417,
4.6947667, 6.1648167, 4.8517333, 3.982925, 5.7966833, 4.1607083,
5.5564833, 4.2557417, 5.2304083, 4.8661333, 5.912875, 4.4988333,
6.03915, 4.9131583, 5.8518667, 5.6578583, 4.773225, 4.8958583,
5.8759833, 5.204725, 4.8961667, 5.9217, 5.58395, 4.5410667, 4.73445,
4.5922333, 5.2517333, 5.0220333, 4.619475, 6.4883667, 6.429175,
4.6796417, 6.3171083, 4.93615, 3.9278833, 5.7590417, 4.1155667,
5.612725, 4.2199833, 5.2126667, 4.805275, 5.8888833, 4.4363,
6.0380083, 4.892, 5.8192083, 5.64205, 4.708825, 4.8751583, 5.833775,
5.2210417, 4.853225, 5.924225, 5.5856583, 4.5386167, 4.7280917,
4.5618, 5.264425, 5.03855, 4.5539, 6.4993, 6.4900667, 4.6749083,
6.2961333, 4.918525, 4.0890583, 6.33385, 4.3470083, 5.9645, 4.6541833,
5.5438667, 4.9556583, 6.1590583, 4.6379417, 6.2876833, 5.2235167,
6.1387167, 6.0547583, 4.9545667, 5.254125, 6.05395, 5.4813417,
4.9971333, 6.2266583, 5.9172833, 4.7275917, 4.9274917, 4.443575,
5.3164917, 5.2507083, 5.1704583, 7.173075, 6.9351583, 5.0816667,
6.5568, 5.3417667, 5.1705167, 7.0777833, 5.6253333, 7.231225,
5.5799167, 6.6942917, 6.1014583, 7.538725, 5.7152667, 7.459275,
6.2406083, 7.064925, 6.9234417, 5.8328833, 6.1819583, 7.2127583,
6.8071583, 6.2599417, 7.2975417, 6.973875, 5.804125, 6.1944667,
6.38855, 7.0553583, 6.8393167, 6.1275417, 7.9986833, 8.5846,
6.4682167, 8.0134583, 6.1805917, 5.0699583, 6.9006667, 5.36365,
6.9204917, 5.4478667, 6.5391583, 6.0647417, 7.2951667, 5.6632833,
7.25595, 6.1057333, 6.9578417, 6.8235583, 5.8671833, 6.0716417,
7.060175, 6.5401, 6.1229417, 7.1305083, 6.7823417, 5.62415, 5.9202,
5.9957167, 6.7142167, 6.4706417, 5.9004667, 7.8304583, 8.2144667,
6.1530583, 7.6896417, 5.9285333, 4.2625417, 5.9677583, 4.58695,
6.0400083, 4.4215333, 5.6052833, 5.04165, 6.48845, 4.6423583,
6.1688833, 5.0256167, 5.926725, 5.7214667, 4.746375, 4.9828,
6.1583083, 5.6903, 5.217375, 6.1341583, 5.7868083, 4.5895333,
4.98235, 5.159725, 5.7866167, 5.6300833, 4.882975, 6.7210833,
7.4314833, 5.2493083, 6.8503833, 5.2225583, 3.8417833, 5.9798,
4.1168583, 5.63415, 4.3311333, 5.0777667, 4.6606833, 5.789425,
4.3565167, 5.9736167, 4.8910667, 5.9445417, 5.699275, 4.6897167,
4.9036083, 5.8767, 5.088675, 4.6224417, 5.8052833, 5.5697167,
4.3237, 4.6084333, 4.2958833, 5.1394417, 5.0137583, 4.7711, 6.771275,
6.5984417, 4.845625, 6.3338083, 5.1370333, 3.1820167, 5.2699667,
3.4827167, 5.0992583, 3.7040583, 4.6358583, 4.1604917, 5.2488333,
3.7522, 5.3774167, 4.2636167, 5.1998167, 5.0456333, 4.051475,
4.289175, 5.1718917, 4.5787083, 4.1461667, 5.2983167, 5.03025,
3.8709333, 4.0917167, 3.731925, 4.5584167, 4.4200333, 4.061375,
6.064225, 6.02975, 4.1590167, 5.6589083, 4.2614833, 3.68695,
5.587375, 3.91725, 5.3387, 4.0061667, 4.9563833, 4.1942, 5.6720583,
3.9584333, 5.6873583, 4.6251, 5.4801417, 5.3975583, 4.2382, 4.6710917,
5.4898083, 5.0469667, 4.4950083, 5.72005, 5.46085, 4.30355, 4.5525917,
4.3681667, 5.1723167, 5.0331417, 4.4793083, 6.5492917, 6.720225,
4.7550917, 6.197775, 4.8082917, 4.09925, 5.986525, 4.3104417,
5.68455, 4.4287167, 5.3555667, 4.5191083, 5.9269833, 4.2695917,
5.9984167, 4.981225, 5.8049917, 5.7680667, 4.5736667, 5.0673583,
5.7443583, 5.2811083, 4.719175, 6.0376667, 5.73875, 4.3947333,
4.8157333, 4.6093417, 5.3906417, 5.2357417, 4.684825, 6.8885583,
7.018425, 5.0878167, 6.5122333, 5.2084, 3.810525, 6.2600083,
3.6246583, 5.7396417, 4.0617917, 5.6724583, 4.2505833, 4.7518417,
4.1232, 6.208375, 4.5881167, 5.252575, 5.71795, 4.0840583, 4.700325,
6.2360333, 4.701725, 3.922525, 5.5162167, 5.6220333, 3.8836833,
4.4883667, 4.5398583)), .Names = "x", row.names = c(NA, -962L
), class = "data.frame")
Assuming I want 30 values per interval (the 'n'), here is the code I used:
df$z<-cut(df$x, seq(30,length(df$x),by=30)/length(df$x), include.lowest=T)
Which gives me:
> table(df$z)
[0.0312,0.0624] (0.0624,0.0936] (0.0936,0.125] (0.125,0.156] (0.156,0.187] (0.187,0.218] (0.218,0.249] (0.249,0.281] (0.281,0.312] (0.312,0.343] (0.343,0.374]
0 0 0 0 0 0 0 0 0 0 0
(0.374,0.405] (0.405,0.437] (0.437,0.468] (0.468,0.499] (0.499,0.53] (0.53,0.561] (0.561,0.593] (0.593,0.624] (0.624,0.655] (0.655,0.686] (0.686,0.717]
0 0 0 0 0 0 0 0 0 0 0
(0.717,0.748] (0.748,0.78] (0.78,0.811] (0.811,0.842] (0.842,0.873] (0.873,0.904] (0.904,0.936] (0.936,0.967] (0.967,0.998]
0 0 0 0 0 0 0 0 0
What I want is a similar result to what I get with quantiles:
df$zbis<-cut(df$x, quantile(df$x, (0:20)/20), include.lowest=T)
table(df$zbis)
[3.18,4.29] (4.29,4.62] (4.62,4.89] (4.89,5.14] (5.14,5.33] (5.33,5.53] (5.53,5.66] (5.66,5.8] (5.8,5.94] (5.94,6.1] (6.1,6.26] (6.26,6.45] (6.45,6.58] (6.58,6.74] (6.74,6.93]
49 48 48 48 48 48 48 48 48 48 48 48 48 48 48
(6.93,7.14] (7.14,7.34] (7.34,7.62] (7.62,8.06] (8.06,9.36]
48 48 48 48 49
Except I'd like this to be reproducible for another database, and so I can't use the quantile function, since I would not get the same intervals on a different database.
SECOND EDIT: here is the second sample from another database. 'x' is the same variable, and they have similar ranges.
structure(list(x = c(5.319125, 7.3036667, 5.5166167, 7.0308333,
5.6812917, 6.5496583, 5.6621833, 6.4682, 5.4897417, 7.185175,
6.44905, 7.2055833, 7.629375, 6.2282833, 6.6813917, 7.7976, 6.683975,
5.5089083, 7.307475, 7.3958667, 6.2036583, 6.2488833, 5.9372,
6.6180167, 6.4167833, 5.640275, 8.7416917, 8.3134167, 6.8996833,
5.1931083, 7.0688917, 5.4793583, 7.0091583, 5.7593, 7.1053333,
5.9382583, 7.1765417, 6.003075, 7.7699833, 6.2757333, 7.2446583,
7.179275, 6.0013083, 6.447975, 7.7845833, 6.9071083, 6.1009,
7.425425, 7.4619083, 5.9380667, 6.2116, 6.13315, 7.0852, 7.0047417,
6.0763917, 8.5926583, 8.7468417, 7.2485167, 8.5096833, 5.177275,
7.09985, 5.6444667, 7.0102417, 5.7303833, 7.0383333, 5.9870583,
7.3342083, 5.9363667, 7.7753333, 6.38355, 7.389575, 7.0396667,
5.889625, 6.29395, 7.51135, 6.940925, 6.1455417, 7.4281833, 7.4657167,
5.9707083, 6.1902083, 6.0936167, 6.9595167, 6.85065, 5.8525,
8.5148083, 8.805625, 7.00665, 8.4457, 5.3437833, 7.1560417, 5.5748,
7.4622583, 5.9412417, 7.3428667, 6.2594167, 7.5839167, 6.28685,
8.0270917, 6.6388333, 7.6611, 7.50065, 6.3217167, 6.7594417,
8.0401167, 7.252425, 6.444, 7.77975, 7.9104167, 6.42495, 6.6421667,
6.6103333, 7.3489417, 7.23205, 6.2059333, 8.726725, 8.994625,
7.2460917, 8.660125, 3.614125, 5.6345917, 3.9410417, 5.2901417,
4.0147333, 4.766825, 4.4500417, 5.5189, 4.11375, 5.6350667, 4.5756917,
5.5998833, 5.3663, 4.44405, 4.5767417, 5.552025, 4.847425, 4.4382583,
5.5769417, 5.2390667, 4.0610917, 4.4054833, 4.1917, 4.9029083,
4.6935917, 4.3499417, 6.0562333, 6.081225, 4.45855, 6.0121583,
4.740275, 4.5028, 6.4177833, 4.8716417, 6.1469917, 4.6208917,
5.7748083, 5.4530083, 6.694125, 5.0944333, 6.5123167, 5.3257083,
6.2765333, 6.0149167, 5.1815583, 5.30715, 6.4149083, 5.82245,
5.515425, 6.3654333, 5.8472833, 4.9798917, 5.1833583, 5.5210333,
6.0410667, 5.7377917, 5.2666083, 7.0378167, 7.744175, 5.718725,
7.3220583, 5.24325, 5.3256, 7.2155167, 5.696925, 7.0029667, 5.5235,
6.7261083, 6.2810667, 7.546825, 5.90915, 7.3299167, 6.2227333,
7.147075, 6.9142417, 6.0012083, 6.1725333, 7.29815, 6.7, 6.3454583,
7.2129583, 6.7559833, 5.8115, 6.0756667, 6.458225, 6.9969167,
6.778825, 6.2245833, 8.0809583, 8.875325, 6.7210917, 8.3203,
6.3513, 5.2591333, 7.1404917, 5.6266417, 6.9356, 5.4568, 6.6604,
6.206025, 7.48525, 5.8323667, 7.24635, 6.1446583, 7.066275, 6.8334,
5.9198667, 6.09505, 7.2206583, 6.63085, 6.270075, 7.1397333,
6.689125, 5.7441333, 6.042575, 6.38255, 6.9325833, 6.7175667,
6.1592, 8.00415, 8.8051167, 6.647125, 8.2465667, 6.2788167, 6.49435,
8.1847583, 6.664475, 8.0528583, 6.6822417, 7.376, 7.1517833,
8.2306833, 6.8584583, 8.3052167, 7.288375, 8.2758583, 7.7162583,
7.2807833, 7.0459, 8.2507833, 7.5855, 7.0505917, 8.2230167, 8.1669,
6.8184667, 6.9700583, 7.0936167, 7.7615667, 7.6239083, 7.0921667,
9.02585, 9.3416167, 7.6256333, 9.0869333, 8.0984667, 4.116325,
6.1680917, 4.56965, 5.797725, 4.36085, 5.42455, 5.144075, 6.1531833,
4.77825, 6.2533417, 5.0192083, 5.99395, 5.6934083, 4.9074167,
4.9823083, 5.9861667, 5.4068833, 5.1872833, 6.10095, 5.659325,
4.6632833, 4.86315, 5.221775, 5.5878, 5.3217083, 4.8202333, 6.4883083,
6.69355, 4.952075, 6.7075583, 5.00015, 5.2502833, 7.2591, 5.6425417,
6.889925, 5.353675, 6.50635, 6.260675, 7.4236583, 5.9076417,
7.3915, 6.2134917, 7.1645333, 6.922675, 6.0295417, 6.1687917,
7.2771083, 6.6152333, 6.3299417, 7.167325, 6.647275, 5.726475,
5.93905, 6.2888583, 6.7497167, 6.4364083, 5.8906583, 7.6052917,
8.039425, 6.5672833, 7.8754667, 6.3086333, 5.352025, 7.2849417,
5.7184833, 6.9675917, 5.5615333, 6.6157917, 6.3505417, 7.4881,
6.0007417, 7.5110583, 6.35525, 7.254075, 7.0289083, 6.1994417,
6.2860833, 7.372575, 6.735975, 6.4628917, 7.3102167, 6.8619417,
5.9123667, 6.1611917, 6.4854083, 6.8942417, 6.563625, 6.0610083,
7.941625, 8.6969167, 6.66075, 8.1197167, 6.2802, 3.9638, 5.870825,
4.1852, 5.5841417, 4.3007583, 5.2352167, 4.4281417, 5.819425,
4.1990917, 5.9338917, 4.89765, 5.7204333, 5.6546833, 4.5632167,
4.9803333, 5.6962417, 5.247725, 4.7092583, 6.0145417, 5.6403917,
4.4016917, 4.7181, 4.5007833, 5.2828917, 5.1314167, 4.7492, 6.777575,
6.9040083, 4.9760583, 6.4471917, 5.0952833, 3.712725, 5.8215333,
4.025725, 5.5635, 4.2354083, 5.143525, 4.4900083, 5.6802417,
4.1214333, 5.8128, 4.7525583, 5.6412583, 5.5534917, 4.487475,
4.8237833, 5.6156917, 5.0573, 4.5755417, 5.8096083, 5.5252083,
4.3145583, 4.5437417, 4.194675, 5.0100833, 4.8972333, 4.590025,
6.6441417, 6.5789417, 4.6947667, 6.1648167, 4.8517333, 4.1059833,
5.9023167, 4.2812417, 5.6593917, 4.3587583, 5.3359583, 4.983275,
6.0223417, 4.6178333, 6.1545333, 5.0244667, 5.9596, 5.7608833,
4.8875333, 4.9990583, 5.9919333, 5.3157417, 5.0169333, 6.024775,
5.6717167, 4.6372083, 4.8370583, 4.7311333, 5.3704, 5.133575,
4.7174917)), .Names = "x", row.names = c(NA, -455L), class = "data.frame")
Updated after some comments:
Since you state that the minimum number of cases in each group would be fine for you, I'd go with Hmisc::cut2
v <- rnorm(10, 0, 1)
Hmisc::cut2(v, m = 3) # minimum of 3 cases per group
The documentation for cut2 states:
m desired minimum number of observations in a group.
The algorithm does not guarantee that all groups will have at least m observations.
The same cuts for separate variables
If the distributions of your variables are very similar you could extract the exact cutpoints by setting the argument onlycuts = T and reuse them for the other variables. In case the distributions are different though, you will end up with few cases in some intervals.
Using your data:
library(magrittr)
library(Hmisc)
cuts <- cut2(df1$x, g = 20, onlycuts = T) # determine cuts based on df1
cut2(df1$x, cuts = cuts) %>% table
cut2(df2$x, cuts = cuts) %>% table*2 # multiplied by two for better comparison
This is a good example of how NOT to pose a question. At last we have an example an, it is possible to post code that applies to it. (You apparently naively pasted the exact code in my comment without thinking about how to express 'n' and 'N' in the context of the problem. I did need to add prob=c( seq(...) , 1) in order to capture the highest values.
This assumes that you want groups of size 100 (although it is still very unclear why this is needed).
x$xct <- cut( x$x, breaks=quantile(x$x, prob=c( seq(100, length(x$x), by=100)/length(x$x) , 1) ))
table(x$xct)
(4.64,5.17] (5.17,5.57] (5.57,5.85] (5.85,6.17] (6.17,6.51] (6.51,6.85]
100 100 100 100 100 100
(6.85,7.26] (7.26,7.94] (7.94,9.36]
100 100 62