In this recipe, we will generate random vectors according to a bivariate Gaussian distribution. We will contaminate it and see how both the standard and the robust methods work.
- First, we will generate bivariate Gaussian numbers and then estimate the correlation matrix. Since we don't have any outliers, both the robust and non-robust methods should be roughly similar:
library(MASS)library(robust)Sigma <- matrix(c(2,1,1,2),2,2)d <- mvrnorm(n = 1000, mu=c(5,5), Sigma)covClassic(d,cor = TRUE)
The following screenshot shows the correlation matrix estimated via classic methods
- The robust correlation matrix looks perfect as well. ...