Logit回归(又称逻辑回归、罗杰斯蒂回归、Logistic回归)无疑是社会科学,尤其是社会学研究中使用最广的方法,没有之一。这也是因为社会科学中变量的类型所决定的。因变量的类型决定着回归模型的使用,对于社会科学中常用的类别变量对应的就是Logit回归。
Logit回归又不同于一般线性回归,一般线性回归的回归系数以及R方等较容易解释,但是Logit回归的数学原理中涉及到了对数转换等,所以解释起来与一般线性回归有着较多的不同之处。
下面给一个具体的例子,研究的是某一地区农户耕种土地占总可耕种土地的情况。
1.Logit和Probit的模型差别
Logit回归和Probit回归本质上都是对二分类变量进行转换,而且转换的关键都是针对事件发生的概率p。其中Logit模型是进行对数转换。
Probit模型顾名思义就是进行了Probit转换,Probit转换是得到一个关于p的单调函数,并且该函数和自变量呈线性关系。
2.二分类Logistic回归
sysuse 'auto.dta',clear
**一般Logistic回归
logit foreign mpg weight
**胜算比 (odds)获取的回归
logit foreign mpg weight,or
在计量经济学中,(多元)Logit模型是非常常用的建模离散选择的计量工具。Filip Matejka和 Alisdair McKay 2015年AER上的文章《Rational inattention to discrete choices: A new foundation for themultinomial logit model》通过不完全信息下「理性疏忽」的角度,提出了多元Logit 模型的一个新的基础。
在实证研究中,我们会遇到被解释变量为类别变量的情形。在部分情境下,被解释变量为非此即彼的二元选择变量 (如是否考取大学、是否结婚等),即我们熟知的0-1变量,此时应采用二元 Logit 模型进行估计;但在很多情形中,被解释变量涉及 3 种以上的类别变量。
**调用数据
use https://stats.idre.ucla.edu/stat/data/hsbdemo,clear
**logit回归
mlogit prog schtyp read write math science socst honors,or
** ses 变量前的i.标识表明该变量为类别变量,base选项帮助我们选定模型估计的基准组,此处我们将「学术课程项目」( ses=2 ) 作为基准组。
mlogit prog i.ses write, base(2)
**计算所有系数估计值对应的胜算比
mlogit, rrr
**预测概率值与概率值的图形显示
margins ses, atmeans predict(outcome(1))
marginsplot, name(general)
margins ses, atmeans predict(outcome(2))
marginsplot, name(academic)
margins ses, atmeans predict(outcome(3))
marginsplot, name(vocational)
graph combine general academic vocational, ycommon
下面讨论连续变量 write 在不同取值情况下对应的平均预测概率,平均预测概率为不同 ses 层级对应的预测概率的平均值。
margins, at(write = (30(10) 70)) predict(outcome(1)) vsquish
margins, at(write = (30(10) 70)) predict(outcome(2)) vsquish
margins, at(write = (30(10) 70)) predict(outcome(3)) vsquish
redict p1 p2 p3
sort write
twoway (line p1 write if ses ==1) (line p1 write if ses==2) (line p1 write if ses ==3),
legend(order(1 'ses = 1' 2 'ses = 2' 3 'ses = 3') ring(0) position(7) row(1)) title('general')
twoway (line p2 write if ses ==1) (line p2 write if ses==2) (line p2 write if ses ==3),
legend(order(1 'ses = 1' 2 'ses = 2' 3 'ses = 3') ring(0) position(7) row(1)) title('academic')
twoway (line p3 write if ses ==1) (line p3 write if ses==2) (line p3 write if ses ==3),
legend(order(1 'ses = 1' 2 'ses = 2' 3 'ses = 3') ring(0) position(7) row(1)) title('vocation')
webuse lbw,clear
** low为应变量,后边均为自变量,OR为各变量回归系数的对数值
logit low age lwt i.race smoke ptl ht ui,or
**使用Hl检验对回归模型进行检验
lfit, group(10) table
**展示回归后的分类结果,包括敏感度和特异度
lstat
**寻找最佳临界值
lsens
**使用ROC评估回归效果
lroc
webuse union
xtset idcode year
sum
**分析各因素对妇女是否选择参加工会的影响。因为被解释变union为二值选择变量,数据类型又是面板数据,我们考虑使用面板数据的离散选择模型。
**固定效应面板数据Logit回归
xtlogit union age grade i.not_smsa south##c.year,fe
**随机效应面板数据Logit回归
xtlogit union age grade i.not_smsa south##c.year,re
联系客服