::Free Statistics and Forecasting Software::

v1.1.22-r6
 
  Black&White | Blue Theme | Normal Fontsize | Increase Fontsize | Decrease Fontsize | Toggle underline | Secure website (SSL)
 
 
This software module is powered by R

:: Bias-Reduced Logistic Regression - Free Statistics Software (Calculator) ::

All rights reserved. The non-commercial (academic) use of this software is free of charge. The only thing that is asked in return is to cite this software when results are used in publications.

This free online software (calculator) computes the Bias-Reduced Logistic Regression (maximum penalized likelihood) as proposed by David Firth. The penalty function is the Jeffreys invariant prior which removes the O(1/n) term from the asymptotic bias of estimated coefficients (Firth, 1993). It always yields finite estimates and standard errors (unlike the Maximum Likelihood Estimation in situations of (quasi-)complete discrimination).

Note: the first column (=endogenous series) must be a binary variable.

Click here to edit the underlying code of this R Module.

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!

Send output to:
Data X:
Names of X columns:
Sample Range:
(leave blank to include all observations)
From:
To:
Chart options
Width:
Height:

Click here to edit the underlying code of this R Module.






Cite this software as:
Wessa P., (2008), Bias Reduced Logistic Regression (v1.0.2) in Free Statistics Software (v1.1.22-r6), Office for Research Development and Education, URL http://www.wessa.net/rwasp_logisticregression.wasp/
The R code is based on :
Firth, D. (1993) Bias reduction of maximum likelihood estimates., Biometrika, 80, 27-38.
Firth, D. (1992) Bias reduction, the Jeffreys prior and GLIM. In Advances in GLIM and Statistical Modelling, Eds. L Fahrmeir, B J Francis, R Gilchrist and G Tutz, pp91-100., New York: Springer.
Heinze, G. and Schemper, M. (2002) A solution to the problem of separation in logistic regression., Statistics in Medicine, 21, 2409-2419.
Zorn, C (2005). A solution to separation in binary response models., Political Analysis, 13, 157-170.
P.D.M. Macdonald, R Functions for ROC Curves and the Hosmer-Lemeshow Test, URL http://www.math.mcmaster.ca/peter/s4f03/s4f03_0607/rochl.html, retrieved 2008/01/28
Viv Bewick, Liz Cheek, and Jonathan Ball, Statistics review 14: Logistic regression, Crit Care. 2005; 9(1): 112–118. Published online 2005 January 13. doi: 10.1186/cc3045. URL http://ccforum.com/content/9/1/112

Source code of R module
1library(brlr)
2roc.plot <- function (sd, sdc, newplot = TRUE, ...)
3{
4sall <- sort(c(sd, sdc))
5sens <- 0
6specc <- 0
7for (i in length(sall):1) {
8sens <- c(sens, mean(sd >= sall[i], na.rm = T))
9specc <- c(specc, mean(sdc >= sall[i], na.rm = T))
10}
11if (newplot) {
12plot(specc, sens, xlim = c(0, 1), ylim = c(0, 1), type = "l",
13xlab = "1-specificity", ylab = "sensitivity", main = "ROC plot", ...)
14abline(0, 1)
15}
16else lines(specc, sens, ...)
17npoints <- length(sens)
18area <- sum(0.5 * (sens[-1] + sens[-npoints]) * (specc[-1] -
19specc[-npoints]))
20lift <- (sens - specc)[-1]
21cutoff <- sall[lift == max(lift)][1]
22sensopt <- sens[-1][lift == max(lift)][1]
23specopt <- 1 - specc[-1][lift == max(lift)][1]
24list(area = area, cutoff = cutoff, sensopt = sensopt, specopt = specopt)
25}
26roc.analysis <- function (object, newdata = NULL, newplot = TRUE, ...)
27{
28if (is.null(newdata)) {
29sd <- object$fitted[object$y == 1]
30sdc <- object$fitted[object$y == 0]
31}
32else {
33sd <- predict(object, newdata, type = "response")[newdata$y ==
341]
35sdc <- predict(object, newdata, type = "response")[newdata$y ==
360]
37}
38roc.plot(sd, sdc, newplot, ...)
39}
40hosmerlem <- function (y, yhat, g = 10)
41{
42cutyhat <- cut(yhat, breaks = quantile(yhat, probs = seq(0,
431, 1/g)), include.lowest = T)
44obs <- xtabs(cbind(1 - y, y) ~ cutyhat)
45expect <- xtabs(cbind(1 - yhat, yhat) ~ cutyhat)
46chisq <- sum((obs - expect)^2/expect)
47P <- 1 - pchisq(chisq, g - 2)
48c("X^2" = chisq, Df = g - 2, "P(>Chi)" = P)
49}
50x <- as.data.frame(t(y))
51r <- brlr(x)
52summary(r)
53rc <- summary(r)$coeff
54hm <- hosmerlem(y[1,],r$fitted.values)
55hm
56bitmap(file="test0.png")
57ra <- roc.analysis(r)
58dev.off()
59te <- array(0,dim=c(2,99))
60for (i in 1:99) {
61threshold <- i / 100
62numcorr1 <- 0
63numfaul1 <- 0
64numcorr0 <- 0
65numfaul0 <- 0
66for (j in 1:length(r$fitted.values)) {
67if (y[1,j] > 0.99) {
68if (r$fitted.values[j] >= threshold) numcorr1 = numcorr1 + 1 else numfaul1 = numfaul1 + 1
69} else {
70if (r$fitted.values[j] < threshold) numcorr0 = numcorr0 + 1 else numfaul0 = numfaul0 + 1
71}
72}
73te[1,i] <- numfaul1 / (numfaul1 + numcorr1)
74te[2,i] <- numfaul0 / (numfaul0 + numcorr0)
75}
76bitmap(file="test1.png")
77op <- par(mfrow=c(2,2))
78plot((1:99)/100,te[1,],xlab="Threshold",ylab="Type I error", main="1 - Specificity")
79plot((1:99)/100,te[2,],xlab="Threshold",ylab="Type II error", main="1 - Sensitivity")
80plot(te[1,],te[2,],xlab="Type I error",ylab="Type II error", main="(1-Sens.) vs (1-Spec.)")
81plot((1:99)/100,te[1,]+te[2,],xlab="Threshold",ylab="Sum of Type I & II error", main="(1-Sens.) + (1-Spec.)")
82par(op)
83dev.off()
84load(file="createtable")
85a<-table.start()
86a<-table.row.start(a)
87a<-table.element(a,"Coefficients of Bias-Reduced Logistic Regression",5,TRUE)
88a<-table.row.end(a)
89a<-table.row.start(a)
90a<-table.element(a,"Variable",header=TRUE)
91a<-table.element(a,"Parameter",header=TRUE)
92a<-table.element(a,"S.E.",header=TRUE)
93a<-table.element(a,"t-stat",header=TRUE)
94a<-table.element(a,"2-sided p-value",header=TRUE)
95a<-table.row.end(a)
96for (i in 1:length(rc[,1])) {
97a<-table.row.start(a)
98a<-table.element(a,labels(rc)[[1]][i],header=TRUE)
99a<-table.element(a,rc[i,1])
100a<-table.element(a,rc[i,2])
101a<-table.element(a,rc[i,3])
102a<-table.element(a,2*(1-pt(abs(rc[i,3]),r$df.residual)))
103a<-table.row.end(a)
104}
105a<-table.end(a)
106table.save(a,file="mytable.tab")
107a<-table.start()
108a<-table.row.start(a)
109a<-table.element(a,"Summary of Bias-Reduced Logistic Regression",2,TRUE)
110a<-table.row.end(a)
111a<-table.row.start(a)
112a<-table.element(a,"Deviance",1,TRUE)
113a<-table.element(a,r$deviance)
114a<-table.row.end(a)
115a<-table.row.start(a)
116a<-table.element(a,"Penalized deviance",1,TRUE)
117a<-table.element(a,r$penalized.deviance)
118a<-table.row.end(a)
119a<-table.row.start(a)
120a<-table.element(a,"Residual Degrees of Freedom",1,TRUE)
121a<-table.element(a,r$df.residual)
122a<-table.row.end(a)
123a<-table.row.start(a)
124a<-table.element(a,"ROC Area",1,TRUE)
125a<-table.element(a,ra$area)
126a<-table.row.end(a)
127a<-table.row.start(a)
128a<-table.element(a,"Hosmer–Lemeshow test",2,TRUE)
129a<-table.row.end(a)
130a<-table.row.start(a)
131a<-table.element(a,"Chi-square",1,TRUE)
132a<-table.element(a,hm[1])
133a<-table.row.end(a)
134a<-table.row.start(a)
135a<-table.element(a,"Degrees of Freedom",1,TRUE)
136a<-table.element(a,hm[2])
137a<-table.row.end(a)
138a<-table.row.start(a)
139a<-table.element(a,"P(>Chi)",1,TRUE)
140a<-table.element(a,hm[3])
141a<-table.row.end(a)
142a<-table.end(a)
143table.save(a,file="mytable1.tab")
144a<-table.start()
145a<-table.row.start(a)
146a<-table.element(a,"Fit of Logistic Regression",4,TRUE)
147a<-table.row.end(a)
148a<-table.row.start(a)
149a<-table.element(a,"Index",1,TRUE)
150a<-table.element(a,"Actual",1,TRUE)
151a<-table.element(a,"Fitted",1,TRUE)
152a<-table.element(a,"Error",1,TRUE)
153a<-table.row.end(a)
154for (i in 1:length(r$fitted.values)) {
155a<-table.row.start(a)
156a<-table.element(a,i,1,TRUE)
157a<-table.element(a,y[1,i])
158a<-table.element(a,r$fitted.values[i])
159a<-table.element(a,y[1,i]-r$fitted.values[i])
160a<-table.row.end(a)
161}
162a<-table.end(a)
163table.save(a,file="mytable2.tab")
164a<-table.start()
165a<-table.row.start(a)
166a<-table.element(a,"Type I & II errors for various threshold values",3,TRUE)
167a<-table.row.end(a)
168a<-table.row.start(a)
169a<-table.element(a,"Threshold",1,TRUE)
170a<-table.element(a,"Type I",1,TRUE)
171a<-table.element(a,"Type II",1,TRUE)
172a<-table.row.end(a)
173for (i in 1:99) {
174a<-table.row.start(a)
175a<-table.element(a,i/100,1,TRUE)
176a<-table.element(a,te[1,i])
177a<-table.element(a,te[2,i])
178a<-table.row.end(a)
179}
180a<-table.end(a)
181table.save(a,file="mytable3.tab")
Last computationDelete history
Server DateModuleCommand
Sun, 18 May 2008 05:35:23 -0600Bias-Reduced Logistic RegressionPrint | Word | Excel | Blog this | Delete
Sun, 18 May 2008 05:35:23 -0600Start of session-

Please, send us your feedback!
Overall rating
What do you think about the response time?
Rate the facility with which you interact with our software.
Is the output presented in an understandable (clear) form?
How did you find this website/module?
Do you have any comments about our site?
Do you have any suggestions for our site?
Please enter the code that is displayed in this picture: captcha

To cite Wessa.net in publications use:
Wessa, P. (2008), Free Statistics Software, Office for Research Development and Education,
version 1.1.22-r6, URL http://www.wessa.net/

© Resa R&D, and the 'Office for Research, Development, and Education' - All rights reserved. Academic license for non-commercial use only.
This website is an intellectual and physical property of Resa R&D. This includes: html content, graphical illustrations (gif files), computer software, online or electronic documentation, associated media, and printed materials. The free use of the scientific content, services, and applications in this website is granted for non commercial use only. In any case, the source (url) should always be clearly displayed. Under no circumstances are you allowed to reproduce, copy or redistribute the design, layout, or any content of this website (for commercial use) including any materials contained herein without the express written permission of Resa R&D or the Office for Research, Development, and Education.

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, Resa R&D makes no warranties or representations as to the accuracy or completeness of such information (or software), and it assumes 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 Resa R&D 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.

Software Version : 1.1.22-r6
Algorithms & Software : Prof. dr. P. Wessa
Facilities : Resa R&D - Office for Research, Development, and Education
Server : www.wessa.net

Comments, Feedback & Errors | Privacy Policy | Statistics Resources | Wessa.net Home

 © Wessa.Net 2002-2008  
 
 

Home Page
Equation Plotter
Time Series Analysis (new)
Time Series Analysis (old)
Multiple Regression (new)
Multiple Regression (old)
Descriptive Statistics
Statistical Distributions
Hypothesis Testing

Academic citations
Computations Archive
Search Computations
FAQ
About Wessa.net
Powered by Linux

Server status page
History list
Edit R Code
Google
Web wessa.net