Generating random data for R, where default is 1 when the customer defaults the loan, the interest rate is having an effect on that but not the level of income (3 levels, 1=low revenues like me, 2=medium revenues, 3=high revenues):
df<-data.frame(
default=as.factor(c(rbinom(30,1,0.6),rbinom(30,1,0.4))),
interestrate=c(rnorm(30,2,5),rnorm(30,5,5)),
levelincome=as.factor(rbinom(60,3,0.5))
)
Building a glm of family "binomial"
model1<-glm(default~interestrate+levelincome,family="binomial",data=df)
summary(model1)
The summary command gives you p-values for each of the continuous variables and for the levels of the categorical variables. If you include more than one categorical variable, this may get hard to interpret and you will probably have to use pairwise comparisons with the function emmeans()
from the package of the same name in R.
> summary(model1)
Call:
glm(formula = default ~ interestrate + levelincome, family = "binomial",
data = df)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.9572 -0.9737 0.4031 0.9128 2.1725
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.84354 0.90072 2.047 0.04068 *
interestrate -0.19427 0.06354 -3.058 0.00223 **
levelincome1 -1.13407 0.92109 -1.231 0.21824
levelincome2 -0.80197 0.93582 -0.857 0.39146
levelincome3 -1.17280 1.20936 -0.970 0.33216
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 83.111 on 59 degrees of freedom
Residual deviance: 69.605 on 55 degrees of freedom
AIC: 79.605
Number of Fisher Scoring iterations: 3
Note that we indeed find an effect for the interest rate and none for the level of income, which does match the simulated data.