knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

The mcvis package provides functions for detecting multi-collinearity (also known as collinearity) in linear regression. In simple terms, the mcvis method investigates variables with strong influences on collinearity in a graphical manner.

Basic usage

Suppose that we have a simple scenario that one predictor $X_1$ is almost linearly dependent on another two predictors $X_2$ and $X_3$, thus $X_1$ is strongly correlated with these two predictors. The dependence among these three variables is a sufficient cause for collinearity which can be shown through large variances of estimated model parameters in linear regression. We illustrate this with a simple example:

## Simulating some data
set.seed(1)
p = 6
n = 100

X = matrix(rnorm(n*p), ncol = p)
X[,1] = X[,2] + X[,3] + rnorm(n, 0, 0.01)

y = rnorm(n)
summary(lm(y ~ X))

The mcvis method highlights the major collinearity-causing variables on a bipartite graph. There are three major components of this graph: + the top row renders the "tau" statistics and by default, only one tau statistic is shown ($\tau_p$, where $p$ is the number of predictors). This tau statistic measures the extent of collinearity in the data and relates to the eigenvalues of the correlation matrix in $X$. + the bottom row renders all original predictors. + the two rows are linked through the MC-indices that we have developed, which are represented as lines of different shades and thickness. Darker lines implies larger values of the MC-index indicate what predictor contribute more to causing collinearity.

If you are interested in how the tau statistics and the resampling-based MC-index are calculated, our paper is published as Lin, C., Wang, K. Y. X., & Mueller, S. (2020). mcvis: A new framework for collinearity discovery, diagnostic and visualization. Journal of Computational and Graphical Statistics, https://doi.org/10.1080/10618600.2020.1779729

library(mcvis)
mcvis_result = mcvis(X = X)

mcvis_result

This matrix of MC-indices is the main numeric output of mcvis and our visualisation techniques are focused on visualising this matrix. Below is a bipartite graph visualising the last row of this matrix, which is the main visualisation plot of mcvis.

plot(mcvis_result)

We also provide a igraph version of the mcvis bipartite graph.

plot(mcvis_result, type = "igraph")

(Extension) why not just look at the correlation matrix?

In practice, high correlation between variables is not a necessary criterion for collinearity. In the mplot package (Tarr et. al. 2018), a simulated data was created with many of its columns being a linear combination of other columns plus noise. In this case, the cause of the collinearity is not clear from the correlation matrix.

The mcvis visualisation plot identified that the 8th variable (x8) is the main cause of collinearity of this data. Upon consultation with the data generation in this simulation, we see that x8 is a linear combination of all other predictor variables (plus noise).

library(mplot)
data("artificialeg")
X = artificialeg[,1:9]
round(cor(X), 2)

mcvis_result = mcvis(X)
mcvis_result
plot(mcvis_result)

Shiny implementation

We also offer a shiny app implementation of mcvis in our package. Suppose that we have a mcvis_result object stored in the memory of R. You can simply call the function shiny_mcvis to load up a Shiny app.

class(mcvis_result)
shiny_mcvis(mcvis_result)

Reference

Session Info

sessionInfo()


leaffur/mcvis documentation built on Aug. 28, 2023, 9:54 a.m.