R Language Generalized linear Model GLM () function
GLM (formula, family=family.generator, Data,control = List (...))
Formula data relationships, such as y~x1+x2+x3
Family: Each response distribution (exponential distribution family) allows various correlation functions to correlate the mean with the linear predictor.
Common family:
Binomal (link= ' logit ')--the response variable is subject to two distributions, and the connection function is logit, i.e. logistic regression
Binomal (link= ' probit ')--the response variable is subject to two distributions, and the connection function is Probit
Poisson (link= ' identity ')--response variable follows Poisson distribution, i.e. Poisson regression
Control: Controlling algorithm error and maximum number of iterations
Glm.control (epsilon = 1e-8, Maxit = +, trace = FALSE)
-----Maxit: Maximum number of iterations of the algorithm, changing the maximum number of iterations: Control=list (maxit=100)
From
Actual combat:
Source ("SETWD.R")
# #下面read. csv error, because the table header is garbled, delete the table header, redefine
data=read.csv ("Bankloan.csv") [2:701,]
# # View the first few lines tail is the last few lines of
Head (data)
colnames (data) <-c ("x1", "X2", "X3", "X4", "X5", "X6", "x7", "x8", "y")
tail ( Data)
#logistic回归模型
glm<-glm (y~x1+x2+x3+x4+x5+x6+x7+x8,family = binomial (link = "logit"), data = data)
GLM
Summary (GLM)
# # #逐步寻优法 forward forward selection method backward
logit.step<-step (glm,direction = C (" Both "))
Summary (logit.step)