l0ara
=====

[![](http://www.r-pkg.org/badges/version/l0ara)](https://cran.r-project.org/package=l0ara)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/l0ara)](https://cran.r-project.org/package=l0ara)

### Overview

`l0ara` fits sparse generalized linear models using an adaptive ridge
approximation to an L0 penalty. 

### Installation

Install the package from `CRAN` with:

```r
install.packages("l0ara")
```

### Basic usage

Fit a sparse Gaussian model:

```r
library(l0ara)

n <- 100
p <- 40
x <- matrix(rnorm(n * p), n, p)
beta <- c(1, 0, 2, 3, rep(0, p - 4))
y <- x %*% beta + rnorm(n)

fit <- l0ara(x, y, family = "gaussian", lam = log(n))
print(fit)
coef(fit)
```

Select the penalty by cross-validation:

```r
lam <- c(0.1, 0.3, 0.5)
cv_fit <- cv.l0ara(x, y, family = "gaussian", lam = lam, measure = "mse")

print(cv_fit)
coef(cv_fit)
plot(cv_fit)
```
