### Example 1
### At least three independent variables, including the intercept, must be present
head(SLM1, n=5)
y = SLM1[,1]
x = SLM1[,2:3]
cv_vif(x)
### Example 2
### Creating the design matrix
library(multiColl)
set.seed(2025)
obs = 100
cte = rep(1, obs)
x2 = rnorm(obs, 5, 0.01)
x3 = rnorm(obs, 5, 10)
x4 = x3 + rnorm(obs, 5, 1)
x5 = rnorm(obs, -1, 30)
x = cbind(cte, x2, x3, x4, x5)
cv_vif(x)
### Example 3
### Obtaining the design matrix after executing the command 'lm'
library(multiColl)
set.seed(2025)
obs = 100
cte = rep(1, obs)
x2 = rnorm(obs, 5, 0.01)
x3 = rnorm(obs, 5, 10)
x4 = x3 + rnorm(obs, 5, 1)
x5 = rnorm(obs, -1, 30)
u = rnorm(obs, 0, 2)
y = 5 + 4*x2 - 5*x3 + 2*x4 - x5 + u
reg = lm(y~x2+x3+x4+x5)
x = model.matrix(reg)
cv_vif(x) # identical to Example 2
### Example 3
### Computationally singular system
head(soil, n=5)
y = soil[,16]
x = soil[,-16]
cv_vif(x)
Run the code above in your browser using DataLab