Display regression equation in seaborn regplot

PythonRegressionSeaborn

Python Problem Overview


Does anyone know how to display the regression equation in seaborn using sns.regplot or sns.jointplot? regplot doesn't seem to have any parameter that you can be pass to display regression diagnostics, and jointplot only displays the pearson R^2, and p-value. I'm looking for a way to see the slope coefficient, standard error, and intercept as well.

Thanks

Python Solutions


Solution 1 - Python

In 2015, the lead developer for seaborn replied to a feature request asking for access to the statistical values used to generate plots by saying, "It is not available, and it will not be made available."

So, unfortunately, this feature does not exist in seaborn, and seems unlikely to exist in the future.

Update: in March 2018, seaborn's lead developer reiterated his opposition to this feature. He seems... uninterested in further discussion.

Solution 2 - Python

A late and partial answer. I had the problem of just wanting to get the data of the regression line and I found this:

When you have this plot:

f = mp.figure()
ax = f.add_subplot(1,1,1)
p = sns.regplot(x=dat.x,y=ydat,data=dat,ax=ax)

Then p has a method get_lines() which gives back a list of line2D objects. And a line2D object has methods to get the desired data:

So to get the linear regression data in this example, you just need to do this:

p.get_lines()[0].get_xdata()
p.get_lines()[0].get_ydata()

Those calls return each a numpy array of the regression line data points which you can use freely.

Using p.get_children() you get a list of the individual elements of the plot.

The path information of the confidence interval plot can be found with:

p.get_children()[1].get_paths()

It's in the form of tuples of data points.

Generally a lot can be found by using the dir() command on any Python object, it just shows everything that's in there.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVikram JosyulaView Question on Stackoverflow
Solution 1 - PythonmillikanView Answer on Stackoverflow
Solution 2 - PythonKhrisView Answer on Stackoverflow