Search code examples
rr-lavaan

Estimating the Variance Inflation Factors (VIF) of a SEM model (lavaan)


I am trying to find the Variance inflation factor (VIF) from a Structural Equation Model (SEM). My model is:

# load the data
library(readxl)
Log_And_SurveyResult <- read_excel("C:/Users/Aakash/Desktop/analysis/Today/Mot-Log.xlsx")

# load lavaan
library(lavaan)

#scale the variables
Log_And_SurveyResult$Time <-
scale(Log_And_SurveyResult$TotalActivity)

model <-
Ct =~ CT1 + CT2 + CT3
R =~ R1 + R2 + R3
B =~ B1 + B2 + B3
UserActivity =~ Time + TotalActivity

fit <- sem(model,data = Log_And_SurveyResult, std.lv = TRUE)
summary(fit, standardized=T)

Here is a sample of my data:

Time,TotalActivity,CT1,CT2,CT3,R1,R2,R3,B1,B2,B3
-0.4923798,-0.09991485,4,4,4,3,3,3,3,3,2
-1.0519708,-1.12771752,3,2,2,2,2,3,4,2,3
-0.5330384,-0.06320762,4,4,5,5,4,4,4,4,4
-1.0134522,-0.67805386,5,4,4,5,5,4,4,5,5
-1.1568273,-1.18277838,4,3,4,3,2,3,3,4,4
-0.8561675,-0.12744528,3,4,4,4,4,3,3,3,3

When I run vif(fit), I get error:

Error: $ operator not defined for this S4 class

I am following the examples from the: http://minato.sip21c.org/msb/man/VIF.html

Most of the example and tutorial on VIF has been generated by using a multiple regression model. But how can I get the VIF for my SEM model?


Solution

  • To estimate the VIF of a model produced with the sem() function of package lavaan you can create a binary dummy variable, regress it against the independent variables in his model, and then use vif() to estimate the Variance Inflation Factors. Example:

    ## Create random binary variable
    Log_And_SurveyResult$randomvar <- rbinom(nrow(Log_And_SurveyResult), 1, 0.5)
    
    ## Model and VIF
    Model <- lm(randomvar ~ CT1 + CT2 + CT3, data=Log_And_SurveyResult)
    vif(Model)