## Population correlation coefficients to consider. R = seq(-0.9, 0.9, 0.1) ## Sample size. n = 20 ## Number of simulation replications. nrep = 1e3 B = array(0, c(length(R),4)) ## Loop over the different population correlation coefficients. for (j in 1:length(R)) { r = R[j] ## Generate nrep sample correlation coefficients. C = array(0, nrep) for (i in 1:nrep) { X = rnorm(n) Y = r*X + sqrt(1-r^2)*rnorm(n) C[i] = cor(X,Y) } ## Bias, MSE, and variance. B[j,] = c(r, mean(C)-r, mean((C-r)^2), var(C)) }