The ‘fastglm’ package is a re-write of glm() using RcppEigen designed to be computationally efficient and algorithmically stable.

Installing the ‘fastglm’ package

Install the development version using the devtools package:

devtools::install_github("jaredhuling/fastglm")

or by cloning and building using R CMD INSTALL

Quick Usage Overview

Load the package:

A (not comprehensive) comparison with glm.fit() and speedglm.wfit():

## glm_vs_fastglm_qrcpiv     glm_vs_fastglm_qr glm_vs_fastglm_qrfpiv 
##          2.590289e-14          2.546921e-14          2.776945e-14 
##    glm_vs_fastglm_LLT   glm_vs_fastglm_LDLT 
##          1.140078e-13          1.094264e-13
## glm_vs_speedglm_eigen  glm_vs_speedglm_Chol    glm_vs_speedglm_qr 
##          1.359413e-12          1.359413e-12          1.191977e-12

Stability

The fastglm package does not compromise computational stability for speed. In fact, for many situations where glm() and even glm2() do not converge, fastglm() does converge.

As an example, consider the following data scenario, where the response distribution is (mildly) misspecified, but the link function is quite badly misspecified. In such scenarios, the standard IRLS algorithm tends to have convergence issues. The glm2() package was designed to handle such cases, however, it still can have convergence issues. The fastglm() package uses a similar step-halving technique as glm2(), but it starts at better initialized values and thus tends to have better convergence properties in practice.

##    user  system elapsed 
##   0.791   0.016   0.813
##    user  system elapsed 
##   2.905   0.110   3.033
system.time(gfit3 <- glm2::glm2(y~x, family = Gamma(link = "sqrt")) )
##    user  system elapsed 
##   2.266   0.082   2.361
system.time(gfit4 <- speedglm(y~x, family = Gamma(link = "sqrt")))
##    user  system elapsed 
##   1.866   0.052   1.928
## speedglm appears to diverge
system.time(gfit5 <- speedglm(y~x, family = Gamma(link = "sqrt"), maxit = 500))
##    user  system elapsed 
##  38.594   1.209  40.115
##     fastglm         glm        glm2    speedglm speedglm500 
##   -16030.81   -16704.05   -16046.66   -47722.66   -57785.72
##             (Intercept)          X1            X2         X3          X4
## fastglm        1.429256   0.1258736  5.321164e-03 -0.1293897   0.2389373
## glm            1.431168   0.1251936 -6.896739e-05 -0.1281857   0.2366473
## glm2           1.426864   0.1242616 -9.860241e-05 -0.1254873   0.2361301
## speedglm     -22.182477   3.1784570 -2.970111e+00 -4.9709797  14.0549438
## speedglm500  -27.891929 -13.9080256 -9.690833e+00  2.7279219 -11.1458325
## [1]  1 17
## [1]  0 25
## [1]  1 19
## [1]   0  25   0 500
##    user  system elapsed 
## 118.292   4.508 124.015
## [1] FALSE
## [1] 1000
## 'log Lik.' -16030.81 (df=102)
## 'log Lik.' -16333.99 (df=102)