View source: R/inference_m2skreg.R
riem.m2skreg | R Documentation |
Given N observations X_1, X_2, …, X_N \in \mathcal{M} and scalars y_1, y_2, …, y_N \in \mathbf{R}, perform the Nadaraya-Watson kernel regression by
\hat{m}_h (X) = \frac{∑_{i=1}^n K ≤ft( \frac{d(X,X_i)}{h} \right) y_i}{∑_{i=1}^n K ≤ft( \frac{d(X,X_i)}{h} \right)}
where the Gaussian kernel is defined as
K(x) := \frac{1}{√{2π}} \exp ≤ft( - \frac{x^2}{2}\right)
with the bandwidth parameter h > 0 that controls the degree of smoothness.
riem.m2skreg( riemobj, y, bandwidth = 0.5, geometry = c("intrinsic", "extrinsic") )
riemobj |
a S3 |
y |
a length-N vector of dependent variable values. |
bandwidth |
a nonnegative number that controls smoothness. |
geometry |
(case-insensitive) name of geometry; either geodesic ( |
a named list of S3 class m2skreg
containing
a length-N vector of smoothed responses.
the bandwidth value that was originally provided, which is saved for future use.
a list containing both riemobj
and y
for future use.
#------------------------------------------------------------------- # Example on Sphere S^2 # # X : equi-spaced points from (0,0,1) to (0,1,0) # y : sin(x) with perturbation #------------------------------------------------------------------- # GENERATE DATA npts = 100 nlev = 0.25 thetas = seq(from=0, to=pi/2, length.out=npts) Xstack = cbind(rep(0,npts), sin(thetas), cos(thetas)) Xriem = wrap.sphere(Xstack) ytrue = sin(seq(from=0, to=2*pi, length.out=npts)) ynoise = ytrue + rnorm(npts, sd=nlev) # FIT WITH DIFFERENT BANDWIDTHS fit1 = riem.m2skreg(Xriem, ynoise, bandwidth=0.001) fit2 = riem.m2skreg(Xriem, ynoise, bandwidth=0.01) fit3 = riem.m2skreg(Xriem, ynoise, bandwidth=0.1) # VISUALIZE xgrd <- 1:npts opar <- par(no.readonly=TRUE) par(mfrow=c(1,3)) plot(xgrd, fit1$ypred, pch=19, cex=0.5, "b", xlab="", ylim=c(-2,2), main="h=1e-3") lines(xgrd, ytrue, col="red", lwd=1.5) plot(xgrd, fit2$ypred, pch=19, cex=0.5, "b", xlab="", ylim=c(-2,2), main="h=1e-2") lines(xgrd, ytrue, col="red", lwd=1.5) plot(xgrd, fit3$ypred, pch=19, cex=0.5, "b", xlab="", ylim=c(-2,2), main="h=1e-1") lines(xgrd, ytrue, col="red", lwd=1.5) par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.