This function selects the bandwidth for both the DFC (Delaigle, Fan, and Carroll, 2009) and HZ (Huang and Zhou, 2014+) estimators.

1 2 3 |

`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 first level error contamination; defualt is |

`length.h` |
number of grid points for each of h1 and h2; default is 10. |

`Wdiff` |
an n by 1 vector of |

`data` |
data frame. |

`na.action` |
a function that indicates what should happen when the data
contain |

`work.dir` |
working directory. |

This function selects the bandwidth for both the DFC (Delaigle, Fan, and Carroll, 2009) and HZ (Huang and Zhou, 2014+) estimators.

The results include the bandwidth `bw`

.

Haiming Zhou <zhouh@email.sc.edu> and Xianzheng Huang <huang@stat.sc.edu>

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.

Delaigle, A., Fan, J., and Carroll, R. (2009). A design-adaptive local polynomial estimator for the errors-in-variables problem. *Journal of the American Statistical Association* 104, 348-359.

Huang, X. and Zhou, H. (2014+). An alternative local polynomial estimator for the errors-in-variable problem. *Submitted*.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ```
#############################################
## X - True covariates
## W - Observed covariates
## Y - individual response
rm(list=ls())
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
hwNEW = bwSIMEX(Y, W, method="HZ", sig=sigma_u, error="laplace", k_fold=2,
B=1, length.h=1)$bw
ghat_NEW = lpme(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")
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.