Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when plotting check_collinearity() with polynomial terms #346

Open
jmgirard opened this issue Jun 12, 2024 · 0 comments
Open

Error when plotting check_collinearity() with polynomial terms #346

jmgirard opened this issue Jun 12, 2024 · 0 comments

Comments

@jmgirard
Copy link

library(easystats)
#> # Attaching packages: easystats 0.7.2 (red = needs update)
#> ✔ bayestestR  0.13.2   ✔ correlation 0.8.4 
#> ✔ datawizard  0.11.0   ✔ effectsize  0.8.8 
#> ✖ insight     0.20.0   ✖ modelbased  0.8.7 
#> ✔ performance 0.12.0   ✔ parameters  0.21.7
#> ✔ report      0.5.8    ✔ see         0.8.4 
#> 
#> Restart the R-Session and update packages with `easystats::easystats_update()`.
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

Created on 2024-06-12 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant