circ_loess {circhelp}R Documentation

An implementation of circular-linear locally-weighted regression (LOESS)

Description

Provides an locally-weighted average when the independent variable is circular and depended variable is linear. Mainly to use with ggplot2.

Usage

circ_loess(
  formula = NULL,
  data = NULL,
  angle = NULL,
  y = NULL,
  xseq = NULL,
  circ_space = NULL,
  span = 0.75,
  ...
)

Arguments

formula

the formula, e.g., y ~ x

data

data to use

angle

a vector of angles (not used if a formula is provided)

y

dependent variable vector (not used if a formula is provided)

xseq

a grid to compute predictions on (optional, the default is to use 500 points spanning the circle)

circ_space

circular space to use (90, 180, 360, or 2*pi)

span

a span to adjust the degree of smoothing

...

other arguments (ignored)

Details

Weights for the regression are computed as \[w = (1-(d/d_{max})^3)^3\] where d is the angular difference between the point at which the estimate is computed and the angles in the data, and \(d_{max}\) is the maximum possible distance. If span is above 1, all points are included and \(d_{max} = {circ\_space}/(4*span)\). Otherwise, a proportion \(\alpha\) of the points included based on their distance to the point at which the estimate is computed and \(d_{max}\) is the corresponding maximal distance.

Value

an object of circ_loess class with the following parameters:

See Also

stats::loess()

Examples

p <- ggplot(Pascucci_et_al_2019_data, aes(x = orientation, y = err)) +
  geom_point(alpha = 0.05) +
  labs(x = "Orientation, deg.", y = "Error, deg.")
p1 <- p + geom_smooth(method = "loess") + ggtitle("Standard LOESS")
p2 <- p + geom_smooth(method = "circ_loess", method.args = list(circ_space = 180, span = 0.5)) +
  ggtitle("Circular LOESS, span = 0.5")
p3 <- p + geom_smooth(method = "circ_loess", method.args = list(circ_space = 180, span = 0.2)) +
  ggtitle("Circular LOESS, span = 0.2")
(p1 + p2 + p3)


[Package circhelp version 1.1 Index]