[R] [cleaned code] RE: AIC() vs. mle.aic() vs. step()?
Alexandra Thorn
alexandra.thorn at tufts.edu
Thu Jun 23 15:47:52 CEST 2011
On Thu, 2011-06-23 at 09:29 -0400, Alexandra Thorn wrote:
> Ok, here's some example code showing how I get different output for
AIC
> vs. mle.aic(). Now that I've taken another look at the independent
> variables, I'm wondering whether missing values in one of the
variables
> might be what is messing me up. I'm going to see if the behavior
> changes when I remove those...
>
Okay, here's the code with dput() used to present the various objects.
Thanks to the list for being so patient with me... it's been quite
educational.
Thanks in advance,
Alexandra
Code:
R> require(wle)
R> dput(xA)
structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L,
1L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
3L, 3L, 1L, 1L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 1L,
2L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 2L, 3L,
3L, 3L, 2L, 3L, 2L, 1L, 1L, 1L, 3L, 3L), .Label = c("Diffuse",
"Other", "Ring"), class = "factor")
R> dput(x5)
c(35.1890162754395, 22.8565556431035, 15.296994438186,
9.60022407772812,
25.0393843292946, 21.179788208, 9.26776603463063, 14.5228279661883,
6.6982273554755, 5.7889657235105, 21.4854296564891, 20.5942435860781,
20.2180106449331, 0.44420165807875, 5.041499147412, 26.984947359545,
14.7613969969327, 10.304583446995, 13.4192477726851, 13.90740846636,
6.721998863216, 13.25694036483, 18.1492698335532, 8.9814627576195,
14.2575003028425, 21.8982502817969, 8.5661573887, 15.343499557995,
7.4060631990625, 10.2824613451941, 23.4777018427811, 35.3389594363836,
51.5448185920973, 6.9571800684925, 23.3166747093435, 35.2280399322705,
53.3812645912466, 44.7933630466069, 25.5658796310335, 9.6980968165235,
2.90031387090862, 4.80738140821225, 6.927406749722, 8.61786424398488,
43.957850260725, 0, 44.1995269203482, 14.68783550262, 5.63854620095413,
0, 21.1687123966326, 20.566941833529, 0, 0, 28.4924849319605,
8.7184162712155, 18.8744437360889, 20.9748315239075, 21.3849539280062,
163.143692522173, 10.85655822755, 9.92978608605625, 0, 0,
41.9369100379775,
121.762594814280, 13.570939755438, 20.1040411710892, 14.1449650049318,
8.2172523975435, 10.16499876975, 19.598117628078, 20.3028116584013,
17.0104638219038, 12.612999143628, 8.20519315482388, 6.42935872078125,
22.1598563909594, 13.9703385210014, 23.0206302023242, 15.25902295115,
14.4778823661717, 2.4819054257875, 21.8293459510672, 25.151516683063,
32.105084991422, 12.5154914474453, 11.6927538156488, 9.40486317871687,
38.4559898615062, 53.195916748074, 14.4917169976215, 10.2548528385015,
8.82271943808338, 12.8573514676201, 10.0589964580665, 12.886892914765,
9.6626724052155, 5.98260608673, 3.25811900139, 13.446737566015,
8.80658397675, 17.773449287436)
R> dput(x15)
c(1.69924629406401, -1.63414400065288, 0.714151689343318,
4.17480342154949,
1.52512663197893, 1.73541067946363, -5.47498002151169,
0.956812825760668,
-1.48092554972038, 1.51101949018443, -2.25838766176389,
2.12958862888441,
1.43795702627435, -4.48003372542488, -3.65963008576897,
-0.763463882139697,
-2.44019862561235, 1.32552846648453, 1.89863804289907,
1.80655970149808,
-0.741756823200407, 1.30112633095768, -1.06424642846912,
-1.47852202054490,
0.090359152072348, NA, NA, 1.82385291704612, -0.153087078076393,
1.0468532207338, 2.45599032439301, 1.36474092834838, -2.39863477181754,
-0.212204468662908, -2.50255033079852, -1.92296430369566,
-0.245775784395867,
-1.96756216156693, 0.433499968438238, 0.884598593578297,
-0.127559050278120,
2.31771322353091, -1.21846730709075, 1.7508299240518,
-3.02346893141966,
-4.15582444612729, 1.09946459784029, 4.30008521664531,
4.37542383384967,
NA, -1.93641861765076, -0.019194921394532, -2.39609317657158,
-3.12228102462318, 0.488046064498046, -1.42886436846636,
-3.52078266098328,
3.22115286286252, 0.879425403143162, -0.293853650273392,
0.400308672754849,
0.843826073923569, -0.144454076182464, -0.619035270434771, NA,
1.53158893613932, -1.01595045420127, 0.188573746980020,
-1.24703875463314,
-0.53766035430668, -0.433050941330375, 1.30035413662748,
0.0825664730349873,
-0.0100815443036547, -1.89151834308193, 0.601611806130933,
1.38339048228375,
1.70782208107344, 0.489955991643127, NA, 0.717743402714073, NA,
0.355783083720979, -1.30038021268004, 0.181709422709264,
-0.769997723552683,
-0.528601269320360, -0.587139047162164, 2.45770817832288,
-3.79345760049497,
-0.737003476707607, 1.85916858045961, 0.485234889001515,
-2.24404921428853,
-3.71691740913278, -0.805258199659559, 0.207685613867357,
-0.0558821002122282,
NA, -0.503328331764907, 0.704074652205563, -0.573911596976014,
-1.11740646296423)
R> dput(y1)
c(0.117364072525805, 0.127930151301644, 0.0662739004000001,
0.0338529181312498,
0.0511158613502366, 0.128968673883822, 0.210301133239691,
0.10661115427526,
0.0232107944450872, 0.0603516951698553, 0.179660748593193,
0.221208092790247,
0.163670330934813, 0.0706269859311667, 0.115630627445422,
0.628098877137453,
0.135715572434304, 0.143665346556254, 0.164531165326550,
0.0403061842410544,
0.299040792256087, 0.138654578757903, 0.258144638644718,
0.0963669275887815,
0.142628933705512, 0.126198969135830, 0.159191997666087,
0.107131754313874,
0.181377404434746, 0.37961763330731, 0.168317339289797,
0.0242576969560779,
0.127930151301644, 0.231747903494157, 0.163842507805506,
0.419768931002777,
0.124986912573692, 0.189609569425260, 0.338737920245291,
0.195946144242518,
0.44510411179482, 0.455544907233516, 0.708216629106476,
0.207399505454978,
0.0782850996352895, 0.073934436075585, 0.122908668292287,
0.226141303767357,
0.49742825381157, 0.0401317925325597, 0.581271174002464,
0.0521616617128153,
0.275972882648746, 0.140901231937583, 0.221208092790247,
0.490903753615141,
0.332161131883703, 0.0343762121290921, 0.120310105846879,
0.102618926830133,
0.58141318431983, 0.0624421386622914, 0.0359460370021749,
0.179660748593193,
0.0934508516894796, 0.438878151552733, 0.519292440712709,
0.205018848163994,
0.0466396604458663, 0.331046037448212, 0.288412867591914,
0.269246872629229,
0.294957264797501, 0.236752295233338, 0.333850654437810,
0.0281490911010528,
0.252817526879522, 0.212406079820395, 0.152045758417791,
0.182886705171632,
0.328678037952921, 0.198133598672472, 0.173791094486816,
0.207554044235378,
0.108982730290661, 0.103034405378365, 0.191450800590200,
0.385419880265333,
0.293721531101057, 0.193371366411327, 0.0681056881993101,
0.0635735698354304,
0.15778876680469, 0.213642394864822, 0.339997597553925,
0.136704439402335,
0.119002383209226, 0.0131518024196947, 0.305992629021408,
0.0520159481761631,
0.301319380348198, 0.220179564538032, 0.238113635903438)
R> summary(mle.aic(lm(y1~xP+x5+x15)),max.num=30) # mle.aic output
Call:
mle.aic(formula = lm(y1 ~ xP + x5 + x15))
Akaike Information Criterion (AIC):
(Intercept) xPNA xPRing x5 x15 aic
[1,] 1 1 1 0 0 -113.60
[2,] 1 1 1 0 1 -112.80
[3,] 1 1 1 1 0 -112.20
[4,] 1 0 1 0 0 -112.10
[5,] 1 1 1 1 1 -111.30
[6,] 1 0 1 0 1 -111.20
[7,] 1 0 1 1 0 -110.60
[8,] 1 0 1 1 1 -109.60
[9,] 1 1 0 0 0 -98.05
[10,] 1 1 0 0 1 -96.66
[11,] 1 1 0 1 0 -96.28
[12,] 1 1 0 1 1 -94.86
[13,] 1 0 0 0 0 -90.92
[14,] 1 0 0 0 1 -89.32
[15,] 1 0 0 1 0 -89.06
[16,] 1 0 0 1 1 -87.45
[17,] 0 0 1 1 1 -59.09
[18,] 0 0 1 1 0 -57.98
[19,] 0 1 1 1 1 -57.34
[20,] 0 1 1 1 0 -56.35
Printed the first 20 best models
R> AIC(lm(y1~xA)) # Model 1 above
[1] -120.3801
R> AIC(lm(y1~xA+x15)) # Model 2 above
[1] -110.8642
R> AIC(lm(y1~xA+x5)) # Model 3 above
[1] -118.9906
More information about the R-help
mailing list