x <- runif(n = 100, min = 100, max = 110)
y <- 0.2 + 1.2 * x + rnorm(100, 0, 1)
df <- data.frame(x, y)
Using I()
fit <- lm(y ~ x + I(x^2), data = df)
(vif <- check_collinearity(fit))
#> # Check for Multicollinearity
#>
#> High Correlation
#>
#> Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
#> x 6318.52 [4361.06, 9154.78] 79.49 1.58e-04 [0.00, 0.00]
#> I(x^2) 6318.52 [4361.06, 9154.78] 79.49 1.58e-04 [0.00, 0.00]
plot(vif)
#> Variable `Component` is not in your data frame :/
Using poly(..., raw = TRUE)
fit2 <- lm(y ~ poly(x, degree = 2, raw = TRUE), data = df)
(vif2 <- check_collinearity(fit2))
#> Not enough model terms in the conditional part of the model to check for
#> multicollinearity.
#> NULL
plot(vif2)
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Error in plot.window(...): need finite 'xlim' values
Using poly(...)
fit3 <- lm(y ~ poly(x, degree = 2), data = df)
(vif3 <- check_collinearity(fit3))
#> Not enough model terms in the conditional part of the model to check for
#> multicollinearity.
#> NULL
plot(vif3)
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in min(x): no non-missing arguments to max; returning -Inf
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Error in plot.window(...): need finite 'xlim' values
Using
I()
Using
poly(..., raw = TRUE)
Using
poly(...)
Created on 2024-06-12 with reprex v2.1.0