0

I am fairly new to R. I am using the ROCR package in R to calculate AUC, which I can do for one predictor just fine. What I am looking to do is perform many AUC calculations for 100 different variables.

What I have done so far is the following:

varlist <- names(mydata)[2:101]
formlist <- lapply(varlist, function(x) paste0("prediction(",x,"mydata$V1))

However then the formulas are in text format, and the as.formula is giving me an error. Any help appreciated! Thanks in advance!

AGS
  • 14,288
  • 5
  • 52
  • 67
  • 1
    You could use a loop with for and save eacha value in a vector. Also pROC package would be better for your problem!!! – Duck May 13 '13 at 22:28
  • The function inside your `lapply` looks like it is just outputing a statement like `prediction(varmydata$V1)`. I am guessing you actually want to *run* that command. If so, you probably want something like `lapply(varlist,function(x) prediction(mydata['x']))`, but it is hard to tell without a reproducible situation. Also, it looks like your code has a missing quote. – nograpes May 13 '13 at 22:37
  • Thanks for your help! You solved it with the square brackets (and you are write I was missing a quote). – user2379487 May 13 '13 at 23:02
  • @user2379487 I reposted as an answer if you want to check it. – nograpes May 13 '13 at 23:32

2 Answers2

0

The function inside your lapply looks like it is just outputting a statement like prediction(varmydata$V1). I am guessing you actually want to run that command. If so, you probably want something like

lapply(varlist,function(x) prediction(mydata[x]))

but it is hard to tell without a reproducible situation. Also, it looks like your code has a missing quote.

nograpes
  • 18,623
  • 1
  • 44
  • 67
0

If I understand you correctly, you want to use the first column of mydata as predictions, and all other variables as labels, one after the other.

Is this the correct way to treat mydata? This way is rather uncommon. It is more common to have the same true labels for several diffent predictions (e.g. iterated cross validation, comparison of different classifiers).

However, to answer your original question:

predictions and labels need to have the same shape for ROCR::prediction, e.g.

  • either as matrix

    prediction (matrix (rep (mydata$V1, 10), 10), mydata [, -1])
    
  • or as lists:

    prediction (mydata [rep (1, ncol (mydata) - 1)], mydata [-1])
    
cbeleites unhappy with SX
  • 13,717
  • 5
  • 45
  • 57