## Non-linear dependence: both estimators detect association.
set.seed(1)
n <- 200
x <- rnorm(n)
y <- x^2 + rnorm(n, sd = 0.2)
X <- cbind(x = x, y = y)
classical <- dcor(X)
robust <- robust_dcor(X)
round(c(
dcor = classical["x", "y"],
robust_dcor = robust["x", "y"]
), 3)
## One diagonal outlier can inflate classical dCor more than robust dCor.
set.seed(45)
x <- rnorm(20)
y <- rnorm(20)
x[1] <- 10
y[1] <- 10
X_out <- cbind(x = x, y = y)
classical <- dcor(X_out)
robust <- robust_dcor(X_out)
round(c(
dcor = classical["x", "y"],
robust_dcor = robust["x", "y"]
), 3)
print(classical)
print(robust)
summary(robust)
estimate(robust)
tidy(robust)
plot(robust)
## Several variables.
set.seed(7)
z <- rnorm(120)
X_multi <- cbind(
linear = z + rnorm(120, sd = 0.3),
nonlinear = z^2 + rnorm(120, sd = 0.3),
noise = rnorm(120),
outlier = rnorm(120)
)
X_multi[1, "outlier"] <- 12
X_multi[1, "noise"] <- 12
robust_multi <- robust_dcor(X_multi)
print(robust_multi)
summary(robust_multi)
plot(robust_multi)
Run the code above in your browser using DataLab