[R] calculating AUCs for each of the 1000 boot strap samples
Brian Diggs
diggsb at ohsu.edu
Wed Mar 16 21:42:14 CET 2011
On 3/16/2011 8:04 AM, taby gathoni wrote:
>> data<-data.frame(id=1:(165+42),main_samp$SCORE, x=rep(c("BAD","GOOD"),c(42,165)))
>> > f<-function(x) {
> + str.sample<-list()
> + for (i in 1:length(levels(x$x)))
> + {
> + str.sample[[i]]<-x[x$x==levels(x$x)[i] ,][sample(tapply(x$x,x$x,length)[i],20,rep=T),]
> + }
> + strat.sample<-do.call("rbind",str.sample)
> + return(strat.sample$main_samp.SCORE)
> + }
>> > f(data)
> [1]
> 706 633 443 843 756 743 730 843 706 730 606 743 768 768 743 763 608 730
> 743 743 530 813 813 831 793 900 793 693 900 738 706 831
> [33] 818 758 718 831 768 638 770 738
>> > repl<-list()
>> > auc<-list()
>> > for(i in 1:1000)
> + {
> + repl[[i]]<-f(data)
> + auc[[i]]<-colAUC(repl[[i]],rep(c("BAD","GOOD")),plotROC=FALSE,alg="ROC")
> + }
> Error in
> colAUC(repl[[i]], rep(c("BAD", "GOOD")), plotROC = FALSE, alg = "ROC") :
> colAUC: length(y) and nrow(X) must be the same Thanks alotTaby
I think (though I can't check because the example is not reproducible
without main_samp$SCORE), that the problem is that the second argument
to colAUC should be
rep(c("BAD", "GOOD"), c(20,20))
The error is that repl[[i]] is length 40 while rep(c("BAD", "GOOD")) is
length 2.
P.S. When giving an example, it is better to not include the prompts and
continuation prompts. Copy it from the script rather than the output.
Relevant output can then be included as script comments (prefixed with
#). That makes cutting-and-pasting to test easier.
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
More information about the R-help
mailing list