predict newdata question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

predict newdata question

Felipe Carrillo
Hi:
I am using a subset of the below dataset to predict PRED_SUIT for
the whole dataset but I am having trouble with 'newdata'. The model
was created with 153 records and want to predict for 208 records.

wolf2 <- structure(list(gridcell = c(367L, 444L, 533L, 587L, 598L, 609L,
620L, 629L, 641L, 651L, 662L, 674L, 684L, 695L, 738L, 748L, 804L,
805L, 872L, 919L, 929L, 938L, 950L, 958L, 966L, 975L, 976L, 985L,
994L, 1006L, 1015L, 1019L, 1022L, 1025L, 1027L, 1028L, 1029L,
1032L, 1040L, 1043L, 1050L, 1053L, 1061L, 1070L, 1074L, 1078L,
1080L, 1082L, 1083L, 1084L, 1090L, 1095L, 1096L, 1099L, 1106L,
1116L, 1124L, 1125L, 1130L, 1133L, 1134L, 1137L, 1138L, 1139L,
1145L, 1150L, 1151L, 1154L, 1161L, 1162L, 1163L, 1171L, 1175L,
1179L, 1181L, 1184L, 1188L, 1189L, 1193L, 1194L, 1199L, 1204L,
1207L, 1214L, 1222L, 1231L, 1232L, 1241L, 1250L, 1256L, 1275L,
1279L, 378L, 421L, 432L, 480L, 492L, 501L, 511L, 522L, 545L,
555L, 566L, 575L, 705L, 716L, 728L, 760L, 774L, 785L, 794L, 816L,
831L, 841L, 850L, 860L, 861L, 873L, 889L, 899L, 908L, 917L, 931L,
933L, 942L, 944L, 954L, 963L, 971L, 986L, 988L, 996L, 997L, 1007L,
1009L, 1014L, 1041L, 1052L, 1062L, 1064L, 1069L, 1107L, 1108L,
1117L, 1120L, 1172L, 1216L, 1225L, 1239L, 1245L, 1265L, 1287L,
1293L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L,
40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L,
53L, 54L, 55L), MAJOR_LC = c(42L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 51L,
51L, 51L, 42L, 42L, 42L, 71L, 51L, 51L, 51L, 71L, 71L, 51L, 42L,
71L, 42L, 51L, 51L, 42L, 51L, 42L, 51L, 42L, 51L, 51L, 51L, 42L,
51L, 42L, 51L, 71L, 42L, 51L, 42L, 42L, 51L, 51L, 42L, 51L, 42L,
42L, 51L, 51L, 51L, 71L, 51L, 42L, 51L, 42L, 51L, 71L, 42L, 51L,
42L, 42L, 51L, 51L, 42L, 51L, 51L, 71L, 82L, 51L, 42L, 51L, 51L,
42L, 82L, 83L, 51L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 51L, 42L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 51L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 71L,
51L, 51L, 51L, 31L, 81L, 41L, 42L, 41L, 42L, 41L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 81L, 81L, 42L,
42L, 42L, 51L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 51L, 42L, 31L, 42L, 81L, 43L, 41L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L), RD_DENSITY = c(1.046, 1.626, 2.356,
1.912, 0.203, 0.049, 0.055, 1.96, 1.515, 0.361, 0.183, 0.022,
1.702, 0.8, 1.356, 0.216, 0.509, 0.915, 0.689, 0.817, 0.93, 0.808,
0.121, 0.026, 0.283, 1.256, 0.56, 0.881, 0.649, 1.074, 0.851,
0.758, 0.375, 0.554, 1.111, 0.783, 1.113, 0.619, 0.587, 0.975,
0.892, 0.162, 0.714, 1.582, 0.408, 0.227, 1.816, 1.586, 0.888,
1.247, 2.016, 0.457, 0.816, 0.933, 0.894, 2.101, 0.091, 2.265,
0.389, 0.343, 1.718, 0.738, 0.597, 1.098, 1.865, 1.082, 0.654,
1.104, 0.43, 0.418, 0.164, 1.068, 0.708, 0.011, 1.61, 1.143,
0.124, 2.039, 0.547, 0.794, 1.694, 0.526, 1.505, 0.861, 0.771,
0.216, 1.018, 2.88, 0.892, 0.741, 0.437, 1.16, 0.966, 0.961,
0.591, 2.052, 0.82, 0.638, 2.107, 3.082, 0.387, 0.716, 1.065,
1.602, 0.93, 0.234, 0.257, 0.186, 0, 0.408, 0.914, 0.281, 0.019,
0.13, 0.704, 0.305, 1.132, 0.347, 0, 0.252, 0.733, 0.925, 0.276,
0.368, 0.596, 0.284, 0.158, 0.627, 0.719, 0.472, 0.264, 0.251,
0.525, 0.231, 0.568, 0.204, 0.44, 0.466, 0.19, 0.134, 0.001,
0.422, 0.2, 0.073, 0.528, 0, 0.42, 0.626, 0.121, 0.181, 1.324,
1.265, 0.827, 11.611, 3.443, 5.382, 2.269, 3.677, 1.1, 4.876,
0.003, 2.86, 2.375, 1.885, 0.044, 0.728, 1.314, 3.042, 0.469,
0.248, 0.675, 1.91, 0.228, 4.058, 3.563, 0.801, 3.421, 0.515,
1.945, 1.235, 1.999, 2.495, 1.193, 1.896, 1.689, 1.144, 1.028,
0.858, 1.703, 4.009, 0.096, 1.85, 0.081, 0, 1.759, 5.549, 4.99,
4.267, 1.792, 0.204, 2.144, 0.212, 9.263, 1.615, 3.502, 1.927,
1.665, 2.17), WOLVES_99 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 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, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L,
1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), PRED_SUIT = c(0.487,
0.404, 0.308, 0.365, 0.607, 0.628, 0.627, 0.359, 0.42, 0.585,
0.609, 0.631, 0.394, 0.522, 0.442, 0.605, 0.564, 0.506, 0.538,
0.135, 0.127, 0.135, 0.618, 0.631, 0.596, 0.088, 0.153, 0.13,
0.146, 0.096, 0.108, 0.139, 0.583, 0.126, 0.477, 0.137, 0.116,
0.548, 0.151, 0.497, 0.13, 0.612, 0.142, 0.091, 0.165, 0.603,
0.08, 0.41, 0.13, 0.088, 0.351, 0.161, 0.52, 0.503, 0.13, 0.069,
0.622, 0.063, 0.581, 0.587, 0.085, 0.14, 0.15, 0.095, 0.078,
0.481, 0.146, 0.478, 0.163, 0.135, 0.612, 0.119, 0.535, 0.633,
0.09, 0.114, 0.617, 0.071, 0.154, 0.112, 0.001, 0.155, 0.421,
0.132, 0.138, 0.605, 0.001, 0, 0.13, 0.531, 0.574, 0.47, 0.498,
0.499, 0.552, 0.346, 0.519, 0.545, 0.339, 0.226, 0.581, 0.534,
0.484, 0.407, 0.503, 0.602, 0.599, 0.609, 0.634, 0.578, 0.506,
0.596, 0.632, 0.617, 0.536, 0.593, 0.115, 0.587, 0.634, 0.6,
0.532, 0.504, 0.597, 0.584, 0.551, 0.595, 0.613, 0.148, 0.534,
0.569, 0.598, 0.6, 0.561, 0.603, 0.555, 0.606, 0.574, 0.57, 0.608,
0.616, 0.634, 0.576, 0.607, 0.624, 0.561, 0.634, 0.576, 0.547,
0.618, 0.152, 0.104, 0.107, 0.134, 0, 0, 0.072, 0.319, 0.172,
0.479, 0.094, 0.634, 0.249, 0.305, 0.369, 0.628, 0.532, 0.448,
0.23, 0.57, 0.6, 0.54, 0.365, 0.603, 0, 0, 0.522, 0.194, 0.563,
0.075, 0.459, 0.353, 0.291, 0.465, 0.367, 0.395, 0.472, 0.489,
0.514, 0.393, 0.146, 0.621, 0.079, 0.623, 0.011, 0.386, 0, 0.088,
0.128, 0.381, 0.607, 0.335, 0.605, 0.008, 0.406, 0.187, 0.363,
0.399, 0.331), Forest = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1,
0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), predicted = c(-0.0536742000000001,
-0.388740200000000, -0.8104612, -0.5539624, 0.4333269, 0.5222927,
0.5188265, -0.581692, -0.3246155, 0.3420503, 0.4448809, 0.5378906,
-0.4326454, 0.0884399999999999, -0.2327612, 0.4258168, 0.2565507,
0.0220045000000000, 0.152564700000000, -1.8606809, -1.925961,
-1.8554816, 0.4806983, 0.5355798, 0.3871109, -2.3421912, -1.712212,
-1.8976537, -1.7636273, -2.2370498, -2.1082227, -1.8265966, 0.3339625,
-1.9366458, -0.0912247000000002, -1.8410391, -2.0316801, 0.1930037,
-1.7278099, -0.0126575000000000, -1.9040084, 0.4570126, -1.8011778,
-2.3026214, -1.6244016, 0.4194621, -2.4378032, -0.3656322, -1.9016976,
-2.3369919, -0.6140432, -1.6527089, 0.0791967999999996, 0.0116058999999997,
-1.9051638, -2.6024477, 0.4980293, -2.6971905, 0.3258747, 0.3524489,
-2.3811886, -1.8150426, -1.7335869, -2.2509146, -2.4661105, -0.0744714000000002,
-1.7665158, -0.0871808, -1.637111, -1.8580786, 0.4558572, -2.0056836,
0.1415884, 0.5442453, -2.318797, -2.0490111, 0.4789652, -2.5666303,
-1.7047019, -2.0752938, -16.5023238, -1.6925702, -0.3188385,
-1.8860997, -1.8341067, 0.4258168, -16.1117986, -17.187476, -1.9040084,
0.122524300000000, 0.2981451, -0.119532, -0.0074582000000003,
-0.00456970000000023, 0.209179300000000, -0.6348404, 0.0768859999999996,
0.182027400000000, -0.6666139, -1.2298714, 0.3270301, 0.136966800000000,
-0.0646505000000004, -0.3748754, 0.0133389999999998, 0.4154182,
0.4021311, 0.4431478, 0.5506, 0.314898400000000, 0.0225822, 0.3882663,
0.5396237, 0.475499, 0.1438992, 0.3744015, -2.0426564, 0.3501381,
0.5506, 0.4050196, 0.1271459, 0.0162274999999998, 0.3911548,
0.3380064, 0.206290800000000, 0.3865332, 0.4593234, -1.7509179,
0.135233700000000, 0.277925600000000, 0.3980872, 0.4055973, 0.2473075,
0.4171513, 0.2224664, 0.4327492, 0.296412, 0.2813918, 0.440837,
0.4731882, 0.5500223, 0.306810600000000, 0.43506, 0.5084279,
0.245574400000000, 0.5506, 0.307966, 0.188959800000000, 0.4806983,
-1.7211637, -2.1535748, -2.1194905, -1.8664579, -8.3242747, -3.6056211,
-4.7257814, -0.7602013, -3.7408029, -0.0848700000000004, -4.4334652,
0.5488669, -1.101622, -0.8214375, -0.5383645, 0.5251812, 0.1300344,
-0.208497800000000, -1.2067634, 0.2796587, 0.4073304, 0.1606525,
-0.552807, 0.4188844, -3.9609066, -3.6749451, 0.0878622999999998,
-1.4257117, 0.253084500000000, -2.5123265, -0.1628595, -0.6042223,
-0.8907615, -0.138596100000000, -0.5447192, -0.4251353, -0.110288800000000,
-0.0432756000000003, 0.0549333999999999, -0.4332231, -1.7653993,
0.4951408, -2.457445, 0.5038063, -1.6166, -0.4655743, -4.8222573,
-4.499323, -4.0816459, -0.4846384, 0.4327492, -0.6879888, 0.4281276,
-4.8006351, -0.3823855, -1.4725054, -0.5626279, -0.4112705, -0.703009
), prob99 = c(0.486584670552659, 0.404020608656185, 0.307792225482413,
0.364945591456331, 0.606667820974553, 0.627683719782276, 0.626873321847087,
0.358543357485507, 0.419551328802209, 0.584688479188911, 0.609421434988108,
0.631321581242126, 0.393494811718216, 0.522095599903215, 0.44207100283161,
0.604874317752202, 0.563788189218218, 0.505500903041261, 0.538067365667117,
0.134623707253202, 0.127198310683846, 0.135230578065470, 0.617912754581926,
0.630783568789971, 0.595587014253568, 0.0876884621478055, 0.152877029271026,
0.130374259752262, 0.146336627891826, 0.0964723913149736, 0.108300183401604,
0.138644214360458, 0.582723200618789, 0.126016813448349, 0.477209627828628,
0.136928446392925, 0.115916634337905, 0.548101700209266, 0.150867931967550,
0.496835667246975, 0.129655474868517, 0.612305242999855, 0.141707752553199,
0.0909060903746533, 0.164598729966023, 0.603354527957077, 0.0803350651486486,
0.409596856135604, 0.129916460172047, 0.0881052946040961, 0.351137441946957,
0.160743170022465, 0.519788857885141, 0.502901442432128, 0.129525149613431,
0.0689810565719842, 0.621996097743729, 0.0631393419178535, 0.58075529056827,
0.587211304551512, 0.0846184534818625, 0.14002978559556, 0.150129350714500,
0.0952706025750436, 0.078268373259536, 0.481390749763869, 0.145976158552064,
0.478218594036017, 0.162858552724011, 0.134927163992898, 0.612030929881264,
0.118607470817052, 0.535338083692257, 0.632799428916766, 0.0895781202237573,
0.114152342265483, 0.617503492062894, 0.0713171606288495, 0.153852167133104,
0.111521425864176, 6.80975999050118e-08, 0.155438132785474, 0.420958840352785,
0.131689819105981, 0.137749774777209, 0.604874317752202, 1.00631681779794e-07,
3.43221117060796e-08, 0.129655474868517, 0.53059281244372, 0.573989008597367,
0.470152529676964, 0.498135458642879, 0.498857576988021, 0.552104971405316,
0.346413803455006, 0.519212036671612, 0.545381613043392, 0.339255459372787,
0.226203934530865, 0.581036579446264, 0.534188269315286, 0.483843002207684,
0.407363480440703, 0.503334700555174, 0.602386347200677, 0.599199571932111,
0.609008832339831, 0.634274784390088, 0.57808045249111, 0.505645310097174,
0.595865276742934, 0.631724876424415, 0.616684467370125, 0.535912850820255,
0.592522106323228, 0.114796516915578, 0.586651067406944, 0.634274784390088,
0.599893073292137, 0.531743722221972, 0.504056785977009, 0.59656066295025,
0.583706172526196, 0.55139058145227, 0.595447859947264, 0.612853655544421,
0.147931461413597, 0.533756994582199, 0.569037583945135, 0.598228002728735,
0.600031725634607, 0.561513674304511, 0.602801380425829, 0.555388351416445,
0.606529960567636, 0.573565166990626, 0.569887409171905, 0.608458453009814,
0.616138082443238, 0.634140764765768, 0.576106574482837, 0.607081300179362,
0.624437865281187, 0.561086911847231, 0.634274784390088, 0.576388707322294,
0.547099888372505, 0.617912754581926, 0.151721332466015, 0.103997643757460,
0.107216830771532, 0.13395210527281, 0.000242497967909788, 0.0264518521928029,
0.00878590863599639, 0.318602563397841, 0.0231847477336065, 0.478795226490737,
0.0117339545631495, 0.633872663216252, 0.249436103842099, 0.305458603769655,
0.368568123199008, 0.628358503845371, 0.532462870144856, 0.448063559349147,
0.230274230977697, 0.569462547711842, 0.600447586436331, 0.540076965766796,
0.365213409075697, 0.603216265788513, 0.0186898751417392, 0.0247240235356012,
0.521951455109384, 0.193767730538401, 0.562935555288143, 0.0749985517386924,
0.459374877742219, 0.353378293235766, 0.290952705566671, 0.465406332743616,
0.367090460567647, 0.395288573322370, 0.472455714192311, 0.489182788133275,
0.513729897472346, 0.393356948260778, 0.146115404416110, 0.621316723498057,
0.0788958125905496, 0.623353408007809, 0.165674305649981, 0.385664280918385,
0.0079843358034966, 0.0109943015040763, 0.0165994671724063, 0.381157434456078,
0.606529960567636, 0.334480623940683, 0.605426468079492, 0.00815743102516259,
0.405551672557508, 0.186562104157836, 0.362939632672359, 0.398607518247037,
0.331145431749362)), .Names = c("gridcell", "MAJOR_LC", "RD_DENSITY",
"WOLVES_99", "WOLVES_01", "PRED_SUIT", "Forest", "Shrub", "Ag",
"predicted", "prob99"), row.names = c(NA, -208L), class = "data.frame")

 head(wolf)
wolfsub<-subset(wolf,subset=!(WOLVES_99==2))
wolfsub$Forest<-ifelse(wolfsub$MAJOR_LC==42,1,0)
wolfsub$Shrub<-ifelse(wolfsub$MAJOR_LC==51,1,0)
wolfsub$Ag<-ifelse(wolfsub$MAJOR_LC>81,1,0)
m1<-glm(WOLVES_99~RD_DENSITY+Forest+Shrub+Ag,family=binomial,data=wolfsub)
summary(m1)

wolf$Forest <- ifelse(wolf$MAJOR_LC==42,1,0)
wolf$Shrub <- ifelse(wolf$MAJOR_LC==51,1,0)
wolf$Ag <- ifelse(wolf$MAJOR_LC>81,1,0)
head(wolf);dim(wolf)
         # This works, it predicts for the whole dataset if done manually using the coefficients of m1
wolf$predicted<- -1.6166 + (-0.5777*wolf$RD_DENSITY)+((2.1672)*wolf$Forest)+((0.2279)*wolf$Shrub)+((-13.9071)*wolf$Ag)
dim(wolf)
wolf$prob99<-(exp(wolf$predicted))/(1+exp(wolf$predicted))
head(wolf);dim(wolf)
   # How can I use predict here, 'newdata' crashes
 predict(m1,newdata=wolf$predicted);wolf  # it doesn't work

Thanks for any hints


Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA




______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: predict newdata question

Bill.Venables
You ask:

# How can I use predict here, 'newdata' crashes
predict(m1,newdata=wolf$predicted);wolf # it doesn't work

To use predict() you need to give a fitted model object (here m1) and a *data frame* to specify the values of the predictors for which you want predictions.  Here wolf$predicted is not a data frame, it is a vector.

What I think you want is

pv <- predict(m1, newdata = wolf)

That will get you linear predictors.  To get probabilities you need to say so as

probs <- predict(m1, newdata = wolf, type = "response")

You can put these back into the data frame if you wish, e.g.

wolf <- within(wold, {
        lpreds <- predict(m1, wolf)
        probs <- predict(m1, wolf, type = "response")
})

Now if you look at

head(wolf)

you will see two extra columns.
 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Felipe Carrillo
Sent: Saturday, 26 June 2010 10:35 AM
To: [hidden email]
Subject: [R] predict newdata question

Hi:
I am using a subset of the below dataset to predict PRED_SUIT for
the whole dataset but I am having trouble with 'newdata'. The model
was created with 153 records and want to predict for 208 records.

[lots of stuff omitted]

wolf$prob99<-(exp(wolf$predicted))/(1+exp(wolf$predicted))
head(wolf);dim(wolf)
   # How can I use predict here, 'newdata' crashes
 predict(m1,newdata=wolf$predicted);wolf  # it doesn't work

Thanks for any hints


Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA




______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: predict newdata question

Felipe Carrillo
Thanks Bill, that worked great!!
 
> You ask:

# How can I use predict here, 'newdata'
> crashes
predict(m1,newdata=wolf$predicted);wolf # it doesn't work

To
> use predict() you need to give a fitted model object (here m1) and a *data
> frame* to specify the values of the predictors for which you want
> predictions.  Here wolf$predicted is not a data frame, it is a
> vector.

What I think you want is

pv <- predict(m1, newdata =
> wolf)

That will get you linear predictors.  To get probabilities you
> need to say so as

probs <- predict(m1, newdata = wolf, type =
> "response")

You can put these back into the data frame if you wish,
> e.g.

wolf <- within(wold, {
    lpreds <-
> predict(m1, wolf)
    probs <- predict(m1, wolf, type =
> "response")
})

Now if you look at

head(wolf)

you will
> see two extra columns.


-----Original Message-----
From: > ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email]
> [mailto:> href="mailto:[hidden email]">[hidden email]] On
> Behalf Of Felipe Carrillo
Sent: Saturday, 26 June 2010 10:35 AM
To: > ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email]
Subject:
> [R] predict newdata question

Hi:
I am using a subset of the below
> dataset to predict PRED_SUIT for
the whole dataset but I am having trouble
> with 'newdata'. The model
was created with 153 records and want to predict
> for 208 records.

[lots of stuff
> omitted]

wolf$prob99<-(exp(wolf$predicted))/(1+exp(wolf$predicted))
head(wolf);dim(wolf)
  
> # How can I use predict here, 'newdata'
> crashes
 predict(m1,newdata=wolf$predicted);wolf  # it doesn't
> work

Thanks for any hints


Felipe D. Carrillo
Supervisory
> Fishery Biologist
Department of the Interior
US Fish & Wildlife
> Service
California,
> USA




______________________________________________
> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email] mailing list
> href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
> >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.




______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: predict newdata question

Felipe Carrillo

 Thanks Bill, that worked great!!
 
> You ask:

# How can I use
> predict here, 'newdata'
>
> crashes
predict(m1,newdata=wolf$predicted);wolf # it doesn't work

To
>
> use predict() you need to give a fitted model object (here m1) and a
> *data
> frame* to specify the values of the predictors for which you want
>
> predictions.  Here wolf$predicted is not a data frame, it is a
>
> vector.

What I think you want is

pv <- predict(m1, newdata =
>
> wolf)

That will get you linear predictors.  To get probabilities
> you
> need to say so as

probs <- predict(m1, newdata = wolf,
> type =
> "response")

You can put these back into the data frame if
> you wish,
> e.g.

wolf <- within(wold, {
    lpreds <-
>
> predict(m1, wolf)
    probs <- predict(m1, wolf, type =
>
> "response")
})

Now if you look at

head(wolf)

you will
>
> see two extra columns.


-----Original Message-----
From:

> > ymailto="mailto:> href="mailto:[hidden email]">[hidden email]"
>
> href="mailto:> href="mailto:[hidden email]">[hidden email]">> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email]
>
> [mailto:> href="mailto:> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email]">> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email]] On
>
> Behalf Of Felipe Carrillo
Sent: Saturday, 26 June 2010 10:35
> AM
To: > ymailto="mailto:> href="mailto:[hidden email]">[hidden email]"
>
> href="mailto:> href="mailto:[hidden email]">[hidden email]">> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email]
Subject:
>
> [R] predict newdata question

Hi:
I am using a subset of the
> below
> dataset to predict PRED_SUIT for
the whole dataset but I am
> having trouble
> with 'newdata'. The model
was created with 153
> records and want to predict
> for 208 records.

[lots of stuff
>
>
> omitted]

wolf$prob99<-(exp(wolf$predicted))/(1+exp(wolf$predicted))
head(wolf);dim(wolf)
  
>
> # How can I use predict here, 'newdata'
>
> crashes
 predict(m1,newdata=wolf$predicted);wolf  # it doesn't
>
> work

Thanks for any hints


Felipe D. Carrillo
Supervisory
>
> Fishery Biologist
Department of the Interior
US Fish &
> Wildlife
> Service
California,
>
> USA




______________________________________________
>
> ymailto="mailto:> href="mailto:[hidden email]">[hidden email]"
>
> href="mailto:> href="mailto:[hidden email]">[hidden email]">> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email] mailing list
>
> href="> >https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
> >> href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
> >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.




______________________________________________
> ymailto="mailto:[hidden email]"
> href="mailto:[hidden email]">[hidden email] mailing list
> href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank
> >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.




______________________________________________
[hidden email] 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.