Code Monkey home page Code Monkey logo

sglfast's Introduction

R package sglfast

sglfast is a fork of R package SGL (Simon et. al. 2013), with individual group regularization parameters, and the iterative sparse-group lasso isgl, an algorithm to select the optimal regularization parameters of the sparse-group lasso.

Installation

The easiest way to install isgl in R is using devtools. If devtools is not installed, run

install.packages('devtools')

Then, install isgl

library(devtools)
install_github("jlaria/sglfast")
library(sglfast)

Usage

Example 1

library(sglfast)

# We create beta="the true coefficient vector" to be used in the simulations.
beta = 1:5

# We generate the model matrix X with iid columns and rows and the response y
X = matrix(rnorm(100*400), nrow = 100)
y = X[,1:5]%*%beta

# We chose the variance of the error such that SNR = 3
snr = 3
error = rnorm(100, mean = 0, sd=sqrt(var(y)/snr))
y = y+error

# Rows in the training sample
train.idx = sample(100, 50)

# Group indices for the SGL  
group_index = rep(1:40, each=10)

# Input data for the iterative 
data.train = list(x=X[train.idx,], y=y[train.idx])
data.validate = list(x=X[-train.idx,], y=y[-train.idx])

# We run the (unpooled) iterative SGL. For the 2-parameter version use isg_simple()
isgl.fit = isgl(data.train, data.validate, group_index, type = "linear")

# Best model returned by the iSGL algorithm
isgl.fit$beta
isgl.fit$intercept

Example 2

library(sglfast)

# We create beta="the true coefficient vector" to be used in the simulations.
beta = 1:5

# We generate the model matrix X with iid columns and rows and the response y
X = matrix(rnorm(100*400), nrow = 100)
y = X[,1:5]%*%beta

# We generate the response from a logit model

y = ((1+exp(-y))^-1 > 0.5) + 0


# Rows in the training sample
train.idx = sample(100, 50)

# Group indices for the SGL  
group_index = rep(1:40, each=10)

# Input data for the iterative 
data.train = list(x=X[train.idx,], y=y[train.idx])
data.validate = list(x=X[-train.idx,], y=y[-train.idx])

# We run the (unpooled) iterative SGL. For the 2-parameter version use isg_simple()
isgl.fit = isgl_simple(data.train, data.validate, group_index, type = "logit")

# Best model returned by the iSGL algorithm
isgl.fit$beta
isgl.fit$intercept

References

Simon, N., J. Friedman, T. Hastie, and R. Tibshirani (2013). A sparse-group lasso. Journal of Computational and Graphical Statistics 22 (2), 231โ€“245.

sglfast's People

Contributors

jlaria avatar

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.