Drawing regression lines
Drawing regression lines is an excellent way to visualize the association between two non-independent variables. Gadfly
and AlgebraOfGraphics
offer easy ways to create such plots. There are two kinds of regression lines we can make with these packages. The first is a classical linear regression to visualize the linear association between two variables. The second is a local regression, usually using a locally estimated scatterplot smoothing (LOESS) method. The LOESS method performs polynomial regressions on subsets of the data points. Therefore, they have two important parameters: the bandwidth or smoothing parameter and the degree of the polynomials. The bandwidth determines the sizes of the data subsets. Therefore, small bandwidth values create regressions that are sensitive to the local variations.
We can create these plots in Gadfly
using Stat.smooth
. This function takes a model
keyword argument to select between a linear model, passing the :lm
symbol...