This runs fine when I specify everything, but just trying to generalize it a bit with "score" and "outcome" and it fails (see the end). Any idea how to do this? (I have the indices thing because I want to bootstrap this later)
library(PRROC)
df <- iris %>% filter(Species != "virginica") %>% mutate(outcome_versi = ifelse(Species == "versicolor", 1, 0)) %>% select(Sepal.Length, outcome_versi)
#Iris single AUC
fc <- function(data, indices){
d <- data[indices,]
versi.y <- d %>% filter(outcome_versi == 1) %>% select(Sepal.Length)
versi.n <- d %>% filter(outcome_versi == 0)%>% select(Sepal.Length)
prroc.sepal.length <-pr.curve(scores.class0 = versi.y$Sepal.Length, scores.class1 = versi.n$Sepal.Length, curve=T)
return(prroc.sepal.length$auc.integral)
}
fc(df)
#AUC = 0.94
#Iris single AUC - functionalized
fcf <- function(score, outcome, data, indices){
d <- data[indices,]
test.pos <- d %>% filter(outcome==1) %>% select(score)
test.neg <- d %>% filter(outcome==0) %>% select(score)
prroc.test <-pr.curve(scores.class0 = test.pos$score, scores.class1 = test.neg$score, curve=T)
return(prroc.test$auc.integral)
}
fcf(data=df, score=Sepal.Length, outcome = outcome_versi)
#Error: 'outcome' not found```