[R] Still problems with "step()" function
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Mar 28 13:24:59 CEST 2006
On Thu, 23 Mar 2006, Kenneth Cabrera wrote:
> What am I doing wrong?
Not paying enough attention to the posting guide. Your example works in
R-patched and R-devel, because of
o factor.scope() could report incorrectly that interaction terms
were not in the upper scope when such terms in the model and
the upper scope had different orders for the main effects.
(Another manifestation of PR#7842.)
in the NEWS for R 2.2.1 patched.
As the posting guide says
If possible, try the current R-patched or R-devel version of R (see the
FAQ for details), to see if the problem has already been addressed.
> Ok
>
> Here is the complete command secuence
> --------------------------------------------------------------------------
>
> testData<-structure(list(MCHNV = c(215, 325, 435, 327, 150, 949, 417, 528,
> 572, 1255, 517, 221, 306, 274, 307, 203, 258, 126, 88, 85, 75,
> 64, 77, 49, 133, 192, 32, 73, 139, 52, 17, 307, 127, 182, 24,
> 51, 141, 40, 76, 40, 100, 42, 18, 20, 18, 75, 26, 21, 216, 81,
> 90, 69, 138, 79, 69, 52, 59, 69, 173, 29, 118, 23, 1456, 156,
> 26, 208, 294, 84, 57, 84, 121, 112, 25, 9281, 36, 71, 812, 135,
> 215, 94, 302, 148, 42, 84, 114, 54, 309, 148, 87, 75, 275, 171,
> 210, 209, 150, 69, 157, 110, 93, 98, 40, 132, 155, 152, 62, 52,
> 50, 124, 248, 52, 181, 76, 118, 73, 66, 65, 75, 33, 71, 84, 223,
> 229), IA = c(26.9863956381346, 21.443816698054, 24.3172115328382,
> 22.9861973271014, 18.1768608561301, 10.6563785744498, 15.0910419778194,
> 13.6340158642317, 15.2055383362367, 16.9860295444068, 17.9909267660402,
> 26.714962883463, 20.1507989217486, 27.4221304422647, 11.806433704469,
> 25.7458563535912, 27.2816742408892, 26.0150722854506, 21.6368286445013,
> 25.1843952723718, 18.6270125223614, 29.9515311742675, 26.2046204620462,
> 12.6096949435855, 18.7464907355418, 10.5534246575342, 17.2654236774291,
> 17.0988006853227, 15.353091109001, 19.3008705114255, 6.27750073335289,
> 26.0375981018434, 17.2681438238026, 15.443279313632, 7.7125328659071,
> 30.1453193646502, 14.8701064405557, 24.7907034861927, 17.3296398891967,
> 10.7364199781261, 19.3800588668138, 10.3085483055134, 8.80185302168878,
> 16.6951761888471, 4.50797141286421, 6.84546862896979, 8.21845174973489,
> 6.19588744588745, 16.9889711436773, 5.59826387611726, 8.68694955964772,
> 3.65186966980101, 16.1123827476325, 9.67841682127396, 13.5423542354235,
> 5.6497484139138, 8.7686432740111, 11.9602529358627, 6.86294126054023,
> 19.2194992008524, 4.64579055441478, 9.5090599349543, 2.79913286437223,
> 10.2515243902439, 8.66738894907909, 3.6576768917803, 12.4953778763831,
> 15.2370770972205, 21.2257484260568, 7.8413206434768, 12.5950805097303,
> 6.23108480731724, 4.72859966550099, 3.11622388590868, 15.9319508257792,
> 6.69567319313512, 2.47749261819931, 24.8112304583644, 3.94306597422581,
> 2.71509876129896, 1.79760050991181, 4.80243967117475, 18.7818696883853,
> 5.24955116696589, 19.0728713579217, 12.6099706744868, 3.58964845561636,
> 11.3911041683795, 7.48350816481021, 15.0857882809971, 19.6855832458419,
> 12.2966073388367, 4.08228296275315, 21.4270750408514, 9.83262770545642,
> 6.28415300546448, 4.2754914877677, 10.4337099078042, 13.9745206313318,
> 14.0491684743312, 8.79131920024113, 15.2282010300124, 19.1379750063759,
> 6.89338235294118, 5.51527398074409, 18.3089033659066, 23.5368956743003,
> 10.3041872432253, 13.7563263088668, 12.0249520153551, 12.0066668763169,
> 9.25797503467406, 11.4912313643021, 14.2689601250977, 15.2254249815225,
> 14.0718562874251, 9.21820303383897, 9.9353894916494, 8.6011885743498,
> 14.7106815614409, 8.6682462336269, 10.9155102240965), IM =
> c(1.07456622007468,
> 1.05477685097601, 1.08970363580813, 1.09309079792113, 0.983952398124775,
> 0.97821952889272, 1.02464131763495, 0.913249100021176, 0.999321512574634,
> 1.00064160401003, 1.00311566921978, 1.03642655495856, 1.05350982751705,
> 1.03894736842105, 1.02694423605901, 1.0255795363709, 1.08604552865165,
> 0.9960092095165, 1.10034379028792, 1.05835010060362, 1.09069658719028,
> 1.08689655172414, 1.11247966534976, 1.06872703695699, 1.09098914000587,
> 0.947705442902882, 1.0462158808933, 1.06583294006607, 1.03178310316816,
> 1.02785822645152, 0.95582329317269, 1.03257159815996, 1.05732223283745,
> 1.05083088954057, 1.0375, 1.18054532056006, 1.08226897069872,
> 1.08357198646186, 1.11061739943873, 1.09309423884014, 1.14100039385585,
> 1.00222807372899, 1.02085106382979, 1.11658218682114, 1.08840413318025,
> 0.940623825629463, 1.07633027522936, 1.24954351795496, 1.06553284443751,
> 1.02449921811006, 1.03136617100372, 0.890711135611907, 1.01692767267131,
> 1.05692478931468, 1.00617965129111, 1.01988510826337, 1.02820400409177,
> 1.00325732899023, 0.969987048820317, 1.0319350473613, 0.948,
> 0.976430976430976, 0.912491945614184, 1.03805825242718, 1.01016333938294,
> 0.934502240405221, 0.936918076139056, 1.03298389158783, 1.06829657188414,
> 1.04918881601657, 1.0427807486631, 0.99369804237061, 1.00763125763126,
> 0.859808006713988, 1.06752246469833, 0.976588628762542, 0.900774538520513,
> 1.014353041988, 0.92939648374078, 0.934334930708457, 0.863916626564004,
> 1.00074278438031, 1.02873563218391, 0.882901764586573, 1.05623621661358,
> 1.09948152948801, 0.971704768125408, 1.0102470870176, 0.949198988195616,
> 0.999676323029616, 0.99394006170119, 1.02639721523883, 0.963297650493535,
> 1.02262711864407, 0.990626969124134, 1.02701607456437, 0.962433460076046,
> 1.05496997998666, 0.995055517002082, 0.99971081550029, 1.06194323596437,
> 1.0324851109908, 1.06694781233527, 1.01801801801802, 1.01774793140664,
> 1.01807723911257, 1.03578996939016, 1.00624427608026, 1.01527025469632,
> 0.990068754774637, 0.967759900990099, 0.954370905805286, 1.03321371306406,
> 1.01163888015099, 1.1162669447341, 0.998290598290598, 0.964776990412672,
> 1.00906196424198, 1.01454685890834, 1.04203511469947, 0.990833036667853,
> 1.02915422885572), altura = c(2, 4, 8, 200, 30, 25, 28, 50, 34,
> 2, 50, 100, 50, 125, 650, 75, 1550, 1165, 1200, 1700, 1850, 1200,
> 650, 1475, 1535, 2300, 1875, 850, 1550, 1675, 2550, 450, 980,
> 700, 1800, 25, 1300, 1625, 1250, 700, 75, 1800, 1925, 500, 2300,
> 1050, 2550, 1920, 1350, 2550, 1450, 2200, 550, 750, 950, 2475,
> 1975, 780, 1300, 1800, 1425, 1875, 1450, 1475, 1650, 1425, 125,
> 1150, 625, 2150, 1000, 2150, 1925, 1550, 1440, 2000, 1550, 18,
> 1775, 1550, 1575, 2120, 1800, 2150, 1600, 1900, 2125, 1000, 2050,
> 1550, 1800, 375, 1750, 2000, 1400, 2175, 2200, 1050, 1300, 1350,
> 2350, 150, 1250, 2150, 2500, 1325, 1250, 1800, 1100, 1800, 1800,
> 2000, 2125, 1750, 1550, 987.5, 1600, 2050, 1750, 1650, 2475,
> 1350), Region = structure(c(8, 8, 8, 8, 1, 8, 8, 1, 8, 8, 1,
> 1, 1, 1, 3, 8, 4, 4, 4, 4, 4, 5, 5, 4, 3, 4, 4, 5, 3, 4, 4, 5,
> 3, 3, 4, 8, 5, 5, 3, 5, 2, 4, 5, 5, 4, 3, 4, 5, 5, 4, 3, 4, 5,
> 5, 2, 4, 3, 5, 9, 7, 9, 6, 9, 3, 6, 9, 2, 5, 5, 6, 6, 6, 6, 9,
> 5, 6, 9, 8, 9, 9, 9, 6, 5, 6, 7, 7, 6, 6, 6, 7, 7, 2, 9, 7, 7,
> 6, 6, 6, 6, 7, 7, 2, 7, 6, 6, 7, 6, 7, 7, 7, 7, 7, 6, 6, 7, 7,
> 7, 7, 7, 6, 6, 7), .Label = c("BAJO CAUCA", "MAGDALENA MEDIO",
> "NORDESTE", "NORTE", "OCCIDENTE", "ORIENTE", "SUROESTE", "URABA",
> "VALLE DE ABURRA"), class = "factor"), Offset1 = c(-0.185125484126689,
> 0.118671529717499, 0.363948427905231, 0.241376319575269,
> -0.683196849706777,
> 1.30128098679293, 0.314810739840034, 0.986562784859487, 0.714908672341458,
> 1.54158724552593, 0.67141268841394, -0.122167633974208, 0.0411419433311752,
> 0.0344014267173323, 0.242161557149972, -0.608806032126194,
> 0.340748793388473,
> -0.551647618286246, -0.901402119380404, -0.763569644856491,
> -1.03282454813011,
> -1.03845836584836, -1.10563690360507, -1.06421086195078,
> -0.616186139423817,
> 0.508021696433256, -1.18417017702976, -1.04128722204884,
> -0.245900538436826,
> -0.473208760194684, -1.69826912614072, 0.131028262406404,
> -0.520875959619492,
> -0.16960278438618, -1.76609172247948, -2.21640739675299,
> -0.138113302129634,
> -1.18090753139494, -1.11474167059799, -0.711311151187616, -0.86988435906,
> -0.898942093539542, -1.48722027970985, -1.99510039324608,
> -1.22417551164346,
> -0.648173814917214, -1.48722027970985, -1.9241486572738, 0.188137942115395,
> 0.16296882827814, -0.233193887167711, -0.415515443961666,
> -0.139262067333508,
> -0.638658995275876, -0.97021907389971, -0.136965855073157,
> -0.512493680866688,
> -0.807436326962073, 0.436963775167535, -1.26584820804402,
> 0.392717535285662,
> -1.21739582465808, 2.50894864426824, -0.0693500781347932,
> -1.53247687129797,
> 0.718814927308523, 0.368801123736573, -0.398986142010455,
> -1.09961278900169,
> 0.0295588022415444, -0.162518929497775, 0.272314595320659,
> -1.20731170559145,
> 4.33235045310693, -1.09064411901893, -0.369615455214467, 2.04485009691022,
> -1.0106014113454, 0.580538236177291, 0.151002873536527, 1.57277392806251,
> 0.579978482454307, -1.17118298150295, 0.407463110770837,
> -0.269187489815617,
> -1.26940060964839, 1.20896034583698, 0.0207825391825284,
> -0.0693500781347932,
> -0.659712404473708, 0.441475545631197, -0.100925918589961,
> 0.789820067820206,
> 0.0797349680188535, 0.0168571170664228, -0.502526820951296,
> 0.56360780920496,
> -0.391562202939173, 0.0610950993598108, -0.612489277542491,
> -0.901402119380404,
> -0.62548853208613, -0.151986356997882, 0.630207380786071,
> -0.331285709933913,
> -1.09362474715707, -0.999672340813206, 0.0601539228197471,
> 0.459953293392234,
> -0.787457860031187, 0.29266961396282, -0.140412153716745,
> 0.268499253035007,
> -0.62548853208613, -0.610645959048202, -0.884307686021104,
> -0.136965855073157,
> -1.01335244471729, -0.372514007968479, -0.375420986759788,
> 0.745739630679116,
> 0.673964361143171)), .Names = c("MCHNV", "IA", "IM", "altura",
> "Region", "Offset1"), class = "data.frame", row.names = c("1",
> "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
> "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
> "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
> "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
> "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57",
> "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68",
> "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
> "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
> "91", "92", "93", "94", "95", "96", "97", "98", "99", "100",
> "101", "102", "103", "104", "105", "106", "107", "108", "109",
> "110", "111", "112", "113", "114", "115", "116", "117", "118",
> "119", "120", "121", "122"))
> model1J<-glm(MCHNV~offset(Offset1),data=testData,family="poisson")
> step(model1J,direction="forward",
> scope=(list(upper=~IA+IM+altura+Region+Region:IA+Region:IM+Region:altura+offset(Offset1),
> lower=~offset(Offset1))))
> What am I doing wrong?
>
> -------------------------------------------------------------------------
> Thank you for your help.
>
> I put here the database I use, so you can replicate the problem.
> (I am using R221 on WinXP)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list