knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)
require(logbin, quietly = TRUE)

logbin

CRAN_Status_Badge

logbin provides methods for performing relative risk regression by fitting log-link GLMs and GAMs to binomial data. As well as providing a consistent interface to use the usual Fisher scoring algorithm (via glm or glm2) and an adaptive barrier approach (via constrOptim), it implements EM-type algorithms that have more stable convergence properties than other methods.

An example of periodic non-convergence using glm (run with trace = TRUE to see deviance at each iteration):

require(glm2, quietly = TRUE)
data(heart)

start.p <- sum(heart$Deaths) / sum(heart$Patients)
t.glm <- system.time(
  fit.glm <- logbin(cbind(Deaths, Patients-Deaths) ~ factor(AgeGroup) + factor(Severity) + 
                      factor(Delay) + factor(Region), data = heart,
                    start = c(log(start.p), -rep(1e-4, 8)), method = "glm", maxit = 10000)
)

The combinatorial EM method (Marschner and Gillett, 2012) provides stable convergence:

t.cem <- system.time(fit.cem <- update(fit.glm, method = "cem"))

...but it can take a while. Using an overparameterised EM approach removes the need to run $3^4 = 81$ separate EM algorithms:

t.em <- system.time(fit.em <- update(fit.glm, method = "em"))

...while generic EM acceleration algorithms (from the turboEM package) can speed this up further still:

t.cem.acc <- system.time(fit.cem.acc <- update(fit.cem, accelerate = "squarem"))
t.em.acc <- system.time(fit.em.acc <- update(fit.em, accelerate = "squarem"))

Comparison of results:

fit.list <- list(fit.glm, fit.cem, fit.em, fit.cem.acc, fit.em.acc)
time.list <- list(t.glm, t.cem, t.em, t.cem.acc, t.em.acc)
res <- data.frame(converged = sapply(fit.list, function(x) x$converged),
                  logLik = sapply(fit.list, logLik),
                  iterations = sapply(fit.list, function(x) x$iter[1]),
                  time = sapply(time.list, function(x) x[3]))
rownames(res) <- c("glm", "cem", "em", "cem.acc", "em.acc")
res

An adaptive barrier algorithm can also be applied using method = "ab", with user-specified options via control.method: see help(logbin) for more details.

Semi-parametric regression using B-splines (Donoghoe and Marschner, 2015) can be incorporated by using the logbin.smooth function. See example(logbin.smooth) for a simple example.

Installation

Get the released version from CRAN:

install.packages("logbin")

Or the development version from github:

# install.packages("devtools")
devtools::install_github("mdonoghoe/logbin")

References



mdonoghoe/logbin documentation built on Aug. 13, 2021, 7:30 p.m.