logic - Avoiding a for loop in R in an attempt to evaluate percentage of true positives/negatives when using logistic regression -
what got: matrix got predicted probability of outcome (from logistic regression model) , known outcome. curious got 2 regression models , independent test dataset wish compare these 2 models doing this.
> head(matrixcomb) probcomb outcomb [1,] 0.9999902 1 [2,] 0.9921736 0 [3,] 0.9901175 1 [4,] 0.9815581 0 [5,] 0.7692992 0 [6,] 0.7369990 0
what want: graph can plot how prediction model yields correct outcomes (one line positives , 1 line negatives) function of cut off value probability. problem unable figure out how without switching perl , use for-loop iterate through matrix.
in perl start @ probability 0.1 , in reach run of for-loop increase value 0.1. in first iteration count probabilities <0.1 , outcome = 0 true negatives, probability < 0.1 , outcome 1 false negatives probability > 0.1 , outcome = 0 false positives , probability > 0.1 , outcome = 1 true positives.
the process repeated , results of each iteration printed [probability, true positives/total positives, true negatives/total negatives]. make easy me print out in open office calc.
the reason asking operation complex me find similar case here on stackoverflow or in tutorial. learn way in efficient manner in r environment.
you can r draw curves based on roc analysis. crude version using rocr
package , made prettier
ss <- 1000 # sample size mydf <- data.frame(probcomb = runif(ss)) # predictions illustration mydf$outcomb <- 0 + (runif(ss) < mydf$probcomb) # actuals illustration library(rocr) pred <- prediction(mydf$probcomb, mydf$outcomb) perfp <- performance(pred, "tpr") perfn <- performance(pred, "tnr") plot(perfp, col="green", ylab="true positive (green) , true negative (red) rates") plot(perfn, col="red", ylab="true negative rate", add=true)
to produce
if must, can find data in perfp
, perfn
.
Comments
Post a Comment