locapply: Apply function to data locally.

locapplyR Documentation

Apply function to data locally.

Description

locapply applies given function to portions of y in the local x neighbourhood. This generalizes e.g. lowess as you can compute any function of y, not only the mean.

Usage

locapply(x, y, fun, bandwidth = 0.2, 
    ...)

Arguments

x

vector of x-coordinates

y

vector of y-coordinates

fun

function to be applied; it will be passed a vector of y coordinates in the neighbourhood of some x

bandwidth

bandwidth defining the neighbourhood in x-coordinates

...

additional arguments to fun

Value

A list of vectors x and y holding the x-coordinates, and the result of fun applied to the local neighbourhood of corresponding element of x.

Author(s)

Tomas Sieger

Examples

set.seed(1)
n<-100
x<-sort(runif(n,0,5))
y<-runif(n,-exp(x),exp(x))
plot(x,y,pch=19)
lines(x,locapply(x,y,quantile,probs=.5)$y)
lines(x,locapply(x,y,quantile,probs=.9)$y)
lines(x,locapply(x,y,quantile,probs=.1)$y)
lines(x,locapply(x,y,quantile,probs=1)$y)
lines(x,locapply(x,y,quantile,probs=0)$y)

tsieger/tsiMisc documentation built on Oct. 10, 2023, 10:24 p.m.