Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display regression equation in seaborn regplot [duplicate]

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

like image 588
Vikram Josyula Avatar asked Nov 03 '15 03:11

Vikram Josyula


People also ask

What is the use of Seaborn Regplot () method?

regplot() : This method is used to plot data and a linear regression model fit. There are a number of mutually exclusive options for estimating the regression model.

How do you plot a regression line in Seaborn?

Regression plots in seaborn can be easily implemented with the help of the lmplot() function. lmplot() can be understood as a function that basically creates a linear model plot. lmplot() makes a very simple linear regression plot.It creates a scatter plot with a linear fit on top of it.

What is the difference between Lmplot and Regplot?

While regplot() always shows a single relationship, lmplot() combines regplot() with FacetGrid to provide an easy interface to show a linear regression on “faceted” plots that allow you to explore interactions with up to three additional categorical variables.

How do you extend a regression line in Seaborn?

By default seaborn fits the length of regression line according to the length of x axis. Another option is to use argument truncate=True - that would limit the regression line only to the extent of data. Other options? In my example I want the lower regression line to be extended down till x=0.

What are Seaborn regression plots?

Seaborn | Regression Plots Last Updated : 17 Sep, 2019 The regression plots in seaborn are primarily intended to add a visual guide that helps to emphasize patterns in a dataset during exploratory data analyses. Regression plots as the name suggests creates a regression line between 2 parameters and helps to visualize their linear relationships.

How do I visualize a linear relationship in Seaborn?

Two main functions in seaborn are used to visualize a linear relationship as determined through regression. These functions, regplot () and lmplot () are closely related, and share much of their core functionality.

What is the difference between lmplot () and regplot () in Seaborn?

In contrast, the size and shape of the lmplot () figure is controlled through the FacetGrid interface using the height and aspect parameters, which apply to each facet in the plot, not to the overall figure itself: A few other seaborn functions use regplot () in the context of a larger, more complex plot.

What is a regplot ()?

This is because regplot () is an “axes-level” function draws onto a specific axes. This means that you can make multi-panel figures yourself and control exactly where the regression plot goes.


2 Answers

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.

like image 130
millikan Avatar answered Sep 24 '22 14:09

millikan


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.

like image 34
Khris Avatar answered Sep 22 '22 14:09

Khris