GithubHelp home page GithubHelp logo

dirkschumacher / rcppglm Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 2.0 17 KB

GLM implementation in c++ with rcpp and armadillo

License: GNU Lesser General Public License v2.1

R 25.47% C++ 73.04% C 1.50%
generalized-linear-models armadillo-library r machine-learning-algorithms

rcppglm's Introduction

RcppGLM

Lifecycle: experimental

RcppGLM implements the GLM fitting algorithm in c++ using Armadillo. It follows the code from [1]. Requires c++11 at the moment.

It is work in progress and mainly for learning purposes.

There are some numerical problems depending on the input. But a lot of stuff seems to work already.

Supported families and link functions

  • Gaussian (gaussian_family) (log, identity, inverse (fails at the moment ¯\_(ツ)_/¯️))
  • Poisson (poisson_family) (log, sqrt, identity)
  • Binomial (binomial_family) (logit, probit)

Example

Logistic regression:

library(RcppGLM)
X <- model.matrix(I(mpg < 20) ~ -1 + hp + drat + cyl, data = mtcars)
y <- mtcars$mpg < 20
family <- binomial_family(link = "logit")
glm_fit(X, y, family)
#>             [,1]
#> [1,]  0.12609238
#> [2,] -4.00405338
#> [3,] -0.03569851

Same as the R implementation:

coef(glm.fit(X, y, family = stats::binomial(link = "logit")))
#>         hp       drat        cyl 
#>  0.1260924 -4.0040534 -0.0356985

Poisson regression:

X <- model.matrix(hp ~ -1 + drat + cyl, data = mtcars)
y <- mtcars$hp
family <- poisson_family(link = "log")
glm_fit(X, y, family)
#>           [,1]
#> [1,] 0.6425100
#> [2,] 0.4078514

Same as the R implementation:

coef(glm.fit(X, y, family = stats::poisson(link = "log")))
#>      drat       cyl 
#> 0.6425100 0.4078514

References

1: Arnold, T., Kane, M., & Lewis, B. W. (2019). A Computational Approach to Statistical Learning. CRC Press.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.