## Demonstrate how the correlation between coefficient estimates is ## related to the correlation of the covariate data. nrep = 1e3 ## The correlation between the covariates. r = 0.4 n = 30 B = array(0, c(nrep,3)) ## How this is specified should not matter. beta = c(0,1,-1) for (k in 1:nrep) { ## Generate the design matrix. X1 = rnorm(n) X2 = r*X1 + sqrt(1-r^2)*rnorm(n) X = cbind(array(1, n), X1, X2) ## Generate the outcome. Y = X %*% beta + rnorm(n) ## Fit the model and store the coefficients. m = lm(Y ~ X+0) B[k,] = m$coefficients }