评估模拟中的参数偏差

时间:2014-04-24 17:10:28

标签: simulation

set.seed(123456)          
reps <- 500      # no. of repetitions
par.est <- matrix(NA, nrow= reps, ncol=2)   # empty matrix to store the estimates

b0 <- .2     # true value for the intercept
b1 <- .5     # true value for the slope
n <- 1000    # sample size
X <- runif(n, -1, 1) # create a sample of n obs on the independent variable x

for (i in 1:reps){                  # start of the loop
    Y <- b0 +b1*X + rnorm(n,0,1)     # the true DGP, with N(0,1) error
   model <-lm(Y~X)                  # estimate the OLS model
   par.est[i,1] <- model$coef[1]    # put the estimate for the intercept in the 1st column
   par.est[i, 2] <- model$coef[2]   # put the estimates for the coefficient of X in the 2nd column

}

有人能告诉我如何评估截距和斜率估计的偏差吗?

0 个答案:

没有答案