Home » date » 2008 » Jan » 30 » attachments

Binghnetty Logistic Regression 1

R Software Module: rwasp_logisticregression.wasp (opens new window with default values)
Title produced by software: Bias-Reduced Logistic Regression
Date of computation: Wed, 30 Jan 2008 01:49:31 -0700
 
Cite this page as follows:
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL http://www.freestatistics.org/blog/date/2008/Jan/30/t1201683126on2c5tyr0czo91k.htm/, Retrieved Wed, 30 Jan 2008 09:52:09 +0100
 
User-defined keywords:
 
Dataseries X:
» Textbox « » Textfile « » CSV «
1 1 5.3 1 1 4.6 1 1 5.9 1 1 6.4 1 1 4.5 1 1 3.1 1 1 3.8 1 1 5.7 1 1 3.6 1 1 3.6 1 1 6.1 1 1 5.3 1 1 4.3 1 1 6.5 1 1 6.2 1 1 6.9 1 1 7.2 1 1 6.6 1 1 5.7 1 1 6.8 1 1 2.2 1 1 2.2 1 1 4.1 1 1 5.2 1 1 5.8 1 1 5.2 1 1 5.6 1 1 5.7 1 1 4.4 1 1 5.4 1 1 6.1 1 1 6.5 1 1 4.7 1 1 6.8 1 1 6.3 1 1 3.8 1 1 3.1 1 1 6.5 1 1 7.1 1 1 1.0 1 0 4.9 1 0 5.8 1 0 5.6 1 0 4.9 1 0 5.2 1 0 7.0 0 1 5.0 0 1 8.0 0 0 6.0 0 1 5.0 0 1 8.0 0 0 10.0 0 1 1.0 0 1 7.0 0 1 6.0 0 1 4.0 0 0 6.0 0 0 6.0 0 1 8.0 0 0 7.0 0 0 6.0 0 1 7.0 0 1 6.0 0 1 6.0 0 0 6.0 0 1 5.0 0 1 6.0 0 1 7.0 0 1 6.0 0 1 3.0 0 1 6.0 0 1 3.0 0 1 7.0 0 1 5.0 0 1 7.0 0 1 5.0 0 1 7.0 0 1 7.0 0 1 6.0 0 1 7.0 0 1 5.0 0 1 6.0 0 1 6.0 0 1 6.0 0 1 5.0 0 1 8.0 0 0 3.0 0 0 5.0 0 0 6.0 0 0 6.0 0 1 6.0 0 0 99.0 0 1 8.0 0 1 8.0 0 0 4.0 0 1 9.0 0 1 5.0 0 0 6.0 0 1 99.0 0 1 6.0 0 1 6.0 0 1 7.0 0 1 5.0 0 0 99.0 0 1 6.0 0 1 6.0 0 0 6.0 0 1 7.0 0 0 8.0 0 0 7.0 0 1 6.0 0 2 6.0 0 1 5.0 0 1 7.0 0 1 6.0 0 0 7.0 0 1 9.0 0 1 6.0 0 1 7.0 0 1 6.0 0 1 7.0 0 1 7.0 0 0 8.0 0 1 4.0 0 0 5.0 0 1 6.0 0 1 6.0 0 1 6.0 0 1 7.0
 
Text written by user:
 
Output produced by software:

Enter (or paste) a matrix (table) containing all data (time) series. Every column represents a different variable and must be delimited by a space or Tab. Every row represents a period in time (or category) and must be delimited by hard returns. The easiest way to enter data is to copy and paste a block of spreadsheet cells. Please, do not use commas or spaces to seperate groups of digits!


Summary of compuational transaction
Raw Inputview raw input (R code)
Raw Outputview raw output of R engine
Computing time28 seconds
R Server'Gwilym Jenkins' @ 72.249.127.135


Coefficients of Bias-Reduced Logistic Regression
VariableParameterS.E.t-stat2-sided p-value
(Intercept)-0.8258900229437280.480135282129261-1.720119419845890.0878658393608114
snoring0.5189238978267260.4717397076556311.100021663229460.273419900430739
sleep_time-0.02314286242229810.0275856292428259-0.8389463303004680.403088263277221


Summary of Bias-Reduced Logistic Regression
Deviance162.926225935245
Penalized deviance150.860973421723
Residual Degrees of Freedom126
ROC Area0.685699319015191
Hosmer–Lemeshow test
Chi-square70.5399502271576
Degrees of Freedom8
P(>Chi)3.83659770619715e-12


Fit of Logistic Regression
IndexActualFittedError
110.3942162886024780.605783711397522
210.3980915646438480.601908435356152
310.3909051599675890.609094840032411
410.3881535260041790.611846473995821
510.398646232148080.60135376785192
610.4064383085961700.59356169140383
710.4025361189925570.597463881007444
810.3920077700792600.607992229920741
910.403649794752070.59635020524793
1010.403649794752070.59635020524793
1110.3898036628253270.610196337174673
1210.3942162886024780.605783711397522
1310.3997563466577420.600243653342258
1410.3876040477916940.612395952208306
1510.389253334774720.61074666522528
1610.3854090052155780.614590994784422
1710.3837657718182810.616234228181719
1810.3870548553613410.612945144638659
1910.3920077700792600.607992229920741
2010.3859573328308750.614042667169125
2110.4114727525580040.588527247441996
2210.4114727525580040.588527247441996
2310.4008674917967580.599132508203242
2410.3947690979405610.605230902059439
2510.3914563265350330.608543673464967
2610.3947690979405610.605230902059439
2710.392559489331250.60744051066875
2810.3920077700792600.607992229920741
2910.3992011599206730.600798840079327
3010.3936637498687240.606336250131276
3110.3898036628253270.610196337174673
3210.3876040477916940.612395952208306
3310.3975371587092460.602462841290754
3410.3859573328308750.614042667169125
3510.3887032887492940.611296711250706
3610.4025361189925570.597463881007444
3710.4064383085961700.59356169140383
3810.3876040477916940.612395952208306
3910.3843132234754660.615686776524534
4010.4182141050472980.581785894952702
4110.2810437717194920.718956228280508
4210.2768544448043390.72314555519566
4310.2777820695072060.722217930492794
4410.2810437717194920.718956228280508
4510.2796430453757630.720356954624237
4610.2713290317116260.728670968288374
4700.395875523296432-0.395875523296432
4800.379396861385598-0.379396861385598
4900.275928734306748-0.275928734306748
5000.395875523296432-0.395875523296432
5100.379396861385598-0.379396861385598
5200.257822198062316-0.257822198062316
5300.418214105047298-0.418214105047298
5400.384860968352024-0.384860968352024
5500.390354271643189-0.390354271643189
5600.401423447577954-0.401423447577954
5700.275928734306748-0.275928734306748
5800.275928734306748-0.275928734306748
5900.379396861385598-0.379396861385598
6000.271329031711626-0.271329031711626
6100.275928734306748-0.275928734306748
6200.384860968352024-0.384860968352024
6300.390354271643189-0.390354271643189
6400.390354271643189-0.390354271643189
6500.275928734306748-0.275928734306748
6600.395875523296432-0.395875523296432
6700.390354271643189-0.390354271643189
6800.384860968352024-0.384860968352024
6900.390354271643189-0.390354271643189
7000.406996742048269-0.406996742048269
7100.390354271643189-0.390354271643189
7200.406996742048269-0.406996742048269
7300.384860968352024-0.384860968352024
7400.395875523296432-0.395875523296432
7500.384860968352024-0.384860968352024
7600.395875523296432-0.395875523296432
7700.384860968352024-0.384860968352024
7800.384860968352024-0.384860968352024
7900.390354271643189-0.390354271643189
8000.384860968352024-0.384860968352024
8100.395875523296432-0.395875523296432
8200.390354271643189-0.390354271643189
8300.390354271643189-0.390354271643189
8400.390354271643189-0.390354271643189
8500.395875523296432-0.395875523296432
8600.379396861385598-0.379396861385598
8700.290013473631371-0.290013473631371
8800.280576388320880-0.280576388320880
8900.275928734306748-0.275928734306748
9000.275928734306748-0.275928734306748
9100.390354271643189-0.390354271643189
9200.0424100863065165-0.0424100863065165
9300.379396861385598-0.379396861385598
9400.379396861385598-0.379396861385598
9500.285271483543346-0.285271483543346
9600.373963169926946-0.373963169926946
9700.395875523296432-0.395875523296432
9800.275928734306748-0.275928734306748
9900.0692601885400124-0.0692601885400124
10000.390354271643189-0.390354271643189
10100.390354271643189-0.390354271643189
10200.384860968352024-0.384860968352024
10300.395875523296432-0.395875523296432
10400.0424100863065165-0.0424100863065165
10500.390354271643189-0.390354271643189
10600.390354271643189-0.390354271643189
10700.275928734306748-0.275928734306748
10800.384860968352024-0.384860968352024
10900.266777754860427-0.266777754860427
11000.271329031711626-0.271329031711626
11100.390354271643189-0.390354271643189
11200.518267015817867-0.518267015817867
11300.395875523296432-0.395875523296432
11400.384860968352024-0.384860968352024
11500.390354271643189-0.390354271643189
11600.271329031711626-0.271329031711626
11700.373963169926946-0.373963169926946
11800.390354271643189-0.390354271643189
11900.384860968352024-0.384860968352024
12000.390354271643189-0.390354271643189
12100.384860968352024-0.384860968352024
12200.384860968352024-0.384860968352024
12300.266777754860427-0.266777754860427
12400.401423447577954-0.401423447577954
12500.280576388320880-0.280576388320880
12600.390354271643189-0.390354271643189
12700.390354271643189-0.390354271643189
12800.390354271643189-0.390354271643189
12900.384860968352024-0.384860968352024


Type I & II errors for various threshold values
ThresholdType IType II
0.0101
0.0201
0.0301
0.0401
0.0500.975903614457831
0.0600.975903614457831
0.0700.963855421686747
0.0800.963855421686747
0.0900.963855421686747
0.100.963855421686747
0.1100.963855421686747
0.1200.963855421686747
0.1300.963855421686747
0.1400.963855421686747
0.1500.963855421686747
0.1600.963855421686747
0.1700.963855421686747
0.1800.963855421686747
0.1900.963855421686747
0.200.963855421686747
0.2100.963855421686747
0.2200.963855421686747
0.2300.963855421686747
0.2400.963855421686747
0.2500.963855421686747
0.2600.951807228915663
0.2700.927710843373494
0.280.08695652173913040.783132530120482
0.290.1304347826086960.746987951807229
0.30.1304347826086960.734939759036145
0.310.1304347826086960.734939759036145
0.320.1304347826086960.734939759036145
0.330.1304347826086960.734939759036145
0.340.1304347826086960.734939759036145
0.350.1304347826086960.734939759036145
0.360.1304347826086960.734939759036145
0.370.1304347826086960.734939759036145
0.380.1304347826086960.63855421686747
0.390.4347826086956520.457831325301205
0.40.7826086956521740.072289156626506
0.410.9347826086956520.0240963855421687
0.4210.0120481927710843
0.4310.0120481927710843
0.4410.0120481927710843
0.4510.0120481927710843
0.4610.0120481927710843
0.4710.0120481927710843
0.4810.0120481927710843
0.4910.0120481927710843
0.510.0120481927710843
0.5110.0120481927710843
0.5210
0.5310
0.5410
0.5510
0.5610
0.5710
0.5810
0.5910
0.610
0.6110
0.6210
0.6310
0.6410
0.6510
0.6610
0.6710
0.6810
0.6910
0.710
0.7110
0.7210
0.7310
0.7410
0.7510
0.7610
0.7710
0.7810
0.7910
0.810
0.8110
0.8210
0.8310
0.8410
0.8510
0.8610
0.8710
0.8810
0.8910
0.910
0.9110
0.9210
0.9310
0.9410
0.9510
0.9610
0.9710
0.9810
0.9910
 
Charts produced by software:
http://127.0.0.1/wessadotnet/public_html/freestatisticsdotorg/blog/date/2008/Jan/30/t1201683126on2c5tyr0czo91k/1qlfa1201682941.png (open in new window)
http://127.0.0.1/wessadotnet/public_html/freestatisticsdotorg/blog/date/2008/Jan/30/t1201683126on2c5tyr0czo91k/1qlfa1201682941.ps (open in new window)


http://127.0.0.1/wessadotnet/public_html/freestatisticsdotorg/blog/date/2008/Jan/30/t1201683126on2c5tyr0czo91k/2igvy1201682941.png (open in new window)
http://127.0.0.1/wessadotnet/public_html/freestatisticsdotorg/blog/date/2008/Jan/30/t1201683126on2c5tyr0czo91k/2igvy1201682941.ps (open in new window)


 
Parameters (Session):
 
Parameters (R input):
 
R code (references can be found in the software module):
library(brlr)
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 <- brlr(x)
summary(r)
rc <- summary(r)$coeff
hm <- hosmerlem(y[1,],r$fitted.values)
hm
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)
a<-table.element(a,hm[1])
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'Degrees of Freedom',1,TRUE)
a<-table.element(a,hm[2])
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'P(>Chi)',1,TRUE)
a<-table.element(a,hm[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')
 





Copyright

Creative Commons License

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.

Software written by Ed van Stee & Patrick Wessa


Disclaimer

Information provided on this web site is provided "AS IS" without warranty of any kind, either express or implied, including, without limitation, warranties of merchantability, fitness for a particular purpose, and noninfringement. We use reasonable efforts to include accurate and timely information and periodically update the information, and software without notice. However, we make no warranties or representations as to the accuracy or completeness of such information (or software), and we assume no liability or responsibility for errors or omissions in the content of this web site, or any software bugs in online applications. Your use of this web site is AT YOUR OWN RISK. Under no circumstances and under no legal theory shall we be liable to you or any other person for any direct, indirect, special, incidental, exemplary, or consequential damages arising from your access to, or use of, this web site.


Privacy Policy

We may request personal information to be submitted to our servers in order to be able to:

  • personalize online software applications according to your needs
  • enforce strict security rules with respect to the data that you upload (e.g. statistical data)
  • manage user sessions of online applications
  • alert you about important changes or upgrades in resources or applications

We NEVER allow other companies to directly offer registered users information about their products and services. Banner references and hyperlinks of third parties NEVER contain any personal data of the visitor.

We do NOT sell, nor transmit by any means, personal information, nor statistical data series uploaded by you to third parties.

We carefully protect your data from loss, misuse, alteration, and destruction. However, at any time, and under any circumstance you are solely responsible for managing your passwords, and keeping them secret.

We store a unique ANONYMOUS USER ID in the form of a small 'Cookie' on your computer. This allows us to track your progress when using this website which is necessary to create state-dependent features. The cookie is used for NO OTHER PURPOSE. At any time you may opt to disallow cookies from this website - this will not affect other features of this website.

We examine cookies that are used by third-parties (banner and online ads) very closely: abuse from third-parties automatically results in termination of the advertising contract without refund. We have very good reason to believe that the cookies that are produced by third parties (banner ads) do NOT cause any privacy or security risk.

FreeStatistics.org is safe. There is no need to download any software to use the applications and services contained in this website. Hence, your system's security is not compromised by their use, and your personal data - other than data you submit in the account application form, and the user-agent information that is transmitted by your browser - is never transmitted to our servers.

As a general rule, we do not log on-line behavior of individuals (other than normal logging of webserver 'hits'). However, in cases of abuse, hacking, unauthorized access, Denial of Service attacks, illegal copying, hotlinking, non-compliance with international webstandards (such as robots.txt), or any other harmful behavior, our system engineers are empowered to log, track, identify, publish, and ban misbehaving individuals - even if this leads to ban entire blocks of IP addresses, or disclosing user's identity.


FreeStatistics.org is powered by