Send output to:
Browser Blue - Charts White
Browser Black/White
CSV
Data X:
1 18 17 15 8 8 7 23 1 21 16 12 19 6 4 24 1 23 14 13 23 9 0 18 1 19 17 11 16 11 6 22 1 21 16 15 8 7 8 16 1 19 15 17 10 9 7 16 1 20 16 18 3 11 13 18 0 23 5 12 1 10 12 12 1 24 14 16 10 10 10 16 0 17 12 19 7 6 11 11 0 21 12 14 13 6 13 8 1 16 5 15 14 7 12 20 1 19 11 18 15 8 10 22 0 19 17 16 11 7 11 17 0 18 9 19 18 6 9 9 0 17 10 20 18 8 10 10 0 17 16 19 12 10 12 11 0 18 9 12 14 11 9 16 1 20 12 13 15 9 11 17 0 18 12 14 16 9 12 11 0 35 10 25 30 17 15 20 0 32 16 25 25 14 16 20 0 30 16 20 32 14 12 25 1 29 15 28 38 13 19 30 0 34 16 23 28 17 18 35 0 25 11 14 25 10 20 33 0 37 19 15 26 10 16 39 0 28 12 23 25 15 20 38 0 29 10 18 29 20 20 50 0 32 12 23 28 14 19 35 0 32 18 21 37 15 16 40 0 31 14 16 34 19 17 36 0 34 10 16 31 13 16 49 0 29 17 23 26 16 22 35 1 34 16 25 36 18 18 39 0 28 15 23 32 16 20 30 0 29 19 22 29 17 19 32 0 31 14 24 36 16 16 35 0 31 15 18 30 13 21 32 0 26 17 16 29 14 22 43 0 38 40 46 55 27 28 83 0 35 32 52 50 24 29 65 0 35 41 48 51 23 32 85 0 36 40 37 65 26 28 100 0 36 31 47 50 25 28 60 0 32 25 54 49 28 27 76 0 35 41 37 52 26 31 67 0 38 48 37 64 19 28 60 0 30 28 41 50 19 31 66 0 36 43 30 48 20 28 56 0 35 48 34 44 24 27 64 0 33 36 55 50 20 31 77 0 35 48 30 53 20 29 65 0 30 45 33 50 23 27 100 0 35 33 48 57 25 26 93 0 38 45 47 51 25 31 81 0 34 25 36 54 25 29 76 0 33 32 24 49 20 27 62 0 32 35 31 55 19 28 60 0 35 39 31 51 18 28 74 0 50 52 57 99 38 42 106 0 47 40 45 104 31 39 85 0 47 53 48 103 27 41 80 0 60 55 35 101 30 43 83 0 45 56 35 102 47 40 80 0 48 49 52 98 34 41 80 0 47 58 49 104 34 38 82 0 46 57 54 97 32 38 82 0 62 55 42 96 34 36 87 0 69 53 40 93 40 37 84 0 59 52 34 74 36 39 100 0 65 64 54 97 50 41 110 0 57 48 38 105 47 43 99 0 58 66 41 70 45 42 111 0 56 49 54 84 31 39 123 0 68 52 37 99 21 41 105 0 50 67 35 70 28 38 104 0 70 53 41 84 31 40 72 0 69 62 47 91 40 42 90 0 71 40 45 86 36 41 91
Names of X columns:
Y X1 X2 X3 X4 X5 X6 X7
Chart options
R Code
library(brglm) roc.plot <- function (sd, sdc, newplot = TRUE, ...) { sall <- sort(c(sd, sdc)) sens <- 0 specc <- 0 for (i in length(sall):1) { sens <- c(sens, mean(sd >= sall[i], na.rm = T)) specc <- c(specc, mean(sdc >= sall[i], na.rm = T)) } if (newplot) { plot(specc, sens, xlim = c(0, 1), ylim = c(0, 1), type = 'l', xlab = '1-specificity', ylab = 'sensitivity', main = 'ROC plot', ...) abline(0, 1) } else lines(specc, sens, ...) npoints <- length(sens) area <- sum(0.5 * (sens[-1] + sens[-npoints]) * (specc[-1] - specc[-npoints])) lift <- (sens - specc)[-1] cutoff <- sall[lift == max(lift)][1] sensopt <- sens[-1][lift == max(lift)][1] specopt <- 1 - specc[-1][lift == max(lift)][1] list(area = area, cutoff = cutoff, sensopt = sensopt, specopt = specopt) } roc.analysis <- function (object, newdata = NULL, newplot = TRUE, ...) { if (is.null(newdata)) { sd <- object$fitted[object$y == 1] sdc <- object$fitted[object$y == 0] } else { sd <- predict(object, newdata, type = 'response')[newdata$y == 1] sdc <- predict(object, newdata, type = 'response')[newdata$y == 0] } roc.plot(sd, sdc, newplot, ...) } hosmerlem <- function (y, yhat, g = 10) { cutyhat <- cut(yhat, breaks = quantile(yhat, probs = seq(0, 1, 1/g)), include.lowest = T) obs <- xtabs(cbind(1 - y, y) ~ cutyhat) expect <- xtabs(cbind(1 - yhat, yhat) ~ cutyhat) chisq <- sum((obs - expect)^2/expect) P <- 1 - pchisq(chisq, g - 2) c('X^2' = chisq, Df = g - 2, 'P(>Chi)' = P) } x <- as.data.frame(t(y)) r <- brglm(x) summary(r) rc <- summary(r)$coeff try(hm <- hosmerlem(y[1,],r$fitted.values),silent=T) try(hm,silent=T) bitmap(file='test0.png') ra <- roc.analysis(r) dev.off() te <- array(0,dim=c(2,99)) for (i in 1:99) { threshold <- i / 100 numcorr1 <- 0 numfaul1 <- 0 numcorr0 <- 0 numfaul0 <- 0 for (j in 1:length(r$fitted.values)) { if (y[1,j] > 0.99) { if (r$fitted.values[j] >= threshold) numcorr1 = numcorr1 + 1 else numfaul1 = numfaul1 + 1 } else { if (r$fitted.values[j] < threshold) numcorr0 = numcorr0 + 1 else numfaul0 = numfaul0 + 1 } } te[1,i] <- numfaul1 / (numfaul1 + numcorr1) te[2,i] <- numfaul0 / (numfaul0 + numcorr0) } bitmap(file='test1.png') op <- par(mfrow=c(2,2)) plot((1:99)/100,te[1,],xlab='Threshold',ylab='Type I error', main='1 - Specificity') plot((1:99)/100,te[2,],xlab='Threshold',ylab='Type II error', main='1 - Sensitivity') plot(te[1,],te[2,],xlab='Type I error',ylab='Type II error', main='(1-Sens.) vs (1-Spec.)') plot((1:99)/100,te[1,]+te[2,],xlab='Threshold',ylab='Sum of Type I & II error', main='(1-Sens.) + (1-Spec.)') par(op) dev.off() load(file='createtable') a<-table.start() a<-table.row.start(a) a<-table.element(a,'Coefficients of Bias-Reduced Logistic Regression',5,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Variable',header=TRUE) a<-table.element(a,'Parameter',header=TRUE) a<-table.element(a,'S.E.',header=TRUE) a<-table.element(a,'t-stat',header=TRUE) a<-table.element(a,'2-sided p-value',header=TRUE) a<-table.row.end(a) for (i in 1:length(rc[,1])) { a<-table.row.start(a) a<-table.element(a,labels(rc)[[1]][i],header=TRUE) a<-table.element(a,rc[i,1]) a<-table.element(a,rc[i,2]) a<-table.element(a,rc[i,3]) a<-table.element(a,2*(1-pt(abs(rc[i,3]),r$df.residual))) a<-table.row.end(a) } a<-table.end(a) table.save(a,file='mytable.tab') a<-table.start() a<-table.row.start(a) a<-table.element(a,'Summary of Bias-Reduced Logistic Regression',2,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Deviance',1,TRUE) a<-table.element(a,r$deviance) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Penalized deviance',1,TRUE) a<-table.element(a,r$penalized.deviance) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Residual Degrees of Freedom',1,TRUE) a<-table.element(a,r$df.residual) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'ROC Area',1,TRUE) a<-table.element(a,ra$area) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Hosmer–Lemeshow test',2,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Chi-square',1,TRUE) phm <- array('NA',dim=3) for (i in 1:3) { try(phm[i] <- hm[i],silent=T) } a<-table.element(a,phm[1]) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Degrees of Freedom',1,TRUE) a<-table.element(a,phm[2]) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'P(>Chi)',1,TRUE) a<-table.element(a,phm[3]) a<-table.row.end(a) a<-table.end(a) table.save(a,file='mytable1.tab') a<-table.start() a<-table.row.start(a) a<-table.element(a,'Fit of Logistic Regression',4,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Index',1,TRUE) a<-table.element(a,'Actual',1,TRUE) a<-table.element(a,'Fitted',1,TRUE) a<-table.element(a,'Error',1,TRUE) a<-table.row.end(a) for (i in 1:length(r$fitted.values)) { a<-table.row.start(a) a<-table.element(a,i,1,TRUE) a<-table.element(a,y[1,i]) a<-table.element(a,r$fitted.values[i]) a<-table.element(a,y[1,i]-r$fitted.values[i]) a<-table.row.end(a) } a<-table.end(a) table.save(a,file='mytable2.tab') a<-table.start() a<-table.row.start(a) a<-table.element(a,'Type I & II errors for various threshold values',3,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Threshold',1,TRUE) a<-table.element(a,'Type I',1,TRUE) a<-table.element(a,'Type II',1,TRUE) a<-table.row.end(a) for (i in 1:99) { a<-table.row.start(a) a<-table.element(a,i/100,1,TRUE) a<-table.element(a,te[1,i]) a<-table.element(a,te[2,i]) a<-table.row.end(a) } a<-table.end(a) table.save(a,file='mytable3.tab')
Compute
Summary of computational transaction
Raw Input
view raw input (R code)
Raw Output
view raw output of R engine
Computing time
1 seconds
R Server
Big Analytics Cloud Computing Center
Click here to blog (archive) this computation