-
Notifications
You must be signed in to change notification settings - Fork 48
/
Training-Example2.R
67 lines (34 loc) · 1.27 KB
/
Training-Example2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Data is from https://archive.ics.uci.edu/ml/datasets/Credit+Approval
creditAppData <- read.csv("https://bit.ly/2HRjkxj")
head(creditAppData)
summary(creditAppData)
attach(creditAppData)
m<-glm(Approved~Employed , family = binomial )
summary(m)
library(aod)
library(stats)
library(pROC)
# calculating the ODDs ratio
exp(cbind(OR = coef(m)))
m2<-glm(Approved~Employed+Debt , family = binomial )
summary(m2)
# OR per 10 unit increase
# m$coefficients gives me access to coefficient values
exp(m2$coefficients[3]*10)
creditAppData$prob.m2<-predict(m2, type=c("response") )
g <-roc(creditAppData$Approved ~ creditAppData$prob.m2)
print(g)
plot(g)
plot( 1-g$specificities, g$sensitivities, xlab = "1 - Specificity", ylab="Sensitivity", main="ROC Curve")
abline(a=0, b=1)
# Is there a correlation between Age, Income, Credit Score, and YearsEmployed and the credit approval status?
# Can this relationship be used to predict if a person is granted credit?
IncomeLog<-log(Income+0.001)
CreditScoreLog<-log(CreditScore+0.001)
YearsEmployed<-log(YearsEmployed+0.001)
m3<-glm(Approved~Age+IncomeLog+CreditScoreLog+YearsEmployed , family = binomial )
summary(m3)
# Global test
# install.package("aod")
library(aod)
wald.test(b=coef(m3), Sigma = vcov(m3), Terms = 2:5)