I want to run a Wald test to evaluate the statistical significance of each coefficient in the model using the regTermTest
function of the survey
package (as described here).
The syntax of regTermTest
calls for the model
followed by the test.terms
, but if you list multiple test terms it seems to evaluate them all together rather than separately.
library(caret) # for the GermanCredit sample dataset
data(GermanCredit)
mod1 <- glm(Class ~ Age + as.factor(ForeignWorker) + Property.RealEstate + Housing.Own + CreditHistory.Critical, data = GermanCredit, family = binomial(link='logit'))
library(survey)
regTermTest(mod1, c("Age", "ForeignWorker", "Property.RealEstate", "Housing.Own", "CreditHistory.Critical"))
#
Of course, I could separate them out this way, but it's clunky and repetitive (i.e. the following code produces the desired result but is inefficient when dealing with lots of variables):
regTermTest(mod1, "Age")
regTermTest(mod1, "ForeignWorker")
regTermTest(mod1, "Property.RealEstate")
regTermTest(mod1, "Housing.Own")
regTermTest(mod1, "CreditHistory.Critical")
I've tried extracting the coefficient names into a vector and inserting it into a for
loop, but it didn't work (it combines all the terms into one evaluation rather than separately estimating their importance):
vars <- names(mod1$coefficients)
vars <- vars[-1]
for (i in 1:length(vars)) {
iv = vars[i]
rtest <- regTermTest(mod1, iv)
}
How can I efficiently code this?