我的模型是逻辑模型,log_expenditure和家庭人口是连续变量,m1_q23_edu和m1_q25_caste是不同的类别。
# Mainmodel
mainmodel<-glm(lpg~log_expenditure+householdpopulation+m1_q23_edu+m1_q25_caste,family = binomial,data2)
summary(mainmodel)
Call:
glm(formula = lpg ~ log_expenditure + householdpopulation + m1_q23_edu +
m1_q25_caste, family = binomial, data = data2)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.9347 -0.8271 -0.5380 0.9566 2.7058
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -8.38247 0.63816 -13.135 < 2e-16 ***
log_expenditure 0.90946 0.07639 11.906 < 2e-16 ***
householdpopulation -0.02287 0.01184 -1.931 0.0534 .
m1_q23_eduUp to 5th Standard 0.52114 0.12205 4.270 1.96e-05 ***
m1_q23_eduUp to 10th Standard 1.05750 0.13153 8.040 8.99e-16 ***
m1_q23_edu12th Standard or Diploma 1.36823 0.14507 9.432 < 2e-16 ***
m1_q23_eduGraduate and Above 1.57049 0.15742 9.976 < 2e-16 ***
m1_q25_casteScheduled Caste -1.51177 0.14253 -10.607 < 2e-16 ***
m1_q25_casteScheduled Tribe -1.91443 0.75983 -2.520 0.0117 *
m1_q25_casteOther Backward Class -0.57581 0.09844 -5.849 4.94e-09 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 3827.7 on 3022 degrees of freedom
Residual deviance: 3214.2 on 3013 degrees of freedom
AIC: 3234.2
Number of Fisher Scoring iterations: 5
# Draw the graph
mydata$prob<-exp(predict(mainmodel))/(1+exp(predict(mainmodel)))
ggplot(mydata, aes(x=log_expenditure, y=prob, col=m1_q25_caste))+
geom_line()