By: Chitta Ranjan, Ph.D., Director of Science, ProcessMiner, Inc.

In this post, we will learn about using a nonlinear correlation estimation function in R. We will also look at a few examples.


Correlation estimations are commonly used in various data mining applications. In my experience, nonlinear correlations are quite common in various processes. Due to this, nonlinear models, such as SVM, are employed for regression, classification, etc. However, there are not many approaches to estimate nonlinear correlations between two variables.

Typically linear correlations are estimated. However, the data may have a nonlinear correlation but little to no linear correlation. In such cases, nonlinearly correlated variables are sometimes overlooked during data exploration or variable selection in high-dimensional data.

We have developed a new nonlinear correlation estimator, nlcor. This estimator comes useful in data exploration and also variable selection for nonlinear predictive models, such as SVM.

Installing nlcor

To install nlcor in R, follow these steps:

  1. Install the devtools package. You can do this from CRAN. You can do it directly in R console by typing,

2. Load the devtools package.

3. Install nlcor from its GitHub repository by typing this in R console.

Nonlinear Correlation Estimator: nlcor

In this package, we provide an implementation of a nonlinear correlation estimation method using an adaptive local linear correlation computation in nlcor. The function nlcor returns the nonlinear correlation estimate, the corresponding adjusted p-value, and an optional plot visualizing the nonlinear relationships.

The correlation estimate will be between 0 and 1. The higher the value the more is the nonlinear correlation. Unlike linear correlations, a negative value is not valid here. Due to multiple local correlation computations, the net p-value of the correlation estimate is adjusted (to avoid false positives). The plot visualizes the local linear correlations.

In the following, we will show its usage with a few examples. In the given examples, the linear correlations between x and y is small, however, there is a visible nonlinear correlation between them. This package contains the data for these examples and can be used for testing the package.

nlcor package has few sample x and y vectors that are demonstrated in the following examples.

First, we will load the package.

Example 1. A data with cyclic nonlinear correlation.

The linear correlation of the data is,

As expected, the correlation is close to zero. We estimate the nonlinear
correlation using nlcor.

The plot shows the piecewise linear correlations present in the data.

Example 2. A data with non-uniform piecewise linear correlations.

The linear correlation of the data is,

The linear correlation is quite high in this data. However, there is
significant and higher nonlinear correlation present in the data. This
data emulates the scenario where the correlation changes its direction
after a point. Sometimes that change point is in the middle causing the
linear correlation to be close to zero. 
Here we show an example when the
change point is off center to show that the implementation works in
non-uniform cases.

We estimate the nonlinear correlation using nlcor.

It is visible from the plot that nlcor could estimate the piecewise correlations in a non-uniform scenario. Also, the nonlinear correlation comes out to be higher than the linear correlation.

Example 3. A data with higher and multiple frequency variations.

The linear correlation of the data is,

The linear correlation is expectedly small, albeit not close to zero due
to some linearity.

Here we show we can refine the granularity of the correlation

Under default settings, the output of nlcor will be,

As can be seen in the figure, nlcor overlooked some of the local relationships. We can refine the correlation estimation by changing the refine parameter. The default value of refine is set as 0.5. It can be set as any value between 0 and 1. A higher value enforces higher refinement.

However, higher refinement adversely affects the p-value. Meaning, the resultant correlation estimate may be statistically insignificant (similar to overfitting). Therefore, it is recommended to avoid over refinement.

For this data, we rerun the correlation estimation with refine = 0.9.

As can be seen in the figure,¬†nlcor¬†could identify the granular piecewise correlations. In this data, the p-value still remains extremely small‚ÄĒthe correlation is¬†statistically significant.


This package provides an implementation of an efficient heuristic to compute the nonlinear correlations between numeric vectors. The heuristic works by adaptively identifying multiple local regions of linear correlations to estimate the overall nonlinear correlation. Its usages are demonstrated here with few examples.


Posted by

ProcessMiner Team
May 20, 2020