moderegbw | R Documentation |
This function selects the bandwidth (Zhou and Huang, 2019) for the local polynomial estimators for nonparametric modal regression in the absence of measurement error.
moderegbw(Y, X, method="CV-density", p.order=0, h1=NULL, h2=NULL, nstart = 4, xinterval = quantile(X, probs=c(0.025, 0.975), names = FALSE), df=5, ncomp=5, nboot=5)
Y |
an n by 1 response vector. |
X |
an n by 1 predictor vector. |
method |
|
p.order |
the order of polynomial, up to 1; |
h1 |
bandwidth vector for h1; default is |
h2 |
bandwidth vector for h2; default is |
nstart |
the starting number of modes for each grid value. |
xinterval |
the interval within which the modes will be estimated. |
df |
the degrees of freedom of splines used in the mixture normal regression for bootstrap method. |
ncomp |
the number of components used in the mixture normal regression for bootstrap method. |
nboot |
the number of bootstrap samples. |
The results include the bandwidth bw
.
Haiming Zhou and Xianzheng Huang
Zhou, H. and Huang, X. (2019). Bandwidth selection for nonparametric modal regression. Communications in Statistics - Simulation and Computation, 48(4): 968-984.
moderegbwSIMEX,modereg
library(lpme) ## sample size: n =100; ## Function m(x) to estimate# gofx1 = function(x){ (x+x^2) } gofx2 = function(x){ (x+x^2)-6 } xgrid = seq(-2, 2, length.out=100); ngrid = length(xgrid) ## Sample X X = rnorm(n, 0, 1); sigma_x=1; ## Sample Y Y = rep(0, n); U = runif(n); for(i in 1:n){ if(U[i]<0.5){ Y[i] = rnorm(1, gofx1(X[i]), 1); }else{ Y[i] = rnorm(1, gofx2(X[i]), 1); } } ## mode estimates h1ref = c(1.06*sd(X)*n^(-0.2)); h2ref = c(1.06*sd(Y)*n^(-0.2)); ## In practice moer fine grids are desired. hx = seq(h1ref*0.2, h1ref*1.5, length.out = 10); hy = seq(h2ref*0.8, h2ref, length.out = 2); hhxy = moderegbw(Y, X, method="CV-mode", p.order=0, h1=hx, h2=hy)$bw; fit = modereg(Y, X, xgrid=xgrid, bw=hhxy, p.order=0, PLOT=TRUE); ## Plot plot(xgrid, gofx1(xgrid), "l", lwd="2", ylim=c(-9,7), xlim=c(-2,2)); lines(xgrid, gofx2(xgrid), "l", lwd="2"); points(rep(fit$xgrid,fit$x.num), fit$mode, col="3",lwd="2")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.