meanregbwSIMEX | R Documentation |
This function selects the bandwidth for both the DFC (Delaigle, Fan, and Carroll, 2009) and HZ (Huang and Zhou, 2017) estimators.
meanregbwSIMEX(Y, W, method="HZ", sig, error="laplace", k_fold=5, B=10, h1=NULL, h2=NULL, length.h=10, lconst=0.5, rconst=2, Wdiff=NULL)
Y |
an n by 1 response vector. |
W |
an n by 1 predictor vector. |
method |
the method to be used; |
sig |
standard deviation of the measurement error. |
error |
the distribution assumed for the measurement error; |
k_fold |
gives fold of cross-validation to be used; default is 2. |
B |
total number of cross-validation criteria to average over; defualt is 10. |
h1 |
bandwidth vector for the first level error contamination; default is |
h2 |
bandwidth vector for the second level error contamination; defualt is |
length.h |
number of grid points for each of h1 and h2; default is 10. |
lconst, rconst |
used to control the searching windows for bandwidths h1 and h2. For example, |
Wdiff |
an n by 1 vector of |
The results include the bandwidth bw
.
Haiming Zhou and Xianzheng Huang
Huang, X. and Zhou, H. (2017). An alternative local polynomial estimator for the error-in-variables problem. Journal of Nonparametric Statistics, 29: 301-325.
Delaigle, A. and Hall, P. (2008). Using SIMEX for smoothing-parameter choice in errors-in-variables problems. Journal of the American Statistical Association, 103: 280-287.
meanreg
############################################# ## X - True covariates ## W - Observed covariates ## Y - individual response library(lpme) ## generate laplace rlap=function (use.n, location = 0, scale = 1) { location <- rep(location, length.out = use.n) scale <- rep(scale, length.out = use.n) rrrr <- runif(use.n) location-sign(rrrr-0.5)*scale*(log(2)+ifelse(rrrr<0.5, log(rrrr), log1p(-rrrr))) } ## sample size: n =100; ## Function gofx(x) to estimate gofx = function(x){ 2*x*exp(-10*x^4/81) } ## Generate data sigma_e = 0.2; sigma_x = 1; X = rnorm(n, 0, sigma_x); ## Sample Y Y = gofx(X) + rnorm(n, 0, sigma_e); ## reliability ratio lambda=0.85; sigma_u = sqrt(1/lambda-1)*sigma_x; print( sigma_x^2/(sigma_x^2 + sigma_u^2) ); #W=X+rnorm(n,0,sigma_u); W=X+rlap(n,0,sigma_u/sqrt(2)); #### SIMEX #**Note: larger values for B and length.h are needed for accurate estimates. #**e.g., k_fold=5, B=10, length.h=10 will be generally good. hwNEW = meanregbwSIMEX(Y, W, method="HZ", sig=sigma_u, error="laplace", k_fold=2, B=1, length.h=1)$bw ghat_NEW = meanreg(Y, W, hwNEW , method="HZ", sig=sigma_u, error="laplace"); ## plots x = ghat_NEW$xgrid; plot(x, gofx(x), "l", main="Individual", lwd="2") lines(ghat_NEW$xgrid, ghat_NEW$yhat, lty="dashed", col="2",lwd="3")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.