Send output to:
Browser Blue - Charts White
Browser Black/White
CSV
Data X:
0 0 2 9 3 1 2 7 0 0 3 8 5 2 0 2 0 0 4 14 2 2 1 4 1 4 3 15 4 0 1 4 1 17 3 9 0 1 4 7 1 4 9 5 0 1 4 4 0 0 6 1 0 4 4 3 0 13 5 0 0 2 6 1 1 0 11 13 2 8 6 5 1 0 9 13 5 4 4 2 0 3 7 9 3 0 4 3 0 1 7 10 3 0 5 3 1 3 6 4 0 2 5 5 1 5 3 6 0 1 5 4 0 1 5 3 0 3 7 3 1 3 11 6 3 1 9 8 1 12 5 2 4 4 8 2 0 0 12 0 4 5 0 3 1 11 5 6 3 5 4 7 1 16 8 4 3 8 3 5 0 10 7 9 5 5 4 9 1 16 3 21 10 10 7 4 0 7 8 7 5 7 5 5 1 8 3 11 3 6 8 12 1 19 6 14 1 8 3 10 1 13 5 10 0 4 6 17 0 16 8 14 1 6 6 10 1 10 9 6 13 5 3 9 1 13 9 22 7 6 8 10 1 9 12 6 10 3 7 8 0 10 9 2 5 2 3 11 0 13 8 13 4 7 6 5 0 2 14 6 3 12 6 10 0 25 8 9 1 8 7 5 0 5 4 5 1 6 0 8 0 12 7 8 0 7 6 6 0 11 1 8 0 4 10 5 0 6 4 7 2 4 4 4 0 27 5 5 3 3 12 5 0 12 4 10 2 3 4 0 0 10 12 16 7 7 11 16 0 10 8 14 11 5 23 4 0 17 10 18 7 9 10 17 0 24 16 10 8 15 4 24 0 2 18 18 9 6 9 24 0 7 9 13 7 6 7 0 0 8 11 8 12 10 5 8 0 12 22 10 6 5 4 4 0 13 18 20 5 7 4 3 0 14 10 20 7 7 11 24 0 15 24 14 17 12 20 0 0 14 10 35 3 11 17 3 0 14 7 35 11 14 7 22 0 12 2 28 7 13 12 2 0 13 3 12 12 3 10 16 0 22 5 24 8 6 12 21 0 24 5 20 6 8 9 22 1 16 6 14 30 0 16 16 0 8 5 11 9 8 18 7 0 41 10 23 8 14 22 7 1 31 11 31 28 36 5 38 0 30 19 17 33 17 23 15 0 25 24 18 28 37 25 43 0 28 12 25 24 23 8 13 0 26 17 34 35 20 14 17 0 26 19 11 21 38 14 19 0 28 12 11 11 18 10 32 0 32 10 30 7 39 24 33 0 10 20 23 48 20 9 17 0 34 21 15 4 40 20 33 0 13 23 11 32 32 13 35 0 32 25 18 15 28 7 11 0 21 18 24 9 10 11 10 0 20 28 20 35 12 33 28 0 22 28 17 33 18 14 34 1 38 24 28 34 13 30 30 0 12 11 19 24 30 20 37 0 15 11 16 21 10 11 20 0 15 11 16 21 10 7 21 0 15 11 16 21 10 7 21
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