
---
title: Sparse regression with paired covariates
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{vignette}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  chunk_output_type: console
---

```{r,include=FALSE}
knitr::opts_chunk$set(echo=TRUE,eval=FALSE)
```

The R package `palasso` implements the paired lasso.

## Installation

Installing the current release from [CRAN](https://CRAN.R-project.org/package=palasso):

```{r,eval=FALSE}
install.packages("palasso")
```

Installing the latest development version from [GitHub](https://github.com/rauschenberger/palasso):

```{r,eval=FALSE}
#install.packages("devtools")
library(devtools)
install_github("rauschenberger/palasso")
```

## Initialisation

We use [glmnet](https://CRAN.R-project.org/package=glmnet) for the *standard lasso*, and [palasso](https://CRAN.R-project.org/package=palasso) for the *paired lasso*.

Loading and attaching the packages:

```{r, message=FALSE}
library(glmnet)
library(palasso)
```

Attaching some data to reproduce the examples:

```{r, eval=FALSE}
attach(toydata)
```

```{r, echo=FALSE}
names <- names(toydata)
for(i in 1:length(names)){
    assign(names[i],toydata[[i]])
}
rm(names)
```

Data are available for $n=30$ samples and $p=50$ covariate pairs. The object `y` contains the response (numeric vector of length $n$). The object `X` contains the covariates (list of two numeric matrices, both with $n$ rows and $p$ columns).

## Standard lasso

The standard lasso is a good choice for exploiting either the first or the second covariate group:

```{r}
object <- glmnet(y=y,x=X[[1]])
object <- glmnet(y=y,x=X[[2]])
```

## Paired lasso

But the paired lasso might be a better choice for exploiting both covariates groups at once:

```{r}
object <- palasso(y=y,X=X)
```

In contrast to the standard lasso, the paired lasso accounts for the structure between the covariate groups.

Given a limited number of non-zero coefficients, we expect the paired lasso to outperform the standard lasso: 

```{r,results='hide'}
object <- palasso(y=y,X=X,max=10)
```

## Methods

Standard methods are available for the paired lasso:

```{r,results='hide'}
weights(object)
```

```{r,results='hide'}
fitted(object)
```

```{r,results='hide'}
residuals(object)
```

```{r,results='hide'}
predict(object,newdata=X)
```

## Reference

Armin Rauschenberger
[![AR](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0001-6498-4801),
Iuliana Ciocănea-Teodorescu
[![ICT](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0003-2489-9025),
Marianne A. Jonker
[![MAJ](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0003-0134-8482),
Renée X. Menezes
[![RXM](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0002-1378-2721),
and Mark A. van de Wiel
[![MvdW](https://info.orcid.org/wp-content/uploads/2019/11/orcid_16x16.png)](https://orcid.org/0000-0003-4780-8472)
(2020).
"Sparse classification with paired covariates".
*Advances in Data Analysis and Classification* 14:571-588.
[doi: 10.1007/s11634-019-00375-6](https://doi.org/10.1007/s11634-019-00375-6)
