... | ... |
@@ -1,27 +1,24 @@ |
1 |
-get.mipp.logistic <- function(x.train, y.train, x.test, y.test){ |
|
2 |
- |
|
3 |
- y.train <- factor(y.train) |
|
4 |
- levels(y.train) <- c("1","0") |
|
5 |
- y.test <- factor(y.test) |
|
6 |
- levels(y.test) <- c("1","0") |
|
7 |
- |
|
8 |
- if(is.data.frame(x.train)) x.train <- as.matrix(x.train) |
|
9 |
- if(is.data.frame(x.test)) x.test <- as.matrix(x.test) |
|
10 |
- |
|
11 |
- fit <- glm(y.train ~ x.train, family="binomial") |
|
12 |
- |
|
13 |
- predx <- cbind(1, x.test)%*%t(matrix(fit$coef, nrow=1)) |
|
14 |
- prob <- 1/(1+exp(-predx)) |
|
15 |
- |
|
16 |
- postdf <- data.frame(prob, y.test) |
|
17 |
- post.prob <- ifelse(postdf$y.test=="1", 1-postdf$prob, postdf$prob) |
|
18 |
- ind <- ifelse(post.prob > .5, 1, 0) |
|
19 |
- |
|
20 |
- N <- length(y.test) |
|
21 |
- nMiss <- N - sum(ind) |
|
22 |
- Er <- nMiss/N |
|
23 |
- MiPP <- sum(post.prob)-nMiss |
|
24 |
- sMiPP <- MiPP/N |
|
25 |
- |
|
26 |
- return(list(N.Miss=nMiss, ErrorRate=Er, MiPP=MiPP, sMiPP=sMiPP)) |
|
27 |
-} |
|
1 |
+get.mipp.logistic <- function(x.train, y.train, x.test, y.test){ |
|
2 |
+ |
|
3 |
+ y.train <- factor(y.train); levels(y.train) <- c("1","0") |
|
4 |
+ y.test <- factor(y.test); levels(y.test) <- c("1","0") |
|
5 |
+ if(is.data.frame(x.train)) x.train <- as.matrix(x.train) |
|
6 |
+ if(is.data.frame(x.test)) x.test <- as.matrix(x.test) |
|
7 |
+ |
|
8 |
+ fit <- glm(y.train ~ x.train, family="binomial") |
|
9 |
+ |
|
10 |
+ predx <- cbind(1, x.test)%*%t(matrix(fit$coef, nrow=1)) |
|
11 |
+ prob <- 1/(1+exp(-predx)) |
|
12 |
+ |
|
13 |
+ postdf <- data.frame(prob, y.test) |
|
14 |
+ post.prob <- ifelse(postdf$y.test=="1", 1-postdf$prob, postdf$prob) |
|
15 |
+ ind <- ifelse(post.prob > .5, 1, 0) |
|
16 |
+ |
|
17 |
+ N <- length(y.test) |
|
18 |
+ nMiss <- N - sum(ind) |
|
19 |
+ Er <- nMiss/N |
|
20 |
+ MiPP <- sum(post.prob)-nMiss |
|
21 |
+ sMiPP <- MiPP/N |
|
22 |
+ |
|
23 |
+ return(list(N.Miss=nMiss, ErrorRate=Er, MiPP=MiPP, sMiPP=sMiPP)) |
|
24 |
+} |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/MiPP@11863 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,27 @@ |
1 |
+get.mipp.logistic <- function(x.train, y.train, x.test, y.test){ |
|
2 |
+ |
|
3 |
+ y.train <- factor(y.train) |
|
4 |
+ levels(y.train) <- c("1","0") |
|
5 |
+ y.test <- factor(y.test) |
|
6 |
+ levels(y.test) <- c("1","0") |
|
7 |
+ |
|
8 |
+ if(is.data.frame(x.train)) x.train <- as.matrix(x.train) |
|
9 |
+ if(is.data.frame(x.test)) x.test <- as.matrix(x.test) |
|
10 |
+ |
|
11 |
+ fit <- glm(y.train ~ x.train, family="binomial") |
|
12 |
+ |
|
13 |
+ predx <- cbind(1, x.test)%*%t(matrix(fit$coef, nrow=1)) |
|
14 |
+ prob <- 1/(1+exp(-predx)) |
|
15 |
+ |
|
16 |
+ postdf <- data.frame(prob, y.test) |
|
17 |
+ post.prob <- ifelse(postdf$y.test=="1", 1-postdf$prob, postdf$prob) |
|
18 |
+ ind <- ifelse(post.prob > .5, 1, 0) |
|
19 |
+ |
|
20 |
+ N <- length(y.test) |
|
21 |
+ nMiss <- N - sum(ind) |
|
22 |
+ Er <- nMiss/N |
|
23 |
+ MiPP <- sum(post.prob)-nMiss |
|
24 |
+ sMiPP <- MiPP/N |
|
25 |
+ |
|
26 |
+ return(list(N.Miss=nMiss, ErrorRate=Er, MiPP=MiPP, sMiPP=sMiPP)) |
|
27 |
+} |