Creates a scatter plot of the input vectors \(X\) and \(Y\), and overlays
a Nadaraya-Watson kernel regression curve using the specified bandwidth.
Usage
create_kernel_plot(X, Y, bandwidth = bw.nrd(X) * (length(X)^-0.1), nrows = 4)
Value
A ggplot object containing the scatter plot(s) with the kernel
regression curve(s). If a vector of bandwidths is supplied, the plots
are put into a grid using faceting.
Arguments
X
Vector of x values.
Y
Vector of y values.
bandwidth
Kernel bandwidth used for the Nadaraya-Watson estimator. Can
be a single numeric value or a vector of bandwidths.
Default is calculated as
bw.nrd(X) * (length(X) ^ -0.1).
nrows
Number of rows in the facet grid if multiple bandwidths are provided.
Does not do anything if only a single bandwidth value is provided.
Default is 4.
References
Nadaraya, E. A. (1964). On estimating regression. Theory of
Probability and Its Applications, 9(1), 141–142.
Watson, G. S. (1964). Smooth estimates of regression functions.
Sankhyā: The Indian Journal of Statistics, Series A, 359-372.