【问题标题】:Python Difference-in-Difference Regression Coefficient plot with 95 interval具有 95 间隔的 Python 差异回归系数图
【发布时间】:2022-01-01 20:49:49
【问题描述】:

我想用 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")

有没有办法得到这样的回归系数图?

提前致谢

【问题讨论】:

    标签: python pandas matplotlib seaborn


    【解决方案1】:

    您应该提供数据以及您喜欢的绘图示例。您的数据将是:

    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")
    

    【讨论】:

    • 谢谢!并为我糟糕的回答感到抱歉。我稍后会修复它
    猜你喜欢
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    • 2021-07-03
    • 2016-06-29
    • 2020-06-28
    相关资源
    最近更新 更多