R version 3.0.1 (2013-05-16) -- "Good Sport" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: i686-pc-linux-gnu (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- array(list(1 + ,0 + ,4 + ,3 + ,6 + ,8 + ,4 + ,15 + ,14 + ,1 + ,2 + ,2 + ,2 + ,3 + ,4 + ,4 + ,5 + ,2 + ,1 + ,10 + ,10 + ,4 + ,3 + ,1 + ,0 + ,5 + ,5 + ,4 + ,2 + ,0 + ,10 + ,13 + ,6 + ,4 + ,8 + ,5 + ,2 + ,5 + ,4 + ,2 + ,2 + ,2 + ,4 + ,2 + ,17 + ,15 + ,0 + ,0 + ,4 + ,6 + ,7 + ,1 + ,2 + ,5 + ,9 + ,2 + ,2 + ,7 + ,3 + ,1 + ,3 + ,0 + ,2 + ,8 + ,8 + ,3 + ,3 + ,0 + ,2 + ,1 + ,0 + ,4 + ,2 + ,3 + ,6 + ,5 + ,1 + ,2 + ,3 + ,5 + ,7 + ,5 + ,5 + ,2 + ,2 + ,2 + ,0 + ,1 + ,3 + ,2 + ,4 + ,4 + ,1 + ,0 + ,5 + ,1 + ,2 + ,1 + ,0 + ,6 + ,2 + ,4 + ,3 + ,17 + ,10 + ,1 + ,4 + ,1 + ,2 + ,1 + ,3 + ,2 + ,2 + ,9 + ,9 + ,1 + ,0 + ,0 + ,3 + ,2 + ,0 + ,1 + ,1 + ,2 + ,2 + ,5 + ,3 + ,4 + ,6 + ,10 + ,3 + ,6 + ,9 + ,5 + ,2 + ,5 + ,4 + ,0 + ,1 + ,1 + ,2 + ,1 + ,2 + ,2 + ,1 + ,6 + ,2 + ,3 + ,2 + ,12 + ,8 + ,2 + ,3 + ,3 + ,3 + ,11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,'X3' + ,'X4' + ,'X5' + ,'X6' + ,'X7' + ,'X8' + ,'X9' + ,'X10' + ,'X11' + ,'X12' + ,'X13' + ,'X14' + ,'X15' + ,'X16' + ,'X17' + ,'X18' + ,'X19' + ,'X20' + ,'X21' + ,'X22') + ,1:42)) > y <- array(NA,dim=c(23,42),dimnames=list(c('Y','X1','X2','X3','X4','X5','X6','X7','X8','X9','X10','X11','X12','X13','X14','X15','X16','X17','X18','X19','X20','X21','X22'),1:42)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: > library(brglm) Loading required package: profileModel > 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) Call: brglm(formula = x) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -0.713155 1.854329 -0.385 0.701 X1 0.101743 0.477005 0.213 0.831 X2 0.316303 0.424433 0.745 0.456 X3 -0.763263 0.841613 -0.907 0.364 X4 -0.235088 0.468710 -0.502 0.616 X5 -0.060651 0.524856 -0.116 0.908 X6 -0.107492 0.560175 -0.192 0.848 X7 -0.134157 0.296311 -0.453 0.651 X8 0.330698 0.416556 0.794 0.427 X9 -0.067381 0.334511 -0.201 0.840 X10 0.202466 0.388654 0.521 0.602 X11 -0.059676 0.147127 -0.406 0.685 X12 0.159089 0.323467 0.492 0.623 X13 0.023833 0.306728 0.078 0.938 X14 0.082181 0.275700 0.298 0.766 X15 -0.007038 0.259494 -0.027 0.978 X16 0.257370 0.392031 0.657 0.511 X17 0.097554 0.246193 0.396 0.692 X18 -0.031881 0.257708 -0.124 0.902 X19 0.143654 0.259383 0.554 0.580 X20 -0.128806 0.232392 -0.554 0.579 X21 -0.066976 0.199131 -0.336 0.737 X22 0.146096 0.274502 0.532 0.595 (Dispersion parameter for binomial family taken to be 1) Null deviance: 19.543 on 41 degrees of freedom Residual deviance: 27.830 on 19 degrees of freedom Penalized deviance: -41.27905 AIC: 73.83 > rc <- summary(r)$coeff > try(hm <- hosmerlem(y[1,],r$fitted.values),silent=T) > try(hm,silent=T) X^2 Df P(>Chi) 10.2922665 8.0000000 0.2451089 > postscript(file="/var/wessaorg/rcomp/tmp/1u4ph1378118543.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > ra <- roc.analysis(r) > dev.off() null device 1 > 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) + } > postscript(file="/var/wessaorg/rcomp/tmp/2nwbe1378118543.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > 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() null device 1 > > #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/rcomp/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="/var/wessaorg/rcomp/tmp/3pfaf1378118543.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="/var/wessaorg/rcomp/tmp/42nrn1378118544.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="/var/wessaorg/rcomp/tmp/5j1cu1378118544.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="/var/wessaorg/rcomp/tmp/6ijsb1378118544.tab") > > try(system("convert tmp/1u4ph1378118543.ps tmp/1u4ph1378118543.png",intern=TRUE)) character(0) > try(system("convert tmp/2nwbe1378118543.ps tmp/2nwbe1378118543.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 4.402 1.456 5.969