[R] CI with confint
peter dalgaard
pdalgd at gmail.com
Wed Mar 28 22:48:17 CEST 2012
On Mar 28, 2012, at 21:33 , Benjamin Caldwell wrote:
> Hello all,
>
> I'm trying to use confint from the MASS package to compute confidence
> intervals for an nls object. When I plot the results, however, they don't
> make sense - lines cross over the fitted model or just don't match the
> data. Code is :
>
> Thanks for help
>
> dat<-data.frame(a,b)
> with(dat, plot(a,b))
> model<-(nls(b~(1/exp(a*x))*n, data=dat, start=list(x=.001,n=20),
> na.action="na.omit"))
> with(dat, plot(a,b))
> x1<-summary(model)$coefficients[1,1]
> n1<-summary(model)$coefficients[2,1]
> lines((1/exp(c(0:30)*x1)*n1))
> int<-MASS:::confint.nls(model)
> lines((1/exp(c(0:30)*int[1,1])*int[2,1]),lty=2)
> lines((1/exp(c(0:30)*int[2,1])*int[2,2]),lty=2)
>
Looks like you just haven't understood how CI's work. There's no reason to believe that you can combine the extremes of confidence intervals for two parameters and get an interval for a fitted value. For one thing, it is quite common that a simultaneous confidence region for two parameters is like a narrow ellipse due to correlation of the estimates.
This is a matter of statistical theory, not of R.
The last lines() look just unintended, btw. Shouldn't int[2,1] be [1,2]??
> "","a"
> "1",NA
> "2",5.8
> "3",5.15
> "4",NA
> "5",5.7
> "6",12.35
> "7",10.9
> "8",10.65
> "9",18.7
> "10",5.35
> "11",12
> "12",NA
> "13",14.8
> "14",13.3
> "15",15.6
> "16",19.8
> "17",NA
> "18",NA
> "19",NA
> "20",NA
> "21",NA
> "22",NA
> "23",NA
> "24",NA
> "25",NA
> "26",NA
> "27",NA
> "28",NA
> "29",7.1
> "30",NA
> "31",NA
> "32",15.15
> "33",NA
> "34",11.6
> "35",NA
> "36",NA
> "37",6.35
> "38",18.45
> "39",16.65
> "40",NA
> "41",9.8
> "42",7.35
> "43",7.35
> "44",11.55
> "45",18.1
> "46",5.65
> "47",4.25
> "48",NA
> "49",6.45
> "50",5.2
> "51",5.45
> "52",NA
> "53",NA
> "54",9.8
> "55",6.35
> "56",21.95
> "57",NA
> "58",NA
> "59",11.4
> "60",NA
> "61",NA
> "62",10.65
> "63",NA
> "64",NA
> "65",4.8
> "66",7.35
> "67",17.55
> "68",5.55
> "69",8.8
> "70",8.3
> "71",10.8
> "72",11.1
> "73",5.3
> "74",NA
> "75",NA
> "76",7.55
> "77",8.5
> "78",NA
> "79",21.55
> "80",NA
> "81",7
> "82",5.4
> "83",NA
> "84",NA
> "85",7.45
> "86",5.5
> "87",8.05
> "88",16.35
> "89",5.25
> "90",6.85
> "91",4.7
> "92",3.25
> "93",5.45
> "94",8.15
> "95",2.9
> "96",3.05
> "97",7.9
> "98",6.2
> "99",5.85
> "100",6.7
> "101",17.45
> "102",4.3
> "103",9.85
> "104",12.6
> "105",12.75
> "106",3.95
> "107",NA
> "108",14.4
> "109",7.4
> "110",NA
> "111",4.95
> "112",4.75
> "113",4.2
> "114",5.5
> "115",6.2
> "116",9.6
> "117",NA
> "118",12.95
> "119",9.1
> "120",25.9
> "121",7.55
> "122",12.3
> "123",11.2
> "124",8.35
> "125",NA
> "126",6.95
> "127",20.9
> "128",NA
> "129",NA
> "130",6.75
> "131",6.55
> "132",NA
> "133",10.25
> "134",8.3
> "135",NA
> "136",10.35
> "137",4.8
> "138",12.25
> "139",9.45
> "140",7.55
> "141",5.15
> "142",9
> "143",4.95
> "144",NA
> "145",8.4
> "146",6.65
> "147",11.15
> "148",7.65
> "149",NA
> "150",NA
> "151",NA
> "152",NA
> "153",12.95
> "154",NA
> "155",4.6
> "156",4.8
> "157",10.95
> "158",4.25
> "159",4.1
> "160",5.3
> "161",3.8
> "162",12.75
> "163",NA
> "164",10.8
> "165",NA
> "166",8.65
> "167",25.45
> "168",NA
> "169",7.65
> "170",18.4
> "171",9.1
> "172",5.7
> "173",6.15
> "174",NA
> "175",NA
> "176",4.5
> "177",8.45
> "178",NA
> "179",NA
> "180",NA
> "181",8.55
> "182",9.15
> "183",12.9
> "184",27.65
> "185",NA
> "186",8.3
> "187",12.8
> "188",NA
> "189",5.85
> "190",NA
> "191",7
> "192",11.65
> "193",8.15
> "194",24.45
> "195",15.25
> "196",10.5
> "197",NA
> "198",3.6
> "199",NA
> "200",5.55
> "201",NA
> "202",10.3
> "203",NA
> "204",4.6
> "205",5.95
> "206",10.15
> "207",5.7
> "208",23.2
> "209",11.95
> "210",NA
> "211",6.05
> "212",5.55
> "213",NA
> "214",NA
> "215",NA
> "216",NA
> "217",16.4
> "218",4.65
> "219",16.35
> "220",7.95
> "221",7.45
> "222",NA
> "223",7.9
> "224",21.15
> "225",NA
> "226",NA
> "227",NA
> "228",11.15
> "229",9.15
> "230",11.35
> "231",4.75
> "232",3.85
> "233",NA
> "234",5.05
> "235",NA
> "236",12.7
> "237",6.35
> "238",NA
> "239",NA
> "240",NA
> "241",10.15
> "242",5.15
> "243",NA
> "244",NA
> "245",6.4
> "246",7.15
> "247",NA
> "248",16.5
> "249",NA
> "250",NA
> "251",NA
> "252",7.15
> "253",6.7
> "254",NA
> "255",NA
> "256",NA
> "257",NA
> "258",NA
> "259",NA
> "260",NA
> "261",4.1
> "262",4.55
> "263",4.45
> "264",NA
> "265",7.2
> "266",6.1
> "267",6
> "268",NA
> "269",8.75
> "270",NA
> "271",5.6
> "272",NA
> "273",NA
> "274",NA
> "275",NA
> "276",NA
> "277",NA
> "278",NA
> "279",NA
> "280",NA
> "281",NA
> "282",NA
> "283",NA
> "284",NA
> "285",NA
> "286",NA
> "287",NA
> "288",8.1
> "289",NA
> "290",NA
> "291",NA
> "292",NA
> "293",NA
> "294",NA
> "295",NA
> "296",NA
> "297",8.15
> "298",7.7
> "299",NA
> "300",NA
> "301",26.75
> "302",21
> "303",10.45
> "304",NA
> "305",6.7
> "306",20.5
> "307",NA
> "308",10.5
> "309",NA
> "310",NA
> "311",NA
> "312",NA
> "313",NA
> "314",5.65
> "315",12.75
> "316",5
> "317",5.85
> "318",3.55
> "319",4.05
> "320",6.4
> "321",4.75
> "322",NA
> "323",NA
> "324",NA
> "325",2.75
> "326",NA
> "327",4.9
> "328",5.05
> "329",5.3
> "330",NA
> "331",NA
> "332",NA
> "333",NA
> "334",NA
> "335",6.95
> "336",6.4
> "337",6.1
> "338",NA
> "339",11.75
> "340",3.35
> "341",7.45
> "342",6.9
> "343",5.75
> "344",6.1
> "345",NA
> "346",NA
> "347",5
> "348",5.85
> "349",NA
> "350",5.5
> "351",6.65
> "352",11.1
> "353",10.95
> "354",16.6
> "355",7.2
> "356",6.5
> "357",NA
> "358",8.45
> "359",NA
> "360",8.3
> "361",17.05
> "362",NA
> "363",NA
> "364",NA
> "365",NA
> "366",12.7
> "367",NA
> "368",8.05
> "369",9.7
> "370",NA
> "371",12.35
> "372",4.85
> "373",5.5
> "374",NA
> "375",4.9
> "376",NA
> "377",NA
> "378",15.05
> "379",NA
> "380",NA
> "381",8.4
> "382",NA
> "383",NA
> "384",5.15
> "385",11.4
> "386",NA
> "387",8
> "388",7.45
> "389",8.7
> "390",9.05
> "391",15.1
> "392",NA
> "393",NA
> "394",NA
> "395",NA
> "396",7.4
> "397",10.6
> "398",20.2
> "399",10.95
> "400",7.6
> "401",NA
> "402",NA
> "403",NA
> "404",8.3
> "405",9.65
> "406",14.75
> "407",NA
> "408",2.9
> "409",NA
> "410",NA
> "411",NA
> "412",NA
> "413",NA
> "414",NA
> "415",NA
> "416",2.55
> "417",3.2
> "418",4.05
> "419",9.05
> "420",3.25
> "421",6.7
> "422",NA
> "423",NA
> "424",NA
> "425",7.25
> "426",NA
> "427",NA
> "428",NA
> "429",8.8
> "430",5.05
> "431",3.6
> "432",7.7
> "433",14.45
> "434",10.2
> "435",NA
> "436",NA
> "437",12.95
> "438",8.8
> "439",4.5
> "440",5.3
> "441",17.7
> "442",10.2
> "443",5.55
> "444",3.9
> "445",20
> "446",12.2
> "447",10.8
> "448",NA
> "449",NA
> "450",NA
> "451",NA
> "452",NA
> "453",NA
> "454",NA
> "455",NA
> "456",NA
> "457",NA
> "458",NA
> "459",NA
> "460",NA
> "461",NA
> "462",NA
> "463",NA
> "464",NA
>
>
> "","b"
> "1",NA
> "2",243.085758119756
> "3",274.339641306582
> "4",NA
> "5",418.039560741661
> "6",46.5033624229099
> "7",79.9087810465099
> "8",215.216454070312
> "9",107.035742459874
> "10",278.567219708664
> "11",283.033857603722
> "12",NA
> "13",98.2911978484231
> "14",173.670430606987
> "15",174.110803357204
> "16",95.6489613471215
> "17",NA
> "18",NA
> "19",NA
> "20",NA
> "21",NA
> "22",NA
> "23",NA
> "24",NA
> "25",NA
> "26",NA
> "27",NA
> "28",NA
> "29",222.264934489499
> "30",NA
> "31",NA
> "32",181.181931517831
> "33",NA
> "34",189.486103379064
> "35",NA
> "36",NA
> "37",389.654391470535
> "38",41.7095904848339
> "39",199.224632198148
> "40",NA
> "41",144.781978192755
> "42",118.095389529608
> "43",97.787914705318
> "44",83.4191809696678
> "45",22.9497113255919
> "46",164.196125438034
> "47",201.514570499276
> "48",NA
> "49",273.786029849166
> "50",350.184410972518
> "51",271.772897276746
> "52",NA
> "53",NA
> "54",57.3742783139797
> "55",135.005703137939
> "56",73.4793388933424
> "57",NA
> "58",NA
> "59",90.5909657589153
> "60",NA
> "61",NA
> "62",204.685254300838
> "63",NA
> "64",NA
> "65",296.182129717343
> "66",237.901941745774
> "67",26.2713800700854
> "68",290.94798502905
> "69",196.657888168312
> "70",117.403375207839
> "71",62.6210050808502
> "72",238.367478653146
> "73",423.550511158662
> "74",NA
> "75",NA
> "76",86.4011335925654
> "77",189.901311972126
> "78",NA
> "79",42.2757840208271
> "80",NA
> "81",269.961077961568
> "82",330.355055134178
> "83",NA
> "84",NA
> "85",109.489247782511
> "86",398.85189091078
> "87",83.9098820341953
> "88",19.099595280838
> "89",335.299812015185
> "90",100.895688113992
> "91",1118.39580060812
> "92",849.554527639962
> "93",719.97170036898
> "94",194.22954700283
> "95",769.06697097888
> "96",616.307954967909
> "97",87.5712669002847
> "98",209.491608317492
> "99",346.485279870696
> "100",209.038653488697
> "101",38.4885783689614
> "102",482.396892666224
> "103",46.6543473658414
> "104",86.0614174709695
> "105",94.6675592180665
> "106",364.691547572522
> "107",NA
> "108",22.1444582966237
> "109",65.2632415821519
> "110",NA
> "111",256.649238826438
> "112",358.488582833752
> "113",167.480047946795
> "114",133.395197080003
> "115",206.497073616016
> "116",309.82110289549
> "117",NA
> "118",58.8841277432949
> "119",135.420911731001
> "120",210.850472803875
> "121",221.130031001797
> "122",124.71356286144
> "123",101.575120357184
> "124",122.952071860572
> "125",NA
> "126",168.29788305434
> "127",58.3305162858794
> "128",NA
> "129",NA
> "130",181.559393875159
> "131",331.311293106077
> "132",NA
> "133",109.86671013984
> "134",121.039595916773
> "135",NA
> "136",85.2561644420014
> "137",312.664652654034
> "138",65.5274652322821
> "139",101.91483647878
> "140",167.593286653993
> "141",280.265800316644
> "142",216.462079849497
> "143",548.087924920015
> "144",NA
> "145",131.998586357886
> "146",286.619749998346
> "147",102.141313893177
> "148",117.264972343485
> "149",NA
> "150",NA
> "151",NA
> "152",NA
> "153",113.125468491445
> "154",NA
> "155",352.411438880758
> "156",211.378920104136
> "157",79.3174233533614
> "158",305.392211236165
> "159",379.777459787097
> "160",306.763657801127
> "161",138.264461489544
> "162",57.6510840426875
> "163",NA
> "164",114.05654230619
> "165",NA
> "166",73.3535181075661
> "167",30.1969885863051
> "168",NA
> "169",74.727481088243
> "170",27.4490626249513
> "171",60.5147651269554
> "172",124.529864514207
> "173",324.04388451964
> "174",NA
> "175",NA
> "176",76.7305479978012
> "177",141.76479574984
> "178",NA
> "179",NA
> "180",NA
> "181",249.359182498561
> "182",476.357494948963
> "183",227.926869849431
> "184",17.5796801886606
> "185",NA
> "186",170.49723038971
> "187",282.643813167816
> "188",NA
> "189",641.691040290414
> "190",NA
> "191",63.4136760312407
> "192",275.109664515532
> "193",75.618292251539
> "194",14.305823342762
> "195",38.7276378619363
> "196",25.9694101842224
> "197",NA
> "198",478.408373757116
> "199",NA
> "200",869.069331513861
> "201",NA
> "202",182.314318589817
> "203",NA
> "204",892.29584856816
> "205",305.744509436339
> "206",672.335950874083
> "207",445.707551533863
> "208",12.5317502633166
> "209",38.4759962903837
> "210",NA
> "211",212.57421756901
> "212",331.56293467763
> "213",NA
> "214",NA
> "215",NA
> "216",NA
> "217",34.9152680529153
> "218",328.417415033223
> "219",34.1980895739905
> "220",119.856880530476
> "221",396.637445081118
> "222",NA
> "223",252.358750031467
> "224",9.66303634761762
> "225",NA
> "226",NA
> "227",NA
> "228",168.297883054341
> "229",48.8184648811932
> "230",78.6128269530143
> "231",86.3382231996773
> "232",1503.6967928908
> "233",NA
> "234",723.909890963777
> "235",NA
> "236",15.6017774362576
> "237",166.007944753212
> "238",NA
> "239",NA
> "240",NA
> "241",150.632644731352
> "242",733.182882875488
> "243",NA
> "244",NA
> "245",330.719935412929
> "246",417.133651084072
> "247",NA
> "248",61.7150954232608
> "249",NA
> "250",NA
> "251",NA
> "252",141.800025569858
> "253",183.195064090251
> "254",NA
> "255",NA
> "256",NA
> "257",NA
> "258",NA
> "259",NA
> "260",NA
> "261",864.388798282983
> "262",285.05957225472
> "263",246.118039056964
> "264",NA
> "265",52.3414468829288
> "266",182.767273418611
> "267",432.571861498821
> "268",NA
> "269",169.883224955121
> "270",NA
> "271",69.8934464987186
> "272",NA
> "273",NA
> "274",NA
> "275",NA
> "276",NA
> "277",NA
> "278",NA
> "279",NA
> "280",NA
> "281",NA
> "282",NA
> "283",NA
> "284",NA
> "285",NA
> "286",NA
> "287",NA
> "288",246.357098549939
> "289",NA
> "290",NA
> "291",NA
> "292",NA
> "293",NA
> "294",NA
> "295",NA
> "296",NA
> "297",162.258485337079
> "298",111.980499340881
> "299",NA
> "300",NA
> "301",413.635833239492
> "302",309.745610424024
> "303",337.97979475222
> "304",NA
> "305",567.489490086716
> "306",105.94110162362
> "307",NA
> "308",801.46582331627
> "309",NA
> "310",NA
> "311",NA
> "312",NA
> "313",NA
> "314",91.949830245299
> "315",168.021077325632
> "316",671.958488516754
> "317",119.227776601595
> "318",1396.20809560213
> "319",671.279056273563
> "320",44.8425280506631
> "321",443.669254804288
> "322",NA
> "323",NA
> "324",NA
> "325",504.138724448364
> "326",NA
> "327",183.597690604735
> "328",536.487248471443
> "329",481.30225182997
> "330",NA
> "331",NA
> "332",NA
> "333",NA
> "334",NA
> "335",91.2200696877966
> "336",130.224513278441
> "337",66.1062408468529
> "338",NA
> "339",23.2516812114549
> "340",187.774940692507
> "341",119.215194523017
> "342",246.105456978387
> "343",352.235289780671
> "344",139.77431091886
> "345",NA
> "346",NA
> "347",377.877565921875
> "348",203.011837850014
> "349",NA
> "350",128.941141263523
> "351",347.756069807037
> "352",164.825229366915
> "353",178.791336588081
> "354",123.807653203851
> "355",552.302921243519
> "356",542.539228267281
> "357",NA
> "358",239.059492974915
> "359",NA
> "360",127.267724812698
> "361",245.841233328256
> "362",NA
> "363",NA
> "364",NA
> "365",NA
> "366",188.680850350096
> "367",NA
> "368",271.772897276746
> "369",44.6915431077315
> "370",NA
> "371",263.443561258357
> "372",493.418793500225
> "373",765.493660662834
> "374",NA
> "375",357.960135533491
> "376",NA
> "377",NA
> "378",28.0957814638413
> "379",NA
> "380",NA
> "381",214.436365198499
> "382",NA
> "383",NA
> "384",361.898326128289
> "385",68.8868802125085
> "386",NA
> "387",273.282746706061
> "388",246.860381693044
> "389",468.619516623722
> "390",237.008614166762
> "391",75.8699338230915
> "392",NA
> "393",NA
> "394",NA
> "395",NA
> "396",268.350571903631
> "397",53.9016246265545
> "398",243.048011884023
> "399",94.6801412966441
> "400",485.882128432227
> "401",NA
> "402",NA
> "403",NA
> "404",651.638431613887
> "405",521.099366371005
> "406",149.651242602297
> "407",NA
> "408",524.924318258604
> "409",NA
> "410",NA
> "411",NA
> "412",NA
> "413",NA
> "414",NA
> "415",NA
> "416",549.534863956443
> "417",269.394884425574
> "418",373.889047012767
> "419",93.6861570890115
> "420",257.11477573381
> "421",167.492630025372
> "422",NA
> "423",NA
> "424",NA
> "425",301.34078193417
> "426",NA
> "427",NA
> "428",NA
> "429",143.850904378011
> "430",239.285970389312
> "431",380.104593830115
> "432",181.181931517831
> "433",31.4426143654902
> "434",52.6685809259471
> "435",NA
> "436",NA
> "437",17.6652383229885
> "438",97.1588107764366
> "439",305.744509436339
> "440",332.166874449356
> "441",34.8775218171824
> "442",65.8294351181451
> "443",153.249717075498
> "444",263.279994236848
> "445",15.287225471817
> "446",44.880274286396
> "447",71.6675195781641
> "448",NA
> "449",NA
> "450",NA
> "451",NA
> "452",NA
> "453",NA
> "454",NA
> "455",NA
> "456",NA
> "457",NA
> "458",NA
> "459",NA
> "460",NA
> "461",NA
> "462",NA
> "463",NA
> "464",NA
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list