简体   繁体   中英

Can you make a Regression Discontinuity Plot using seaborn regplot?

Is there a way to include the variable d in the seaborn regplot so that the discontinuity at x=6 is shown? If not, are there alternatives to seaborn's regplot to create a classical regression discontinuity plot?

import seaborn as sns
import numpy as np

x = np.array([2,4,5.99,6,8,10,12])
d = (x>=6)*1
y = 2*x + 10*d

sns.regplot(x = x, y = y, ci = None )

Yes but you'd need to use lmplot , which annoyingly requires a dataframe input:

import seaborn as sns
import numpy as np
import pandas as pd

x = np.array([2, 4, 5.99, 6, 8, 10, 12])
d = x >= 6
y = 2 * x + 10 * d
df = pd.DataFrame({"x": x, "y": y, "d": d})

sns.lmplot(data=df, x="x", y="y", hue="d", ci=None)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM