#############################################
## X - True covariates
## W - Observed covariates
## Y - individual response
rm(list=ls())
library(lpme)
## sample size:
n =100;
## Function gofx(x) to estimate
gofx = function(x){ 1/4*x + x^2/4 }
## Generate data
sigma_e = 0.5;
sigma_x = 1; X = rnorm(n, 0, sigma_x);
## Sample Y
Y = gofx(X) + rnorm(n, 0, sigma_e);
##------------------ method Based on X ---------------------------
#ghat_X= lpme(Y, X, 0.1, method="naive");
## 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+rlaplace(n,0,sigma_u/sqrt(2));
##------------------ method Based on W ---------------------------
#ghat_W=lpme(Y, W, 0.1, method="naive");
##------------------ JASA method -------------------------------------
h = 0.13;
#ghat_JASA = lpme(Y, W, h, method="DFC", sig=sigma_u, error="laplace");
##------------------ Our method -------------------------
ghat_NEW = lpme(Y, W, h, 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")
#lines(ghat_JASA$xgrid, ghat_JASA$yhat, lty="dotted", col="3",lwd="3")
#lines(ghat_X$xgrid, ghat_X$yhat, lty="dashed", col="4",lwd="2")
#lines(ghat_W$xgrid, ghat_W$yhat, lty="dashed", col="5",lwd="3")
Run the code above in your browser using DataLab