Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the span argument control in geom_smooth?

Tags:

r

ggplot2

loess

I am using geom_smooth from the ggplot2 package to create a smoothed line on a time series scatter plot (one point for each day of the year, so I have 365 points). One of the arguments is called span, and going into the help file (?geom_smooth) the following description is given:

span controls the amount of smoothing for the default loess smoother. Smaller numbers produce wigglier lines, larger numbers produce smoother lines.

However, this doesn't actually tell me what the span argument is controlling. Setting it to 1 is useless, and setting it to 0.1 provides something that looks good.

span = 0.5

Plot using <code>span = 0.5</code>

span = 0.1

Plot using <code>span = 0.1</code>

However, when describing the plot, since I'm not totally sure what span actually changes, I'm not sure how to describe the smoothed line. Any pointers?

like image 934
amccnnll Avatar asked Feb 20 '17 07:02

amccnnll


1 Answers

The span (also defined alpha) will determine the width of the moving window when smoothing your data.

"In a loess fit, the alpha parameter determines the width of the sliding window. More specifically, alpha gives the proportion of observations that is to be used in each local regression. Accordingly, this parameter is specified as a value between 0 and 1. The alpha value used for the loess curve in Fig. 2 is 0.65; so, each of the local regressions used to produce that curve incorporates 65% of the total data points. "

Taken from:

Jacoby (2000) Loess:: a nonparametric, graphical tool for depicting relationships between variables. Electoral Studies 19-4. (Paywalled paper)

For more details check the referenced paper.

like image 109
Juan Ossa Avatar answered Sep 27 '22 20:09

Juan Ossa