Python 95 区间的差分回归系数图
Python Difference-in-Difference Regression Coefficient plot with 95 interval
我想画一个95ci的差分系数图
这是我的数据框。
example:
x coef stderr ci_lower ci_upper
t-3 .0005219 .0004025 -.000759 .0018028
t-2 .0008449 .0004205 -.0004935 .0021833
t-1 0 0 0 0
t .0009092 .0003047 -.0000604 .0018789
t+1 .0010828 .0002889 .0001634 .0020023
t+2 .0013157 .0001613 .0008022 .0018291
t+3 .001452 .0001755 .0008933 .0020106
这是我使用的代码。但它没有用,而且信息量也不大
plt.errorbar(x=x, y=coef, yerr=ci_lower(?), color="black", capsize=3,
linestyle="None",
marker="s", markersize=7, mfc="black", mec="black")
有什么办法可以得到这样的回归系数图吗?
提前致谢
你应该提供数据和你喜欢的情节的例子。您的数据将是:
df = {'x': {0: 't-3', 1: 't-2', 2: 't-1', 3: 't', 4: 't+1', 5: 't+2', 6: 't+3'},
'coef': {0: 0.0005219,
1: 0.0008449,
2: 0.0,
3: 0.0009092,
4: 0.0010828,
5: 0.0013157,
6: 0.001452},
'stderr': {0: 0.0004025,
1: 0.0004205,
2: 0.0,
3: 0.0003047,
4: 0.0002889,
5: 0.0001613,
6: 0.0001755},
'ci_lower': {0: -0.000759,
1: -0.0004935,
2: 0.0,
3: -6.04e-05,
4: 0.0001634,
5: 0.0008022,
6: 0.0008933},
'ci_upper': {0: 0.0018028,
1: 0.0021833,
2: 0.0,
3: 0.0018789,
4: 0.0020023,
5: 0.0018291,
6: 0.0020106}}
df = pd.DataFrame(df)
我猜是这样的:
fig, ax = plt.subplots()
df.plot.scatter(x = "coef", y = "x",ax=ax)
for ix in df.index:
ax.plot(df[['ci_lower','ci_upper']].loc[ix].values, df.loc[ix,['x','x']].values,c="b")
我想画一个95ci的差分系数图
这是我的数据框。
example:
x coef stderr ci_lower ci_upper
t-3 .0005219 .0004025 -.000759 .0018028
t-2 .0008449 .0004205 -.0004935 .0021833
t-1 0 0 0 0
t .0009092 .0003047 -.0000604 .0018789
t+1 .0010828 .0002889 .0001634 .0020023
t+2 .0013157 .0001613 .0008022 .0018291
t+3 .001452 .0001755 .0008933 .0020106
这是我使用的代码。但它没有用,而且信息量也不大
plt.errorbar(x=x, y=coef, yerr=ci_lower(?), color="black", capsize=3,
linestyle="None",
marker="s", markersize=7, mfc="black", mec="black")
有什么办法可以得到这样的回归系数图吗?
提前致谢
你应该提供数据和你喜欢的情节的例子。您的数据将是:
df = {'x': {0: 't-3', 1: 't-2', 2: 't-1', 3: 't', 4: 't+1', 5: 't+2', 6: 't+3'},
'coef': {0: 0.0005219,
1: 0.0008449,
2: 0.0,
3: 0.0009092,
4: 0.0010828,
5: 0.0013157,
6: 0.001452},
'stderr': {0: 0.0004025,
1: 0.0004205,
2: 0.0,
3: 0.0003047,
4: 0.0002889,
5: 0.0001613,
6: 0.0001755},
'ci_lower': {0: -0.000759,
1: -0.0004935,
2: 0.0,
3: -6.04e-05,
4: 0.0001634,
5: 0.0008022,
6: 0.0008933},
'ci_upper': {0: 0.0018028,
1: 0.0021833,
2: 0.0,
3: 0.0018789,
4: 0.0020023,
5: 0.0018291,
6: 0.0020106}}
df = pd.DataFrame(df)
我猜是这样的:
fig, ax = plt.subplots()
df.plot.scatter(x = "coef", y = "x",ax=ax)
for ix in df.index:
ax.plot(df[['ci_lower','ci_upper']].loc[ix].values, df.loc[ix,['x','x']].values,c="b")