How to calculate VIF (variance inflation factor) with sdmTMB models #202
-
Question by email:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Although there's no built-in method currently, it's fairly simple to calculate yourself on the input data frame. From the Wikipedia entry:
Here's a little function to do that and an example: vif <- function(x) {
v <- vapply(seq_along(x), function(i) {
rsq <- summary(lm(x[[i]] ~ . , data = x[,-i, drop = FALSE]))$r.squared
1 / (1 - rsq)
}, FUN.VALUE = numeric(1L))
setNames(v, colnames(x))
}
# subset your data frame to include just the predictors in the model:
d <- mtcars[,c("mpg", "cyl", "disp", "drat")]
vif(d)
#> mpg cyl disp drat
#> 4.257023 6.388608 6.349561 2.147019 Created on 2023-04-25 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
Dear Sean,
Check for MulticollinearityLow Correlation
sDist2vill 1.03 [1.00, 1.76] 1.02 0.97 [0.57, 1.00] Regards, |
Beta Was this translation helpful? Give feedback.
Although there's no built-in method currently, it's fairly simple to calculate yourself on the input data frame.
From the Wikipedia entry:
Here's a little function to do that and an example: