ore.stepwise for highperformance stepwise regression
This guest post from Alexandre Ardelea describes the Oracle R Enterprise deployment in the Oracle microprocessor tools environment.
The deployment of ORE
within the Oracle microprocessor tools environment introduced a technology that
significantly expands our data analysis capabilities and opens the door to new
applications.
Oracle R Enterprise (ORE) has been recently deployed in the Oracle microprocessor tools environment, replacing a popular commercial tool as a production engine for data analysis. Fit/response models are important components of the simulation flows in the Oracle microprocessor tools environment; such models are used for a variety of purposes ranging from library generation to design yield prediction and optimization. Several tools were targeted for the migration to ORE; these tools are constructed around an iterative loop processing hundreds of data structures. At each iteration, a simulator engine generates data for multiple figures of metrics (targets), and a fit engine is called to construct response models for each target. The fit models are assembled into libraries for subsequent simulation within other flows or used on the fly.
A common characteristic of these
models is that they need to express strong nonlinear relations between the targets and large
sets of explanatory variables. Multiple interactions and many nonlinear
dependencies are considered as candidate effects for the model construction; they often result from an automatic generation procedure attempting
to cover a large variety of anticipated relations between the dependent and
independent variables. For example, for a case with O[10^2]
main explanatory variables, the total number of
candidate regressors, nregs_tot, could
quickly rise to O[10^310^4]. Linear regression models with such a high number of terms
are not only too expensive to use, as they have, potentially, a large
number of terms with negligible coefficients, but are also likely to lead to instability and
inaccuracy problems. For example,
overfitting is an important concern with
models expressing fluctuations in the data rather than capturing the trend.
Moreover, if strong quasilinear
interactions occur between large numbers of regressors,
the variance of the calculated (model) coefficients can be massively inflated.
In order to reduce the size of
the fit models while retaining significant dependencies, we use stepwise
regression. Stepwise regression is an iterative fitting method which
builds the model incrementally by adding and eliminating regressors (from a
specified candidate set) using a predefined selection mechanism/test of
statistical significance – the model converges when all regressors retained in
the model satisfy the significance test criteria. Commercial and open source
regression packages offer various flavors of stepwise regression which differ in
multiple ways through the choice of the selection mechanism (Ftest, Information Criteria:
AIC, BIC, etc), choice of the ‘direction’ (forward, backward, or both), flexibility for specifying the model
scope, the significance threshold(s), the handling of interaction terms, etc.
ORE has developed a proprietary indatabase algorithm for stepwise regression, ore.stepwise, which complements the functionality of R’s step and,
especially, offers a very significant performance improvement through faster, scalable algorithms and indatabase execution. The basic syntax is the following:
ore.stepwise(start_model, DB_data, model_scope, direction, add.p, drop.p)
ore.stepwise allows the user to
specify a model scope and stepwise direction, and uses the Ftest for regressor selection with the add.p and drop.p
significance levels for adding and removing regressors while the model is
iteratively constructed.
A typical usage for ore.stepwise
is illustrated below:
list_modnames < c("mdlA","mdlB",...) Effects_mdlA < ... Effects_mdlB < ... ...
for(modname in list_modnames){ Upper_model < as.formula(sprintf("%s ~ %s", modname,...) get(sprintf("Effects_%s", modname))) Lower_model < as.formula(sprintf("%s ~ 1", modname)) Scope_model < list(lower = Lower_model, upper = Upper_model) ... ...
assign(sprintf("%s_model", modname), ore.stepwise(Lower_model, data = dataDB, scope = Scope_model, direction="both", add.p=..., drop.p=...)) ... The indatabase ore frame dataDB contains observations for several target models mdlA,mdlB,..and a list with all target names (list_modnames) is assembled for iterative processing. For each target, a model scope is specified within lower and upper bounds. In the example above the lower bound is the intercept but the upper bound is customized so that each target model can be constructed from its own collection of regressors. The results shown in Figure1 illustrate the performance difference between ore.stepwise in using ORE and base R’s step function for both a bilinear and a fully quadratic model constructed from 34 independent variables and 10k data observations.
method 
R^2 
Number of Regressors 
mean(rel_error) 
Elapsed Time (seconds) 
step 
0.9658 
86 
3.52e02 
2110.0 
ore.stepwise 
0.9966 
124 
3.50e02 
32.1 
performance difference 



ore.stepwise is approx. 65X faster than step 
Quadratic
model
method 
R^2 
Number of Regressors 
mean(rel_error) 
Elapsed Time (seconds) 
step 
0.9962 
154 
1.05e02 
12600.0 
ore.stepwise 
0.9963 
210 
1.04e02 
69.5 
performance difference 



ore.stepwise is approx. 180X faster than step at similar R^2 relative 
Figure 1: Comparison of results for R’s step function and ORE’s ore.stepwise function for both bilinear and quadratic models
ore.stepwise is faster than R’s step by a factor of 66180X.
The larger the data set and the number
of regressors, we observed greater performance with ore.stepwise compared to
R’s step. The models produced by R’s step and ore.stepwise have a different number of regressors because both the selection mechanisms and interaction terms are handled differently. step favors the main terms – x1:x2 will be added only if x1 and x2 were previously added, and, reversibly, x1:x2 will be eliminated before x1 and x2 are eliminated, whereas ore.stepwise does not differentiate between main terms and interactions. With respect to collinearity, ore.stepwise detects strict linear dependencies and eliminates from start the regressors involved in multicollinear relations.
In summary, the ORE capabilities for stepwise regression far surpass similar functionality in tools we
considered as alternatives to ORE. The deployment of ORE within the Oracle microprocessor tools environment introduced a technology which significantly expands the data analysis capabilities through the R ecosystem combined with indatabase high performance algorithms and opens the door to new applications. This technology leverages the flexibility and extensibility of the R environment and allows massive and complex data analysis sustained by the scalability and performance of the Oracle database for Big Data.
Alexandre Ardelea is a principal hardware engineer at Oracle Corporation. Alex has a PhD and MS in Physics from
Ecole polytechnique fédérale de Lausanne and postdoctoral research in
nonlinear physics, CFD and parallel methods. Alex’s specialities
include response surface modeling, optimization strategies for
multiparametric/objective/constraint problems, statistical process
characterization, circuit analysis and RF algorithms.
_______________________________________________________________________________________________________________
Oracle R
Enterprise (ORE) implements a transparency layer on top of the R engine
that allows R computations specified in the R environment to be pushed for execution in Oracle Database. A mapping is established between a special R object called
an ore frame and a corresponding database table or view, allowing analytical functions such as ore.stepwise to be executed on these mapped objects in Oracle Database. The
overloaded functions in the ORE packages generate SQL statements in the
background, export the expensive computations to the database for
execution, and return results to the R environment. Here is a simple example using ore.stepwise with the longley data, which is shipped in the datasets package with R:
# load the Oracle R Enterprise library and connect to Oracle Database R> library(ORE) R> ore.connect(user = "rquser", host = "localhost", sid = "oracle", password = "rquser") R> # push the longley data to a database table: R> LONGLEY < ore.push(longley) R> class(LONGLEY) [1] "ore.frame" attr(,"package") [1] "OREbase" # Fit full model R> oreFit < ore.lm(Employed ~ ., data = LONGLEY) R> summary(oreFit) Call: ore.lm(formula = Employed ~ ., data = LONGLEY) Residuals: Min 1Q Median 3Q Max 0.41011 0.15980 0.02816 0.15681 0.45539 Coefficients: Estimate Std. Error t value Pr(>t
) (Intercept) 3.482e+03 8.904e+02 3.911 0.003560 ** GNP.deflator 1.506e02 8.492e02 0.177 0.863141 GNP 3.582e02 3.349e02 1.070 0.312681 Unemployed 2.020e02 4.884e03 4.136 0.002535 ** Armed.Forces 1.033e02 2.143e03 4.822 0.000944 *** Population 5.110e02 2.261e01 0.226 0.826212 Year 1.829e+00 4.555e01 4.016 0.003037 **  Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.3049 on 9 degrees of freedom Multiple Rsquared: 0.9955, Adjusted Rsquared: 0.9925 Fstatistic: 330.3 on 6 and 9 DF, pvalue: 4.984e10 # perform stepwise variable selection R> oreStep < ore.stepwise(Employed ~ .^2, data = LONGLEY, add.p = 0.1, drop.p = 0.1) # View a summary of ore.stepwise object R> summary(oreStep) Call: ore.stepwise(formula = Employed ~ .^2, data = LONGLEY, add.p = 0.1, drop.p = 0.1) Residuals: Min 1Q Median 3Q Max 18.42 22.08 24.08 29.40 33.19 Coefficients: Estimate Std. Error t value Pr(>t
) (Intercept) 3.539e01 8.455e03 41.852 < 2e16 *** Year 3.589e05 1.821e05 1.971 0.0675 . GNP.deflator:GNP 2.978e03 3.039e04 9.800 6.51e08 *** GNP.deflator:Unemployed 2.326e04 5.720e06 40.656 < 2e16 *** GNP.deflator:Population 2.303e05 2.293e06 10.044 4.72e08 *** GNP:Armed.Forces 6.875e06 8.415e07 8.170 6.64e07 *** GNP:Year 2.007e04 1.890e05 10.618 2.26e08 ***  Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.9829 on 15 degrees of freedom Multiple Rsquared: 0.9972, Adjusted Rsquared: 0.9961 Fstatistic: 3242 on 6 and 15 DF, pvalue: < 2.2e16
For more information on how Oracle R Enterprise leverages Oracle Database as computational engine, see the Oracle R Training Series. Oracle R Enterprise is a component in the Oracle Advanced Analytics Option of Oracle Database Enterprise Edition. We encourage you download Oracle software for evaluation from the
Oracle Technology Network. See these links for Rrelated software: Oracle R Distribution, Oracle R Enterprise, ROracle, Oracle R Connector for Hadoop. As always, we welcome comments and questions on the Oracle R Forum.
Rbloggers.com offers daily email updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...