## The number of replications. nrep = 1e4 ## The sample size from each instrument. n = 10 ## The mean value of the bad data. mu2 = 0.5 ## A grid of proportions to consider. Q = seq(0, 1, 0.1) V = array(0, c(length(Q),4)) ## Check each prortion in Q to see how it performs. for (k in 1:length(Q)) { ## The good data. X1 = rnorm(nrep*n) X1 = array(X1, c(nrep,n)) M1 = apply(X1, 1, mean) ## The bad data. X2 = rnorm(nrep*n, mean=mu2) X2 = array(X2, c(nrep,n)) M2 = apply(X2, 1, mean) ## The estimator. M = Q[k]*M1 + (1-Q[k])*M2 ## Estimate bias, variance, and MSE from the simulation. bias = mean(M) variance = var(M) mse = mean(M^2) V[k,] = c(bias, variance, bias^2+variance, mse) }