compute_smooth_vec: Smooth vectors.

Description Usage Arguments Examples

View source: R/smooth.R

Description

This method is analogous to loess but it first finely bins the data. This yields a substantially performance improvement (<1s for 10m points), while only worsening performance slightly.

Usage

1
2
compute_smooth_vec(x, z, span = 0.25, n_bin = 1000, n_smooth = 100,
  weight = NULL)

Arguments

x, z

Numeric vectors.

span

Fraction of data that should be used by the smoother. Will be weighted by distance from predicted point.

n_bin, n_smooth

Number of components to use for binning and for smoothing.

weight

Optional. A numeric vector giving a weight for each location.

Examples

1
2
3
4
5
6
7
8
x <- runif(1e4, 0, 4 * pi)
y <- sin(x) + runif(1e4, -0.5, 0.5)
plot(x, y)
smu <- compute_smooth_vec(x, y, span = 0.25)
lines(smu$x, smu$y, type = "l", col = "red", lwd = 2)
x_grid <- seq(0, 4 * pi, length = 100)
lines(x_grid, sin(x_grid), type = "l", col = "blue", lwd = 2)
lines(x_grid, predict(loess(y ~ x), data.frame(x = x_grid)), col = "green", lwd = 2)

hadley/ggstat documentation built on May 17, 2019, 10:40 a.m.