Free Statistics

of Irreproducible Research!

Author's title

Author*Unverified author*
R Software Modulerwasp_logisticregression.wasp
Title produced by softwareBias-Reduced Logistic Regression
Date of computationSun, 25 Mar 2018 20:08:23 +0200
Cite this page as followsStatistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?v=date/2018/Mar/25/t152200135767j514wzcqp6kvn.htm/, Retrieved Mon, 29 Apr 2024 13:48:21 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=315015, Retrieved Mon, 29 Apr 2024 13:48:21 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact148
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-       [Bias-Reduced Logistic Regression] [] [2018-03-25 18:08:23] [d41d8cd98f00b204e9800998ecf8427e] [Current]
Feedback Forum

Post a new message
Dataseries X:
Department,Age,Gender,Monthly Income,Months At Company,JobSatisfaction,Satisfaction with Manager,Satisfaction with Company,Attrition
1,22,2,23972,6,3,1,1,0
2,38,1,20520,10,3,1,1,1
1,26,1,8360,0,2,1,1,1
2,35,1,11636,8,3,1,1,1
1,35,2,13872,2,2,1,1,0
1,0,2,12272,7,1,1,1,0
2,34,2,10680,1,4,1,1,0
1,20,2,10772,1,4,3,1,0
1,27,1,38104,9,4,1,2,1
3,14,1,20948,7,2,1,1,1
1,34,1,9704,5,4,1,1,1
2,34,1,16772,9,3,1,1,1
1,20,2,11644,5,2,1,1,0
1,39,2,10644,2,4,1,5,0
1,24,1,8112,4,2,1,1,0
3,35,1,39920,10,3,1,1,1
1,28,2,13192,6,4,4,1,0
3,0,2,11740,1,4,1,1,1
1,31,1,61708,25,4,1,1,0
1,0,1,15776,3,4,1,1,1
3,35,2,16044,4,2,1,1,0
3,34,2,13628,5,2,1,1,1
1,15,1,47976,12,3,1,1,1
2,28,2,4928,0,3,1,1,1
1,32,1,11840,4,1,3,1,0
1,38,1,76376,14,4,1,5,1
1,0,2,15676,10,3,1,1,0
2,21,2,27300,9,4,3,2,0
1,0,1,40992,22,3,1,1,1
1,0,2,75788,2,3,1,1,0
2,40,2,9984,1,3,1,1,0
2,0,1,25860,4,2,1,1,1
1,0,1,8824,10,4,1,1,1
3,26,2,8344,1,4,1,1,0
2,28,2,9172,2,2,1,1,0
2,42,2,10580,5,3,1,1,0
1,0,2,10732,3,3,1,1,1
1,21,2,8056,2,4,1,1,0
1,23,1,13676,1,3,2,1,0
1,26,1,21504,5,3,1,1,1
1,40,1,7804,1,1,1,1,0
3,27,1,9364,1,4,1,1,0
1,0,2,9172,1,1,1,1,0
3,33,1,34904,9,3,1,2,1
1,19,1,16044,12,3,1,1,1
1,0,2,78180,22,4,1,1,0
1,0,2,18272,9,2,1,1,0
1,0,1,12088,1,3,1,1,1
1,0,2,23088,9,2,2,1,0
1,18,1,9076,1,1,1,1,0
1,27,2,21524,1,2,4,1,0
1,21,2,13764,2,4,1,1,0
2,49,1,21816,4,3,1,1,1
3,29,1,39536,4,1,1,1,1
2,24,2,16628,2,4,1,1,0
2,0,2,53832,15,3,1,1,1
3,21,1,36276,9,3,1,1,1
1,28,2,16056,2,4,1,1,0
3,25,1,23660,7,2,1,2,1
1,31,2,23972,7,2,5,2,0
1,22,2,24648,9,1,1,1,0
2,38,1,9624,10,3,1,1,1
2,45,2,74960,27,2,1,1,0
1,24,2,30548,21,3,3,2,0
2,0,2,40384,17,2,1,1,0
1,0,2,59024,5,2,1,1,1
3,29,1,25996,6,1,1,1,1
1,22,2,38896,1,3,1,1,0
1,27,1,8776,3,2,4,2,1
1,26,2,13552,1,3,2,1,0
3,32,2,21892,4,2,1,1,0
1,26,1,10812,5,2,5,2,0
3,21,2,10004,1,2,1,1,0
1,26,2,24880,10,3,1,1,0
1,32,2,12152,1,1,1,1,1
1,25,2,17696,11,3,1,1,0
1,0,2,17248,15,3,1,1,0
1,0,2,52980,0,3,1,1,0
3,39,2,54656,5,4,1,2,1
1,30,1,20084,4,3,1,1,1
1,22,2,20504,10,4,1,1,0
1,29,2,11436,6,4,1,1,1
1,0,1,40956,1,1,1,1,1
2,28,2,21316,13,4,1,1,0
3,27,1,17300,5,4,1,1,1
1,33,1,29040,6,1,3,1,1
1,26,2,9288,0,3,1,3,0
1,0,2,8300,4,1,1,1,0
2,23,1,16608,11,2,3,2,1
1,24,2,38476,9,3,1,1,0
1,29,2,54012,22,4,1,1,0
1,20,2,21764,10,3,1,1,0
2,46,2,20836,11,4,1,1,0
1,26,2,42692,10,4,1,2,0
1,29,2,20040,11,4,1,1,0
1,0,2,54196,4,4,1,1,0
2,39,2,19996,3,2,1,1,0
2,23,2,16884,5,4,1,1,1
3,34,1,55488,37,1,1,1,1
3,34,2,8168,3,4,1,1,0
1,28,1,8292,3,2,1,1,0
1,0,2,11824,1,3,1,1,0
2,21,2,11704,1,4,1,1,0
1,33,2,19236,16,3,1,1,0
1,37,2,20652,1,2,2,1,0
1,28,2,75376,3,4,1,1,0
1,21,1,72688,8,3,1,1,1
1,0,2,22976,6,3,1,1,1
1,38,2,11556,2,4,1,1,0
1,0,1,11484,0,4,1,1,1
2,47,2,29936,13,4,1,1,0
1,26,1,24296,9,2,1,1,0
1,22,2,69312,5,3,1,1,0
1,20,1,11096,5,4,1,1,0
1,37,1,18020,1,3,1,1,0
1,21,2,29712,5,1,1,1,0
1,24,2,46524,11,4,1,1,0
3,29,2,38952,9,4,1,1,0
2,24,2,11340,1,1,1,1,0
1,32,1,67836,25,3,4,2,0
3,21,2,10452,10,1,2,1,0
1,0,2,24584,7,1,1,1,0
3,33,2,19852,5,4,1,1,0
3,33,1,78148,20,3,1,1,1
2,29,2,24688,7,3,1,1,0
1,28,2,9472,5,2,1,1,1
1,0,2,41248,40,4,1,1,0
1,24,2,6700,0,3,1,1,1
1,0,1,10092,2,4,1,1,1
1,45,2,26268,15,4,1,1,0
1,33,2,18956,3,1,1,1,0
1,20,2,36832,2,4,1,1,0
1,47,1,18236,2,2,1,1,0
3,29,1,32756,9,1,1,1,1
3,25,2,11768,8,3,1,1,0
3,23,2,19764,3,4,1,1,0
2,23,1,42600,4,2,1,2,1
2,37,2,23608,15,4,1,1,0
1,23,2,34556,2,3,1,1,0
2,24,2,25388,11,3,1,1,0
1,0,1,16800,5,4,1,2,0
1,22,1,13808,6,3,1,1,1
1,24,1,17268,3,3,1,1,1
1,27,2,10528,5,2,1,1,0
3,18,2,18672,8,4,1,1,0
3,19,2,12816,3,2,1,1,0
1,27,2,10880,5,4,1,1,1
1,25,1,68724,7,4,2,2,0
3,37,2,8952,5,1,1,2,0
3,42,2,5932,1,4,1,1,0




Summary of computational transaction
Raw Input view raw input (R code)
Raw Outputview raw output of R engine
Computing time0 seconds
R ServerBig Analytics Cloud Computing Center

\begin{tabular}{lllllllll}
\hline
Summary of computational transaction \tabularnewline
Raw Input view raw input (R code)  \tabularnewline
Raw Outputview raw output of R engine  \tabularnewline
Computing time0 seconds \tabularnewline
R ServerBig Analytics Cloud Computing Center \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=315015&T=0

[TABLE]
[ROW]
Summary of computational transaction[/C][/ROW] [ROW]Raw Input[/C] view raw input (R code) [/C][/ROW] [ROW]Raw Output[/C]view raw output of R engine [/C][/ROW] [ROW]Computing time[/C]0 seconds[/C][/ROW] [ROW]R Server[/C]Big Analytics Cloud Computing Center[/C][/ROW] [/TABLE] Source: https://freestatistics.org/blog/index.php?pk=315015&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=315015&T=0

As an alternative you can also use a QR Code:  

The GUIDs for individual cells are displayed in the table below:

Summary of computational transaction
Raw Input view raw input (R code)
Raw Outputview raw output of R engine
Computing time0 seconds
R ServerBig Analytics Cloud Computing Center



Parameters (Session):
Parameters (R input):
R code (references can be found in the software module):
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')