Thực hiện hồi quy logit cho biến Lợi nhuận bán hàng trên trung bình, biến V1 đã được biến đổi từ kqkd9 là biến nhị phân Các biến giải thích là - Giới tính (Giới tính của giám đốc) - Tài sản - Tổng số lao động - P: Là xác suất > trung bình
Phương trình Logit sẽ là: Log(P/1-P) = anpha + Beta1Giới tính + Beta2Tài sản + Beta3 * Tổng số lao động Giới tính ở đây là biến giả
tab1 <- data.frame(dn$macs,dn$gioitinh,dn$ts11,dn$tsld)
tb <- mean(dn$kqkd9)
v1 <- dn$kqkd9
v1 <- replace(v1, v1 < tb, 0)
v1 <- replace(v1, v1 > tb, 1)
v0 <- dn$macs
tab2 <- data.frame(v0,v1)
tab <- data.frame(tab1, tab2)
logit1=glm(v1~dn.gioitinh+dn.ts11+dn.tsld,family=binomial,data=tab)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
library(pscl)
## Loading required package: MASS
## Loading required package: lattice
## Classes and Methods for R developed in the
## Political Science Computational Laboratory
## Department of Political Science
## Stanford University
## Simon Jackman
## hurdle and zeroinfl functions by Achim Zeileis
summary(logit1)
##
## Call:
## glm(formula = v1 ~ dn.gioitinh + dn.ts11 + dn.tsld, family = binomial,
## data = tab)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -6.2581 -0.2433 -0.2230 -0.2103 2.8742
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -3.816e+00 2.115e-01 -18.042 <2e-16 ***
## dn.gioitinh -8.151e-02 1.321e-01 -0.617 0.537
## dn.ts11 -1.091e-06 1.196e-07 -9.122 <2e-16 ***
## dn.tsld 5.967e-02 2.436e-03 24.491 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 3711.2 on 6852 degrees of freedom
## Residual deviance: 2032.1 on 6849 degrees of freedom
## AIC: 2040.1
##
## Number of Fisher Scoring iterations: 8
exp(logit1$coefficients) # Tính các hệ số OR
## (Intercept) dn.gioitinh dn.ts11 dn.tsld
## 0.02200802 0.92172413 0.99999891 1.06148667
pR2(logit1)
## llh llhNull G2 McFadden r2ML
## -1016.0608529 -1855.5922045 1679.0627033 0.4524331 0.2173043
## r2CU
## 0.5196811
You can also embed plots, for example:
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.