rwrite.table

How can I make a table for vif output for multiple models?


I created 5 polr models and then using the Anova anf vif functions to my models.

Here is an example of my data set:

gender Work less happy lifestatisfied country Work much
2 0 7 8 GB 1
1 1 8 8 SE 0
1 0 7 9 DK 1
1 0 6 9 DE 1
1 NA 7 5 NO NA

continued:

health education income age marital status
3 3 Na 61 NA
4 2 2 30 NA
1 3 4 39 6
5 7 5 52 4
4 1 5 17 5

Here is an example of how I convert my output of vif into table:

vif.model1 = vif(model1)
vif.model1.tolerance = 1/vif.model1

vif.model2 = vif(model2)
vif.model2.tolerance = 1/vif.model2

vif.model3 = vif(model3)
vif.model3.tolerance = 1/vif.model3

vif.model4 = vif(model4)
vif.model4.tolerance = 1/vif.model4

vif.model5 = vif(model5)
vif.model5.tolerance = 1/vif.model5

write.table(vif.model1, "vif.m1.txt", sep = ";", dec = ",") 
write.table(vif.model2, "vif.m2.txt", sep = ";", dec = ",")
write.table(vif.model3, "vif.m3.txt", sep = ";", dec = ",")
write.table(vif.model4, "vif.m4.txt", sep = ";", dec = ",")
write.table(vif.model5, "vif.m5.txt", sep = ";", dec = ",")

When I then want to read them in excel I need to do it for all 5, five times.. is there a more easy way to load all the table into one table (with the variable names and model names appearing in the table .. it's not need to be excel. It is also fine if it's something similar to the method of regression output using stargazer.

I tried:

vif.table = table(vif.model1, vif.model2, row.names=TRUE, colnames=TRUE)

But this doesn't work.. the variable names are not included and the table it self just look wrong/weird/strange.


Solution

  • I figured out.. this post helped me: Anova table

    v1 <- data.frame(vif.model1)  
    v2 <- data.frame(vif.model2)  
    v3 <- data.frame(vif.model3)  
    v4 <- data.frame(vif.model4)  
    v5 <- data.frame(vif.model5)  
    
    v.tabel = data.frame(cbind(v1,v2,v3,v4,v5)) 
    
    write.table(v.table, "vtabel.txt", sep = ";", dec = ",") # i want to have decimals with comma instead of dot, that's why dec =","
    

    and then I just open excel and click on Data -> From Text/CSV and then load my data. It is actually not needed to create tolerance since it easliy can be calculated in excel but I just did it.