Re: [R] predict newdata question

2010-06-26 Thread 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:r-help-boun...@r-project.org; 
 href=mailto:r-help-boun...@r-project.org;r-help-boun...@r-project.org 
 [mailto: 
 href=mailto:r-help-boun...@r-project.org;r-help-boun...@r-project.org] On 
 Behalf Of Felipe Carrillo
Sent: Saturday, 26 June 2010 10:35 AM
To:  ymailto=mailto:r-h...@stat.math.ethz.ch; 
 href=mailto:r-h...@stat.math.ethz.ch;r-h...@stat.math.ethz.ch
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:R-help@r-project.org; 
 href=mailto:R-help@r-project.org;R-help@r-project.org 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.




__
R-help@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.


Re: [R] predict newdata question

2010-06-26 Thread 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:r-help-boun...@r-project.org;r-help-boun...@r-project.org 
 
 href=mailto: 
 href=mailto:r-help-boun...@r-project.org;r-help-boun...@r-project.org 
 ymailto=mailto:r-help-boun...@r-project.org; 
 href=mailto:r-help-boun...@r-project.org;r-help-boun...@r-project.org 
 
 [mailto: href=mailto: ymailto=mailto:r-help-boun...@r-project.org; 
 href=mailto:r-help-boun...@r-project.org;r-help-boun...@r-project.org 
 ymailto=mailto:r-help-boun...@r-project.org; 
 href=mailto:r-help-boun...@r-project.org;r-help-boun...@r-project.org] On 
 
 Behalf Of Felipe Carrillo
Sent: Saturday, 26 June 2010 10:35 
 AM
To:  ymailto=mailto: 
href=mailto:r-h...@stat.math.ethz.ch;r-h...@stat.math.ethz.ch 
 
 href=mailto: 
 href=mailto:r-h...@stat.math.ethz.ch;r-h...@stat.math.ethz.ch 
 ymailto=mailto:r-h...@stat.math.ethz.ch; 
 href=mailto:r-h...@stat.math.ethz.ch;r-h...@stat.math.ethz.ch
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:R-help@r-project.org;R-help@r-project.org 
 
 href=mailto: href=mailto:R-help@r-project.org;R-help@r-project.org 
 ymailto=mailto:R-help@r-project.org; 
 href=mailto:R-help@r-project.org;R-help@r-project.org 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:R-help@r-project.org; 
 href=mailto:R-help@r-project.org;R-help@r-project.org 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.




__
R-help@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.


[R] predict newdata question

2010-06-25 Thread 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, 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, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L), WOLVES_01 = c(0L, 1L, 1L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 

Re: [R] predict newdata question

2010-06-25 Thread 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: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Felipe Carrillo
Sent: Saturday, 26 June 2010 10:35 AM
To: r-h...@stat.math.ethz.ch
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




__
R-help@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.

__
R-help@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.