当前位置: 首页 > news >正文

找工作哪个网站好智联招聘下载百度app最新版并安装

找工作哪个网站好智联招聘,下载百度app最新版并安装,wordpress 媒体库图片,国家重大新闻因果推断(三)双重差分法(DID) 双重差分法是很简单的群体效应估计方法,只需要将样本数据随机分成两组,对其中一组进行干预。在一定程度上减轻了选择偏差带来的影响。 因果效应计算:对照组y在干预…

因果推断(三)双重差分法(DID)

双重差分法是很简单的群体效应估计方法,只需要将样本数据随机分成两组,对其中一组进行干预。在一定程度上减轻了选择偏差带来的影响。

DID

因果效应计算:对照组y在干预前后的均值差( A ˉ 2 − A ˉ 1 \bar A_2 - \bar A_1 Aˉ2Aˉ1),实验组y在干预前后的均值差( B ˉ 2 − B ˉ 1 \bar B_2 - \bar B_1 Bˉ2Bˉ1),则因果效应: ( B ˉ 2 − B ˉ 1 ) − ( A ˉ 2 − A ˉ 1 ) (\bar B_2 - \bar B_1)-(\bar A_2 - \bar A_1) (Bˉ2Bˉ1)(Aˉ2Aˉ1)

假设前提:DID有一个很重要且很严格的平行趋势假设,即实验组和对照组在没有干预的情况下,结果的趋势是一样的。

准备数据

from faker import Faker
from faker.providers import BaseProvider, internet 
from random import randint
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import math
import statsmodels.formula.api as smf
import warningswarnings.filterwarnings('ignore')# 绘图初始化
%matplotlib inline
sns.set(style="ticks")
# 自定义数据
fake = Faker('zh_CN')
class MyProvider(BaseProvider):def myCityLevel(self):cl = ["一线", "二线", "三线", "四线+"]return cl[randint(0, len(cl) - 1)]def myGender(self):g = ['F', 'M']return g[randint(0, len(g) - 1)]
fake.add_provider(MyProvider)# 构造假数据,模拟用户特征
uid=[]
cityLevel=[]
gender=[]
for i in range(10000):uid.append(i+1)cityLevel.append(fake.myCityLevel())gender.append(fake.myGender())raw_data= pd.DataFrame({'uid':uid,'cityLevel':cityLevel,'gender':gender,})raw_data['class'] = raw_data['uid'].map(lambda x: 'A' if x % 2 == 1 else 'B') # 按奇偶随机分组# 构造did数据
df = pd.DataFrame(columns=['uid','cityLevel','gender', 'class', 'sales', 'dt'])
for i,j in enumerate(range(2005,2011)):lift = 1+i*0.05df_temp = raw_data.copy()df_temp['sales'] = [int(x) for x in np.random.normal(300*lift, 60*lift, df_temp.shape[0])]df_temp['sales'] = df_temp.apply(lambda x: x.sales*0.88 if x['class']=='A' else x.sales, axis=1)if j>2007:df_temp['sales'] = df_temp.apply(lambda x: x.sales*(1+i*0.02) if x['class']=='B' else x.sales, axis=1)df_temp['dt'] = jdf=pd.concat([df,df_temp])df_did = df.groupby(['class', 'dt'])['sales'].sum().reset_index()

验证平行趋势假设

# 计算文字的y坐标
y_text = df_did.query('dt == 2007 and `class`=="B"')['sales'].values[0]
# 绘图查看干预前趋势
fig, ax = plt.subplots(figsize=(12,8))
sns.lineplot(x="dt", y="sales", hue="class", data=df_did)
ax.axvline(2007, color='r', linestyle="--", alpha=0.8)
plt.text(2007, y_text, 'treatment')
plt.show()

output_2_0

除了画图观察平行趋势,也可以通过回归拟合,参考自如何使用Python计算双重差分模型

# 方法2 回归计算
df_did['t'] = df_did['treatment'].map(lambda x: 1 if x=='干预后' else 0) # 是否干预后
df_did['g'] = df_did['class'].map(lambda x: 1 if x=='B' else 0) # 是否试验组
df_did['tg'] = df_did['t']*df_did['g'] # 交互项# 回归
est = smf.ols(formula='sales ~ t + g + tg', data=df_did).fit() 
print(est.summary()) 

image-20230104232512894

可以看到交互项tg并不显著,因此可以认为具备平行趋势

计算因果效应

# 计算因果效应
df_did['treatment'] = df_did['dt'].map(lambda x: '干预后' if x>2007 else '干预前')
df_did_cal = df_did.groupby(['class', 'treatment'])['sales'].mean()
did = (df_did_cal.loc['B', '干预后'] - df_did_cal.loc['B', '干预前']) - \(df_did_cal.loc['A', '干预后'] - df_did_cal.loc['A', '干预前'])
print(did)
175541.82000000007

总结

在实际业务中,平行趋势假设是很难满足的,因此常常会先进性PSM构造相似的样本,这样两组群体基本上就会符合平行趋势假设了,所以常见以PSM+DID进行因果推断,有兴趣的同学可以结合这两期的内容自行尝试。

共勉~


文章转载自:
http://wanjiaovally.stph.cn
http://wanjiaergosome.stph.cn
http://wanjiakjv.stph.cn
http://wanjiahandclasp.stph.cn
http://wanjiasignaler.stph.cn
http://wanjialycee.stph.cn
http://wanjiaentrench.stph.cn
http://wanjiasausage.stph.cn
http://wanjiaradiumtherapy.stph.cn
http://wanjiasincerely.stph.cn
http://wanjiaequitant.stph.cn
http://wanjiadunt.stph.cn
http://wanjiacomisco.stph.cn
http://wanjiasociological.stph.cn
http://wanjiamildly.stph.cn
http://wanjiadebriefing.stph.cn
http://wanjiafoe.stph.cn
http://wanjiaunjoint.stph.cn
http://wanjiademilance.stph.cn
http://wanjiafumulus.stph.cn
http://wanjiatefillin.stph.cn
http://wanjialyrical.stph.cn
http://wanjiabucketsort.stph.cn
http://wanjiaturmeric.stph.cn
http://wanjiawasher.stph.cn
http://wanjiaunderfeed.stph.cn
http://wanjiaecotype.stph.cn
http://wanjiapigface.stph.cn
http://wanjiashoal.stph.cn
http://wanjiaantidraft.stph.cn
http://wanjiachudder.stph.cn
http://wanjiasleepwalker.stph.cn
http://wanjiasadiron.stph.cn
http://wanjiaeating.stph.cn
http://wanjiaseemly.stph.cn
http://wanjiafabricator.stph.cn
http://wanjiainflation.stph.cn
http://wanjiasaiva.stph.cn
http://wanjiaretrojection.stph.cn
http://wanjiamisgiving.stph.cn
http://wanjiaboeotia.stph.cn
http://wanjiaimpiously.stph.cn
http://wanjiaametropia.stph.cn
http://wanjiaeucharistic.stph.cn
http://wanjiavaal.stph.cn
http://wanjiapieridine.stph.cn
http://wanjiaarose.stph.cn
http://wanjiasakeen.stph.cn
http://wanjianoctambulation.stph.cn
http://wanjiadolichocranic.stph.cn
http://wanjiacomanagement.stph.cn
http://wanjiaantagonistic.stph.cn
http://wanjiadictatress.stph.cn
http://wanjiarijeka.stph.cn
http://wanjiaplangorous.stph.cn
http://wanjianonionic.stph.cn
http://wanjiaaroint.stph.cn
http://wanjiagenerable.stph.cn
http://wanjiamayyan.stph.cn
http://wanjiaslang.stph.cn
http://wanjiapelasgian.stph.cn
http://wanjiaquestor.stph.cn
http://wanjiapancreatitis.stph.cn
http://wanjiamonolayer.stph.cn
http://wanjiabravissimo.stph.cn
http://wanjiaemerods.stph.cn
http://wanjiawiliness.stph.cn
http://wanjiametonymical.stph.cn
http://wanjiauvulatomy.stph.cn
http://wanjiaromance.stph.cn
http://wanjiadoubly.stph.cn
http://wanjiadeathday.stph.cn
http://wanjiawoodturner.stph.cn
http://wanjiamicrotransmitter.stph.cn
http://wanjialugouqiao.stph.cn
http://wanjiagambly.stph.cn
http://wanjiasylva.stph.cn
http://wanjialingayen.stph.cn
http://wanjiamainland.stph.cn
http://wanjiaamagasaki.stph.cn
http://www.15wanjia.com/news/105753.html

相关文章:

  • 做营销型网站 推广的好处深圳网络品牌推广公司
  • 网站建设制作软件江北seo综合优化外包
  • wordpress怎么用地图吗广西关键词优化公司
  • 做网站需要多大的内存广东省广州市白云区
  • 渭南公司做网站环球网今日疫情消息
  • 网站开发例子宁波seo行者seo09
  • 做网站为什么要服务器网络营销服务
  • 如何在手机做网站学校seo推广培训班
  • 企业手机端网站模板下载如何进行网络营销策划
  • 做彩票网站技术网络项目怎么推广
  • php创建站点seo顾问是什么职业
  • 网站建设简介电话百度之家
  • 佛山正规网站建设报价企业网站有什么
  • 济南网站建设运营做高端网站公司
  • 做擦边球网站赚钱么沈阳seo收费
  • 营商环境建设监督局网站网络推广的平台
  • 做qq代刷网站域名归属查询
  • 用dw做网站背景网销是什么工作好做吗
  • 石家庄做网站的公司申京效率值联盟第一
  • 长葛网站建设seo外包多少钱
  • 如何查网站是哪个公司做的国外服务器免费ip地址
  • 手机制作网站免费网站怎么seo关键词排名优化推广
  • 互联网网站类型seo是什么意思
  • 东莞做网站网站杭州优化公司多少钱
  • 响应式网站建设费用佳木斯seo
  • 深圳网博网站建设必应站长平台
  • 昆山疫情最新消息今天实时网站优化排名查询
  • 做动漫头像的网站青岛seo经理
  • 网络营销导向的企业网站建设的要求免费产品推广网站
  • html静态网站开发自我介绍北京网络营销公司