Coder Social home page Coder Social logo

stephenberg / bcd Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 2.86 MB

Block coordinate descent for group lasso

R 45.52% C++ 54.48%
multinomial-regression group-lasso logistic-regression coordinate-descent c-plus-plus r-package overlapping-groups sparse-group-lasso overlapping-group-lasso rcpp

bcd's Introduction

bcd

block coordinate descent for group lasso problems

Description

The bcd package uses block coordinate descent to fit common GLMs with a group lasso penalty. The model fitting implementation is in C++, and the package is used in R with wrapper functions from Rcpp. Run help("fit_bcd") in R for descriptions of the function arguments and for some examples of using the package.

Features:

  • tested against glmnet and grpreg
  • fits linear, logistic, multinomial, multiresponse Gaussian, and Poisson models
  • supports sparse and dense design matrices
  • supports multiple group penalization options:
    • sparse group lasso penalization
    • overlapping group lasso penalization
    • models with 1 or more than 1 unpenalized coefficient
    • models with 0 unpenalized coefficients, including models where the intercept is penalized or the model does not contain an intercept
  • varying weights for each sample

Installation

Install using devtools package:

devtools::install_github("stephenberg/bcd")

Example

Linear regression with simulated data

library(bcd)
data(exampleData)
fit_linear=fit_bcd(X=X,y=y_gaussian,family="gaussian",groups=grouping,penaltyFactor=penaltyFactor)

Example with overlapping groups

A more complicated logistic regression example with overlapping groups:

data(exampleData)
grouping=list(as.integer(1),2:10,11:30,11:50)
fit_overlap=fit_bcd(X=X,y=y_binary,family="logistic",groups=grouping,penaltyFactor=penaltyFactor)

Comparison to results from glmnet and grpreg

The tests/ folder of the repository contains a substantial collection of test functions for comparing bcd, glmnet, and grpreg under many settings. Below, we show the setting and output for two of the linear regression test examples.

The tests use the example data that comes with the package:

library(bcd)
library(glmnet)
library(grpreg)
data(exampleData)

Testing linear regression vs. grpreg, with 3 groups and an unpenalized intercept:

fitBCD=fit_bcd(X=X,y=y_gaussian,family="gaussian",groups=grouping,penaltyFactor=penaltyFactor)
fitGrpreg=grpreg(X=X[,-1],y=y_gaussian,family="gaussian",group=c(rep(1,9),rep(2,20),rep(3,20)),eps = 10^-16)
betaBCD=matrix(unlist(fitBCD$beta),ncol=length(fitBCD$beta))
max(abs(betaBCD-fitGrpreg$beta))

[1] 4.468648e-15

Testing linear regression vs. glmnet, with lasso (l1) penalty only

fitBCD=fit_bcd(X=X,y=y_gaussian,family="gaussian",groups=as.list(1:50),penaltyFactor=c(0,rep(1,49)),tol=10^-12)
fitGlmnet=glmnet(x=X[,-1],y=y_gaussian,family="gaussian",lambda=fitBCD$lambda*sqrt(n),thresh=10^-30)
betaBCD=matrix(unlist(fitBCD$beta),ncol=length(fitBCD$beta))
max(abs(betaBCD-coefficients(fitGlmnet)))

[1] 2.250804e-15

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.