Usage of the oem Package

Jared Huling


1 Introduction

oem is a package for the estimation of various penalized regression models using the oem algorithm of (Xiong et al. 2016). The focus of oem is to provide high performance computation for big tall data. Many applications not only have a large number of variables, but a vast number of observations; oem is designed to perform well in these settings.

2 Installation

The simplest way to install oem is via the CRAN repositories as the following:

To install the development version, first install the devtools package

install.packages("devtools", repos = "")

and then installl oem via the install_github function


3 Quick Start

First load oem


Simulate data

nobs  <- 1e4
nvars <- 100
x <- matrix(rnorm(nobs * nvars), ncol = nvars)
y <- drop(x %*% c(0.5, 0.5, -0.5, -0.5, 1, rep(0, nvars - 5))) + rnorm(nobs, sd = 4)

Fit a penalized regression model using the oem function

fit1 <- oem(x = x, y = y, penalty = "lasso")

Plot the solution path


4 Key Features

4.1 Available functions

Function Name Functionality
oem() Main fitting function
oem.xtx() Fitting function for precomputed \(X'X,X'y\)
big.oem() Fitting function for big.matrix() objects
summary.oemfit() Summary for oem objects
predict.oemfit() Prediction for oem objects
plot.oemfit() Plotting for oem objects
logLik.oemfit() log Likelihood for oem objects
cv.oem() Cross-validation function
xval.oem() Fast cross-validation for linear models Summary for cv.oem objects Prediction for cv.oem objects Plotting for cv.oem objects log Likelihood for cv.oem objects

4.2 Available Penalties

Penalty Option Name Penalty Form
Lasso lasso \(\lambda \sum_{j = 1}^pd_j|\beta_j|\)
Elastic Net \(\lambda \sum_{j = 1}^p\alpha d_j|\beta_j| + \frac{1}{2}(1 - \alpha)\lambda \sum_{j = 1}^pd_j\beta_j^2\)
MCP mcp \(\lambda \sum_{j = 1}^pd_j \int_0^{\beta_j}(1 - x/(\gamma\lambda d_j))_+\mathrm{d}x\)
SCAD scad \(\sum_{j = 1}^p p^{SCAD}_{\lambda d_j,\gamma}(\beta_j)\)
Group Lasso grp.lasso \(\lambda \sum_{k = 1}^Gd_k\sqrt{\sum_{j \in g_k}\beta_j^2}\)
Group MCP grp.mcp \(\lambda \sum_{k = 1}^Gp^{MCP}_{\lambda d_k,\gamma}(||\boldsymbol\beta_{g_k}||_2)\)
Group SCAD grp.scad \(\lambda \sum_{k = 1}^Gp^{SCAD}_{\lambda d_k,\gamma}(||\boldsymbol\beta_{g_k}||_2)\)
Sparse Group Lasso sparse.grp.lasso \(\lambda \alpha\sum_{j = 1}^pd_j|\beta_j| + \lambda (1-\alpha)\sum_{k = 1}^Gd_k\sqrt{\sum_{j \in g_k}\beta_j^2}\)

where \(||\boldsymbol\beta_{g_k}||_2 = \sqrt{\sum_{j \in g_k}\beta_j^2}\), \[ p_{\lambda, \gamma}^{SCAD}(\beta) = \left\{ \begin{array}{ll} \lambda|\beta| & |\beta| \leq \lambda ; \\ -\frac{|\beta|^2 - 2\gamma\lambda|\beta| + \lambda^2}{2(\gamma - 1)} & \lambda < |\beta| \leq \gamma\lambda ; \\ \frac{(\gamma + 1)\lambda^2}{2} & |\beta| > \gamma\lambda, \\ \end{array} \right. \]


\[ p_{\lambda, \gamma}^{MCP}(\beta) = \lambda \int_0^{\beta}(1 - x/(\gamma\lambda ))_+\mathrm{d}x = \\ \left\{ \begin{array}{ll} -\lambda (|\beta| - \frac{\beta^2} {2 \lambda\gamma}) & |\beta| \leq \gamma\lambda ; \\ \frac{ \lambda^2\gamma}{2} & |\beta| > \gamma\lambda. \\ \end{array} \right. \]

Any penalty with .net at the end of its name has a ridge term of \(\frac{1}{2}(1 - \alpha)\lambda \sum_{j = 1}^pd_j\beta_j^2\) added to it and the original penalty multiplied by \(\alpha\). For example, is the penalty

\[\lambda \sum_{k = 1}^G\alpha p^{MCP}_{\lambda d_k,\gamma}(||\boldsymbol\beta_{g_k}||_2) + \frac{1}{2}(1 - \alpha)\lambda \sum_{j = 1}^pd_j\beta_j^2. \]

4.3 Available Model Families

The following models are available currently.

Model Option Name Loss Form
Linear Regression gaussian \(\frac{1}{2n}\sum_{i=1}^n(y_i - x_i^T\beta) ^ 2\)
Logistic Regression binomial \(-\frac{1}{n}\sum_{i=1}^n\left[y_i x_i^T\beta - \log (1 + \exp\{ x_i^T\beta \} ) \right]\)

There are plans to include support for multiple responses, binomial models (not just logistic regression), Cox’s proportional hazards model, and more if requested.

5 Fitting multiple penalties at once

The oem algorithm is well-suited to quickly estimate a solution path for multiple penalties simultaneously if the number of variables is not too large. The oem algorithm is only efficient for multiple penalties for linear models.

For the group lasso penalty, the groups argument must be used. groups should be a vector which indicates the group number for each variable.

fit2 <- oem(x = x, y = y, penalty = c("lasso", "mcp", "grp.lasso", "grp.mcp"),
            groups = rep(1:20, each = 5))

Plot the solution paths for all models

layout(matrix(1:4, ncol = 2))
plot(fit2, which.model = 1, xvar = "lambda")
plot(fit2, which.model = 2, xvar = "lambda")
plot(fit2, which.model = 3, xvar = "lambda")
plot(fit2, which.model = "grp.mcp", xvar = "lambda")

5.1 Timing Comparison

The following is a demonstration of oem’s efficiency for computing solutions for tuning parameter paths for multiple penalties at once.

6 Cross Validation

Here we use the nfolds argument to specify the number of folds for \(k\)-fold cross validation

system.time(cvfit1 <- cv.oem(x = x, y = y, 
                             penalty = c("lasso", "mcp", 
                                         "grp.lasso", "grp.mcp"), 
                             gamma = 2,
                             groups = rep(1:20, each = 5), 
                             nfolds = 10))
##    user  system elapsed 
##    1.48    0.06    1.58

Plot the cross validation mean squared error results for each model

layout(matrix(1:4, ncol = 2))
plot(cvfit1, which.model = 1)
plot(cvfit1, which.model = 2)
plot(cvfit1, which.model = 3)
plot(cvfit1, which.model = 4)

6.1 Extremely Fast Cross Validation for Linear Models

The function xval.oem offers accelerated cross validation for penalized linear models. In many cases is is orders of magnitude faster than cv.oem. It is only recommended for scenarios where the number of observations is larger than the number of variables. In addition to the computational gains in single-core usage, it also benefits from parallelizaton using OpenMP (instead of using foreach, as used by cv.oem). For large enough problems, it has on a similar order of computation time as just fitting one OEM model.

##    user  system elapsed 
##    5.33    0.60    5.99
##    user  system elapsed 
##    0.87    0.01    0.89
##    user  system elapsed 
##    1.15    0.03    0.75
##    user  system elapsed 
##    0.17    0.02    0.18

6.2 Evaluation Metrics

A variety of evaluation metrics can be used for cross validation. The available metrics can be found in the table below

Model Metric type.measure=
Linear Regression Mean squared error mse or deviance
Mean absolute error mae
——————— ———————————- ————————
Logistic Regression Deviance deviance
Area under the ROC curve auc
Misclassification Rate class
Mean squared error of fitted mean mse
Mean absolute error of fitted mean mae

Consider a binary outcome setting with logistic regression.

6.2.1 Misclassification Rate

In this case, misclassification rate is not the best indicator of performance. The classes here are imbalanced:

## [1] 0.068

6.2.2 Area Under the ROC Curve

Area under the ROC curve is an alternative classification metric to misclassification rate. It is available by setting type.measure = "auc".

7 Methods for Very Large Scale Problems

7.1 OEM with Precomputed \(X^TX\), \(X^TY\) for Linear Models

With a very large dataset and computing cluster, the total size of a dataset may be very large, but if the number of variables is only moderately large (on the order of a few thousands) \(X^TX\) and \(X^TY\) may not be large and may already be available from other computations or can be computed trivially in parallel. The function oem.xtx computes penalized linear regression models using the OEM algorithm only using \(X^TX\) and \(X^TY\). Standardization can be achieved by providing a vector of scaling factors (usually the standard deviations of the columns of x). The function is used like the following:

##    user  system elapsed 
##    0.17    0.00    0.17
##    user  system elapsed 
##       0       0       0
## [1] 1.931788e-14
## [1] 1.953993e-14

7.2 Out-of-memory Computation

The OEM package also provides functionality for on-disk computation with the big.oem function, allowing for fitting penalized regression models on datasets too large to fit in memory. The big.oem function uses the tools provided by the bigmemory package, so a big.matrix object must be used for the design matrix.

## [1] 1.534783e-05

8 Other Features

8.1 Parallelization via OpenMP

Computational time can be reduced a little via OpenMP parallelization of the key computational steps of the OEM algorithm. Simply use the ncores argument to access parallelization. There is no need for the foreach package.

##    user  system elapsed 
##    3.18    0.04    3.24
##    user  system elapsed 
##    3.99    0.08    2.28

8.2 Penalty Adjustment

If some variables should not be penalized, this can be specified through the use of the penalty.factor argument for all penalties other than the group lasso. For the group lasso, the group-specific weights can be modified by the group.weights argument. penalty.factor should be a vector of length equal to the number of columns in x. Each element in penalty.factor will be multiplied to the applied tuning parameter for each corresponding variable. For example, for a problem with 5 variables (ncol(x) = 5), setting penalty.factor = c(1, 1, 1, 0, 0) will effectively only allow penalization for the first three variables. The group.weights argument should be a vector with length equal to the number of groups. Similarly to penalty.factor, these weights will be multiplied to the penalty applied to each group. penalty.factor and group.weights can also be used to fit the adaptive lasso and adaptive group lasso, respectively.

The following example shows how to fit an adaptive lasso using oem

9 More Information

For further information about oem, please visit:


Xiong, Shifeng, Bin Dai, Jared Huling, and Peter Z.G. Qian. 2016. “Orthogonalizing EM: A Design-Based Least Squares Algorithm.” Technometrics, in Press.