Re: [R] Extracting slots from ROCR prediction objects

From: Tobias Sing <tobias.sing_at_gmail.com>
Date: Thu, 22 May 2008 21:40:29 +0200

Hi Stacey,

ROCR uses S4 classes. The elements are accessed using "@" instead of "$". You can find an example on slide 12 of the following slide deck: http://rocr.bioinf.mpi-sb.mpg.de/ROCR_Talk_Tobias_Sing.ppt

Also have a look at the R code that appears when you type "demo(ROCR)" in R which contains some more examples related to your question.

Hope that helps,
  Tobias

On Thu, May 22, 2008 at 8:32 PM, Jorge Ivan Velez <jorgeivanvelez_at_gmail.com> wrote:

> Hi Stacey,
> Try this:
>
> library(ROCR)
> data(ROCR.simple)
> pred <- prediction(ROCR.simple$predictions,ROCR.simple$labels)
> perf <- performance(pred,"sens","spec")
> cuts <- unlist(slot(perf,"alpha.values"))
> cuts
>
> HTH,
>
> Jorge
>
>
> On Thu, May 22, 2008 at 2:08 PM, Stacey Burrows <stacey.burrows_at_yahoo.ca>
> wrote:
>
> > Hi,
> >
> > I have an object from the prediction function from the ROCR package and I
> > would like to extract one of the slots from the object, for example the
> > cutoffs slot. However the usual techniques ($, [["name"]]) of subsetting
> > don't work. How can I assess the lists in the slots?
> >
> > Here is an example of what I am working with:
> >
> > library(ROCR)
> > data(ROCR.simple)
> > pred <- prediction(ROCR.simple$predictions,ROCR.simple$labels)
> >
> > > str(pred)
> > Formal class 'prediction' [package "ROCR"] with 11 slots
> > ..@ predictions:List of 1
> > .. ..$ : num [1:200] 0.613 0.364 0.432 0.140 0.385 ...
> > ..@ labels :List of 1
> > .. ..$ : Ord.factor w/ 2 levels "0"<"1": 2 2 1 1 1 2 2 2 2 1 ...
> > ..@ cutoffs :List of 1
> > .. ..$ : num [1:201] Inf 0.991 0.985 0.985 0.983 ...
> > ..@ fp :List of 1
> > .. ..$ : num [1:201] 0 0 0 0 1 1 2 3 3 3 ...
> > ..@ tp :List of 1
> > .. ..$ : num [1:201] 0 1 2 3 3 4 4 4 5 6 ...
> > ..@ tn :List of 1
> > .. ..$ : num [1:201] 107 107 107 107 106 106 105 104 104 104 ...
> > ..@ fn :List of 1
> > .. ..$ : num [1:201] 93 92 91 90 90 89 89 89 88 87 ...
> > ..@ n.pos :List of 1
> > .. ..$ : int 93
> > ..@ n.neg :List of 1
> > .. ..$ : int 107
> > ..@ n.pos.pred :List of 1
> > .. ..$ : num [1:201] 0 1 2 3 4 5 6 7 8 9 ...
> > ..@ n.neg.pred :List of 1
> > .. ..$ : num [1:201] 200 199 198 197 196 195 194 193 192 191 ...
> > >
> >
> > Thanks in advance,
> > Stacey
> >
> >
> > ---------------------------------
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]



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 Thu 22 May 2008 - 19:43:30 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 Thu 22 May 2008 - 20:30:49 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