R confint method very slow - r

Here is the code sample
cq = c(15.5193589369923,15.6082097993496,15.3048276641115,15.887944383963,15.3813224284544,14.9723432922121,14.8742353464212,15.0448020475332,15.1584221729435,15.3692219904727,15.2369219681739,15.0804950645883,15.0836397511495,14.8821059462034,14.6827696388115,14.5701385743889,14.8506248103639,14.8475325690146,14.7377458445001,14.6258765734272,15.3585770134881,15.2994209401567,15.5178103826596,15.2411668198437,15.3413307248142,15.3645926457095,15.2241340874265,15.7516405898009,15.7683360263607,15.5852354340738,14.7451372367313,14.650625258402,14.7596201108925,15.0504977144055,15.0178091754821,15.100874342289,14.5156700740607,15.0530667717479,14.754595621435,15.5879633065185,15.3449828894141,15.3112460363113,15.232600495493,15.4378070492087,15.1621663266126,16.0120124580213,16.2104534293435,16.2765899877946,17.1446379330444,17.1717364140053,17.0155350105157,15.5218922723681,15.4543443324508,15.5282690363252,15.0202919978723,15.0410524376083,15.1169661551775,15.335220483258,15.3191814464955,15.0679651604846,14.7270263787123,14.70717761566,14.7907442084919,15.8468089268423,15.6714073529734,15.5478017041242,14.6949593095613,14.7537769900696,14.830942214569,15.0820225358985,15.3454125813989,15.304399073517,15.4159319040107,16.1250033895004,15.5359407225865,15.3251900155103,15.1571914994646,15.412721442436,15.913112918988,15.9852823695227,16.0912887332562,15.4897399161851,15.0710262650299,15.3517226832146,17.0001128578501,17.1040579605654,16.9578316599788,15.8842918497549,15.7016383123704,15.8513519332371,16.9420990886101,17.0793832045434,16.9288868492911,14.9127628979216,14.7689529893246,15.0534122173222,15.3185448628303,15.5507864243439,15.3737185073511,15.4350799532271,15.2414612478027,15.361320770232,15.7401140808761,15.8582795450189,15.7634036480016,15.5797995263497,15.9126261329496,15.9256641722586,15.1308493265056,15.2450158090279,15.0699176510971,15.0368959001792,14.8828877909216,14.8852035927172,15.8253506435753,15.8938440960183,15.888311876759,15.4872886586516,15.5492199156675,15.7313291529313,16.5365758222542,16.8386981731158,16.7239280992675,15.9356391540897,15.7383049532238,15.9409000309973,15.2005952554035,15.0390142751348,15.154888655127,14.6373767323354,14.3087397097081,14.3970067065903,14.6453627024929,14.8109205614192,14.6266778290643,15.5170574352528,15.359943766027,15.5869322081508,15.5246550838727,15.4670382654415,15.4211907882731,16.9534561402918,17.4848334482537,17.3182067272327,15.7804318020053,15.86794322314,15.6532944587946,16.543432367992,16.6848617423114,16.8344939905775,15.5212254647114,15.8348559815603,15.6592827767612,15.3027400892518,15.5498124465958,15.8362202772445,14.8415823671167,15.7307379811374,14.8529575353737,16.6466266958983,16.1687733596343,16.0342973266029,14.5976161739123,14.776507726931,14.6780484406283,15.3927619991024,15.3106866267163,15.2920260038624,15.9666798099925,16.2595244266754,16.1035265916681,16.018233002759,15.8460056716414,16.0722176294152,16.2763177549617,16.364250121284,16.2995041975045,16.3975912697976,16.182759197402,16.1164022801451,16.5026752161837,16.2401540005223,16.3715573563274,18.4119769797938,18.1208386122385,18.0068316479116,17.1455993749728,17.0558275544137,16.9150038143768)
sample = c("CD4 LM","CD4 LM","CD4 JC","CD4 JC","CD4 JC","CD4 BM","CD4 BM","CD4 BM","CD4 MC","CD4 MC","CD4 MC","CD4 TM","CD4 TM","CD4 TM","CD4 MM","CD4 MM","CD4 MM","CD4 SRits","CD4 SRits","CD4 SRits","CD4 GV","CD4 GV","CD4 GV","CD4 WW","CD4 WW","CD4 WW","CD4 CH","CD4 CH","CD4 FJ","CD4 FJ","CD4 KS","CD4 KS","CD4 KS","CD4 NG","CD4 NG","CD4 NG","CD4 CG","CD4 CG","CD4 CG","CD4 CSR","CD4 CSR","CD4 CSR","CD4 JM","CD4 JM","CD4 JM","CD4 DF","CD4 DF","CD4 DF","CD4 AM","CD4 AM","CD4 AM","CD4 BP","CD4 BP","CD4 BP","CD4 ER","CD4 ER","CD4 ER","CD4 SRusse","CD4 SRusse","CD4 SRusse","CD4 DS","CD4 DS","CD4 DS","CD4 KJ","CD4 KJ","CD4 KJ","CD4 GD","CD4 GD","CD4 GD","CD4 KG","CD4 KG","CD4 KG","CD4 KR","CD4 KR","CD4 KR","CD4 FN","CD4 FN","CD4 FN","CD4 RM","CD4 RM","CD4 RM","CD4 LA","CD4 LA","CD4 LA","CD4 EC","CD4 EC","CD4 EC","CD4 KW","CD4 KW","CD4 KW","CD4 HB","CD4 HB","CD4 HB","CD8 LM","CD8 LM","CD8 LM","CD8 JC","CD8 JC","CD8 JC","CD8 BM","CD8 BM","CD8 BM","CD8 MC","CD8 MC","CD8 MC","CD8 TM","CD8 TM","CD8 TM","CD8 MM","CD8 MM","CD8 MM","CD8 SRits","CD8 SRits","CD8 SRits","CD8 GV","CD8 GV","CD8 GV","CD8 WW","CD8 WW","CD8 WW","CD8 CH","CD8 CH","CD8 CH","CD8 FJ","CD8 FJ","CD8 FJ","CD8 KS","CD8 KS","CD8 KS","CD8 NG","CD8 NG","CD8 NG","CD8 CG","CD8 CG","CD8 CG","CD8 CSR","CD8 CSR","CD8 CSR","CD8 JM","CD8 JM","CD8 JM","CD8 DF","CD8 DF","CD8 DF","CD8 AM","CD8 AM","CD8 AM","CD8 BP","CD8 BP","CD8 BP","CD8 ER","CD8 ER","CD8 ER","CD8 SRusse","CD8 SRusse","CD8 SRusse","CD8 DS","CD8 DS","CD8 DS","CD8 KJ","CD8 KJ","CD8 KJ","CD8 GD","CD8 GD","CD8 GD","CD8 KG","CD8 KG","CD8 KG","CD8 KR","CD8 KR","CD8 KR","CD8 FN","CD8 FN","CD8 FN","CD8 RM","CD8 RM","CD8 RM","CD8 LA","CD8 LA","CD8 LA","CD8 EC","CD8 EC","CD8 EC","CD8 KW","CD8 KW","CD8 KW","CD8 HB","CD8 HB","CD8 HB")
df = data.frame(cq, sample)
df.res <- lm(cq~sample, data = df)
require(lsmeans)
t<- pairs(lsmeans(df.res, "sample"))
system.time(tc <- confint(t, level=0.95))
The time taken by the confint function is
user system elapsed
10.58 0.00 10.60
I have tried using confint.default but I get an error
tc <- confint.default(t, level=0.95)
Error: $ operator not defined for this S4 class

It's a bit buried in the documentation, but what's slowing you down is the multiple-comparisons correction computations. There's wide variation in the elapsed time for the available methods. See the Confidence-limit and P-value adjustments section of ?summary.ref.grid for details, and decide which method meets your criteria of being both fast enough and reliable enough for your use case ...
adj <- c("tukey","scheffe","sidak","bonferroni","dunnettx","mvt")
sapply(adj,function(a) system.time(confint(t,adjust=a))["elapsed"])
## tukey.elapsed scheffe.elapsed sidak.elapsed bonferroni.elapsed
9.256 0.195 0.168 0.173
## dunnettx.elapsed mvt.elapsed
14.370 1.821

Here is a fast way:
confint(t,method="Wald")

Related

Calculation of Akaike Information Criterion

My data file is given below.
Expt. (Col 1:2) Fit1 (Col 3:4) Fit2 (Col 5:6)
x_expt. y_expt x_fit y_fit x_fit y_fit
2.89394 3.04606 2.95515 3.14485 2.96485 3.16485
2.90727 3.22788 2.96788 3.31939 2.97758 3.34061
2.92788 3.42545 2.98242 3.50303 2.99212 3.52606
2.97576 3.62303 2.99818 3.69758 3.00788 3.72182
2.97394 3.84182 3.01576 3.90182 3.02545 3.92848
3.00061 4.06364 3.03515 4.11818 3.04485 4.14606
3.02788 4.29939 3.05636 4.34545 3.06606 4.37515
3.05758 4.54848 3.08 4.58545 3.0897 4.61697
3.09455 4.80424 3.10606 4.83818 3.11576 4.87212
3.12909 5.07818 3.13515 5.10424 3.14485 5.14061
3.1697 5.37152 3.16667 5.38485 3.17758 5.42364
3.20727 5.65333 3.20182 5.68061 3.21273 5.72182
3.25394 5.98 3.24061 5.99152 3.25212 6.03576
3.30061 6.30909 3.28364 6.32121 3.29576 6.36364
3.35697 6.66061 3.33091 6.66667 3.34364 6.71515
3.41212 7.0303 3.38242 7.02424 3.39636 7.07879
3.47273 7.41818 3.44 7.40606 3.45455 7.46667
3.54606 7.82424 3.50303 7.81212 3.51818 7.87273
3.62242 8.24848 3.57212 8.2303 3.58909 8.29697
3.69939 8.69697 3.64788 8.67879 3.66667 8.74545
3.79212 9.16364 3.73152 9.14545 3.75212 9.21212
3.8903 9.66061 3.82364 9.6303 3.84545 9.70909
4.00242 10.1818 3.92424 10.1455 3.94848 10.2242
4.13212 10.6909 4.03455 10.6849 4.06121 10.7697
4.29697 11.2667 4.15576 11.2546 4.18485 11.3394
4.39273 11.8909 4.28788 11.8485 4.32061 11.9394
4.5503 12.5091 4.43273 12.4727 4.46848 12.5636
4.72061 13.2 4.59152 13.1212 4.63091 13.2242
4.89152 13.8424 4.76424 13.8061 4.80788 13.9091
5.07818 14.5636 4.95333 14.5212 5.00061 14.6303
5.30303 15.3212 5.15879 15.2667 5.21091 15.3818
5.54606 16.0788 5.38303 16.0485 5.44 16.1636
5.79212 16.8909 5.62667 16.8667 5.68848 16.9879
6.07273 17.7273 5.89212 17.7212 5.95939 17.8424
6.35152 18.6303 6.18182 18.6121 6.25455 18.7333
6.67879 19.5394 6.49091 19.5394 6.5697 19.6667
6.99394 20.4727 6.8303 20.503 6.91515 20.6364
7.42424 21.4485 7.19394 21.5091 7.28485 21.6424
7.73939 22.497 7.59394 22.5515 7.69091 22.6909
8.17576 23.5879 8.01818 23.6424 8.12121 23.7758
8.64242 24.7091 8.47879 24.7697 8.58788 24.903
9.12727 25.8242 8.97576 25.9394 9.09091 26.0788
9.59394 27.0727 9.50909 27.1515 9.6303 27.2909
10.1636 28.297 10.0788 28.4061 10.2061 28.5455
10.6909 29.5212 10.6909 29.7091 10.8242 29.8424
11.3939 31.0121 11.3455 31.0485 11.4909 31.1818
12.1152 32.4121 12.0485 32.4364 12.1939 32.5697
12.903 33.8667 12.8 33.8667 12.9455 34
13.6364 35.3515 13.5939 35.3455 13.7515 35.4667
14.4303 36.8546 14.4485 36.8606 14.6 36.9818
15.2849 38.5515 15.3515 38.4242 15.503 38.5394
16.2606 40.1939 16.3091 40.0303 16.4606 40.1455
17.2364 41.8909 17.3212 41.6788 17.4788 41.7879
18.3212 43.7091 18.3939 43.3697 18.5455 43.4727
19.4667 45.5576 19.5273 45.103 19.6788 45.2061
20.5152 46.8849 20.7212 46.8788 20.8667 46.9758
22.0606 49.1758 21.9818 48.6909 22.1152 48.7939
23.3152 51.1879 23.303 50.5515 23.4303 50.6485
24.7212 53.1576 24.6909 52.4485 24.8061 52.5455
26.2121 55.4727 26.1455 54.3879 26.2485 54.4849
a). Col 1:2 represent experimental data.
b). Col 3:4 is fitted data using non-linear least squares fitting using 4 adjustable parameters.
c). Col 5:6 is fitted data using non-linear least squares fitting using 5 adjustable parameters with one parameter fixed to 0.
I wish to calculate AIC for both the fits and conclude which fit is better. Can anybody suggest how to solve this problem in R or Excel?

R: The 61928th question about the "singular gradient matrix at initial parameter estimates" error message

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.

Bootstrap p value contradicts p value for likelihood ratio test

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.

Numerical integration in R : bad integrand behaviour error

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.

Suggestion for curve fitting

I have this set of data:
X: Y:
0. 0.
0.001417162 0.0118
0.002352761 0.0128
0.003123252 0.0135
0.003866221 0.0138
0.004045083 0.0147
0.005544762 0.0151
0.006260197 0.0156
0.007195755 0.0157
0.007883656 0.0158
0.008805432 0.0159
0.009314465 0.0165
0.010566391 0.0168
0.011047891 0.0186
0.011666955 0.0177
0.012341036 0.0225
0.013193938 0.0399
0.013854235 0.087
0.014500764 0.1479
0.015381122 0.198
0.015601208 0.2586
0.01638525 0.3111
0.016976706 0.3693
0.017691939 0.42
0.018338382 0.4737
0.018861027 0.5223
0.01963122 0.5691
0.021625353 0.6183
0.020923988 0.6684
0.021377815 0.711
0.021927895 0.7551
0.022574222 0.7938
0.023633053 0.8382
0.023646804 0.8742
0.024279325 0.912
0.025131822 0.9495
0.0256543 0.9891
0.026094271 1.0215
0.026685464 1.0596
0.027345378 1.098
0.028101497 1.1328
0.028513912 1.1739
0.029077528 1.1997
0.029723601 1.2339
0.030355902 1.2741
0.031056901 1.3041
0.031428005 1.3383
0.032087723 1.3665
0.032692438 1.3983
0.033242157 1.4262
0.033846824 1.4589
0.034410239 1.4877
0.035248448 1.5222
0.035729364 1.5534
0.036430096 1.5861
0.037034618 1.6179
0.037694064 1.6536
0.038408425 1.6842
0.039067798 1.7121
0.039521096 1.7427
0.040207877 1.7763
0.04071607 1.8075
0.041279177 1.8381
0.04129291 1.8711
0.042707418 1.9065
0.043366544 1.9332
0.043860863 1.9659
0.044368889 1.9959
0.045055371 2.0202
0.045700624 2.0487
0.04626347 2.0796
0.047059639 2.1105
0.047540055 2.1339
0.048308673 2.1618
0.048857648 2.1849
0.049557546 2.2203
0.050229948 2.2425
0.052082233 2.2716
0.051355084 2.2983
0.051945039 2.3193
0.052466363 2.3475
0.053371748 2.3718
0.053851839 2.3937
0.054647359 2.4189
0.055072521 2.4372
0.055675941 2.4633
0.056306742 2.4882
0.057060898 2.5131
0.057691594 2.5332
0.058582712 2.5527
0.059007671 2.5755
0.059597094 2.5941
0.060172767 2.6115
0.065187502 2.6403
0.06131028 2.6592
0.061968042 2.6808
0.062598344 2.6991
0.063173791 2.7246
0.063790292 2.7441
0.064393043 2.7633
0.065091624 2.7795
0.065502522 2.8011
0.066433804 2.8212
0.066598135 2.8368
0.067351271 2.8545
0.067981104 2.8665
0.068610879 2.8845
0.069309041 2.9046
0.069870256 2.9214
0.070253498 2.9355
0.070828319 2.9499
0.07159467 2.9691
0.072046228 2.9856
0.072620893 2.9982
0.07326391 3.0108
0.073893183 3.0255
0.074467682 3.0387
0.075165218 3.0531
0.075862676 3.0654
0.076395973 3.0735
0.077230012 3.0879
0.077571798 3.0996
0.077968246 3.1116
0.078720058 3.1251
0.079485442 3.1332
0.080168736 3.1473
0.080797297 3.1524
0.081671703 3.1647
0.082518656 3.1761
0.082737205 3.1794
0.083242565 3.1911
0.083843476 3.207
0.084594523 3.2157
0.083993693 3.2217
0.086028058 3.2313
0.086806105 3.2412
0.087515804 3.2475
0.087979788 3.2562
0.089221428 3.2658
0.089289641 3.2727
0.090053572 3.2823
0.090599168 3.285
0.091485638 3.2988
0.092508299 3.3006
0.092794607 3.309
0.093585278 3.3177
0.094443969 3.3255
0.095029975 3.336
0.095752165 3.3381
0.096378886 3.3468
0.097182604 3.3498
0.097781901 3.3573
0.098585385 3.3612
0.099238967 3.3702
0.102192566 3.372
0.100464189 3.3816
0.101226388 3.3879
0.101961246 3.396
0.102519116 3.4038
0.103335387 3.4113
0.103920292 3.4134
0.104777107 3.4206
0.105416212 3.423
0.105932869 3.4308
0.106952407 3.4353
0.107550426 3.4431
0.108284246 3.4479
0.108759804 3.4539
0.109439081 3.4587
0.110118251 3.4662
0.11096027 3.4701
0.111802122 3.4749
0.112182257 3.4857
0.113132445 3.4902
0.113878868 3.4929
0.114530181 3.5028
0.11465229 3.5076
0.116063069 3.513
0.116619106 3.5181
0.117378448 3.5247
0.118246089 3.5295
0.118869589 3.5286
0.119479439 3.5364
0.120292424 3.5451
0.120807227 3.5511
0.121728283 3.5565
0.122283519 3.5625
0.123068837 3.5622
0.123745705 3.5691
0.124544254 3.5775
0.125247919 3.5796
0.125924395 3.5868
0.126614273 3.5892
0.128683133 3.5958
0.127993643 3.5991
0.128602023 3.6057
0.129507645 3.6093
0.130115772 3.6132
0.130669753 3.6156
0.131682911 3.6222
0.132263658 3.6234
0.132911821 3.6288
0.133870342 3.6291
0.136717348 3.6336
0.13504451 3.6396
0.135692157 3.6372
0.13621828 3.6432
0.137068001 3.6465
0.141030546 3.6522
0.138470251 3.6501
0.139009423 3.6567
0.140181824 3.6615
0.140532116 3.6633
0.141124835 3.6588
0.141717448 3.6675
0.14257924 3.6711
0.143319661 3.6741
0.143844585 3.6729
0.144813453 3.6753
0.145243967 3.678
0.1472209 3.6849
0.14672342 3.6879
0.147301565 3.6888
0.147866163 3.6933
0.148403782 3.6927
0.149277216 3.6972
0.149962355 3.7011
0.151922897 3.7077
0.151426165 3.7023
0.152070559 3.7089
0.153251595 3.7107
0.153587034 3.7134
0.15429804 3.7191
0.154861361 3.7191
0.155706144 3.7221
0.157086785 3.7206
0.157086785 3.7272
0.156925966 3.7269
0.158480178 3.7335
0.15912306 3.7272
0.159618519 3.7356
0.160381629 3.7359
0.161171304 3.7386
0.161853731 3.7377
0.162415608 3.7398
0.163151233 3.7437
0.163993625 3.7443
0.165062969 3.7533
0.165330242 3.7509
0.166065112 3.7512
0.166866568 3.7569
0.167494215 3.7635
0.168108371 3.7569
0.168829162 3.7638
0.169536423 3.7626
0.173429745 3.7581
0.171070418 3.7617
0.171803762 3.7653
0.172790131 3.7635
0.172936723 3.7644
0.174029244 3.7695
0.174761783 3.7701
0.175334355 3.7668
0.176173017 3.7704
0.176705362 3.7722
0.177490375 3.7701
0.178261854 3.774
0.178979922 3.7797
0.178793775 3.78
0.180774223 3.7887
0.182394664 3.8301
0.18451827 3.8169
0.186282158 3.8067
0.186772642 3.7731
0.188058046 3.7782
0.188587916 3.7734
0.189395747 3.7749
0.189885613 3.7707
0.190560674 3.7734
0.191447234 3.7752
0.192280569 3.7713
0.193007849 3.7704
0.193946376 3.7701
0.194329613 3.7734
0.195188367 3.7647
0.195716677 3.7644
0.196416507 3.7683
0.197142527 3.7695
0.197709986 3.7596
0.198923623 3.7662
0.199714786 3.7617
0.200189355 3.7626
0.2011382 3.7683
0.201915434 3.7665
0.202310538 3.7599
0.203258508 3.7656
0.204153451 3.7569
0.204903352 3.753
0.205311089 3.7512
0.206192075 3.753
0.207033292 3.7461
0.207966146 3.7539
0.208478393 3.7473
0.209318747 3.7425
0.210119413 3.7455
0.21077548 3.7443
0.21140512 3.7425
0.21234924 3.7443
0.213122589 3.7461
0.213751552 3.7443
0.214498207 3.7422
0.215192234 3.7425
0.216030006 3.7395
0.216762788 3.7437
0.217508397 3.7377
0.218096851 3.7446
0.223098604 3.7383
0.219547672 3.7386
0.220187807 3.7395
0.220906094 3.7386
0.221872127 3.7368
0.222381072 3.7404
0.223111647 3.7374
0.223789808 3.7365
0.224207027 3.7278
0.225288796 3.7359
0.225862032 3.7326
0.226487197 3.7368
0.226396039 3.7302
0.227775995 3.7308
0.228426593 3.7287
0.229115997 3.7278
0.229063975 3.7269
0.230312139 3.726
0.23101389 3.7104
plot(x,y)
Can you please give me suggestions of models (I've tried polynomials and I either get a bad fit or a overfit). Thanks!
Just monkeying around in Python/Numpy for a few minutes, it looks like you want a formula like
Yfit(x) = Ymax * (1 - exp(-(x-x0)/a) )
x0 is where the data starts to take off from zero. Looks like x0 = 0.012 give or take a little. Ymax is the maximum value. The parameter a sets how fast the curve rises, and it look like you want a = 0.007 or so.
Polynomials are bad for any data that levels off and holds steady before or after the interesting parts. Polynomials like to wiggle, like a snake trying to go through lined-up croquet wickets. Even fitting loosely with least-squares or whatever, polynomials don't like flatness. But the shape sure looks like a constant minus a decaying exponential - very common in electronics and physics.
The initial zero values, I take to be meaningless and not needing fitting. The Yfit values you get could be clipped to zero when negative, for plotting and comparison.
If exp(-(x-x0)/a) doesn't work well enough, you could try other functions that quickly fade to zero, such as 1/(1+x^p) for some power p>=2, or use a Gaussian exp(-(x-x0)^2 / a^2)
I actually see a slight curve - the Y values go up to max, and then slightly back down. Maybe add a quadratic term to your model, like:
Y_extra_term(x) = ((x-xmax)/b)^2
where xmax is the x value where y is maximum.
(BTW, I'm no expert on R, so use the correct syntax not whatever I write.)

Resources