Re: [R] predict newdata question

From: Felipe Carrillo <mazatlanmexico_at_yahoo.com>
Date: Sat, 26 Jun 2010 10:01:37 -0700 (PDT)

 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-bounces_at_r-project.org">r-help-bounces_at_r-project.org"
>
> href="mailto:> href="mailto:r-help-bounces_at_r-project.org">r-help-bounces_at_r-project.org">> ymailto="mailto:r-help-bounces_at_r-project.org"
> href="mailto:r-help-bounces@r-project.org">r-help-bounces@r-project.org
>
> [mailto:> href="mailto:> ymailto="mailto:r-help-bounces_at_r-project.org"
> href="mailto:r-help-bounces_at_r-project.org">r-help-bounces_at_r-project.org">> ymailto="mailto:r-help-bounces_at_r-project.org"
> href="mailto:r-help-bounces_at_r-project.org">r-help-bounces_at_r-project.org] On
>
> Behalf Of Felipe Carrillo
Sent: Saturday, 26 June 2010 10:35
> AM

To: > ymailto="mailto:> href="mailto:r-help_at_stat.math.ethz.ch">r-help_at_stat.math.ethz.ch"
>
> href="mailto:> href="mailto:r-help_at_stat.math.ethz.ch">r-help_at_stat.math.ethz.ch">> ymailto="mailto:r-help_at_stat.math.ethz.ch"
> href="mailto:r-help@stat.math.ethz.ch">r-help@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_at_r-project.org">R-help_at_r-project.org"
>
> href="mailto:> href="mailto:R-help_at_r-project.org">R-help_at_r-project.org">> ymailto="mailto:R-help_at_r-project.org"
> href="mailto:R-help_at_r-project.org">R-help_at_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_at_r-project.org"
> href="mailto:R-help_at_r-project.org">R-help_at_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_at_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. Received on Sat 26 Jun 2010 - 17:04:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Jun 2010 - 17:50:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive