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.