##b) #Suppose $X_1$ and $X_3$ are independent standard normal random variables. n = 100 x1<-rnorm(n,0,1) x3<-rnorm(n,0,1) #find the correlated x2 as follows: rho<-0.5 x2<-rho*x1+sqrt(1-rho^2)*x3 r = cor(x1,x2) #the empirical pearson correlation ## c) y<-x1+x2+rnorm(n,0,1) mod1<-lm(y~x1) summary(mod1) #finding the information directly from R: est_b1 = summary(mod1)$coef[2,1] est_sd_b1 = summary(mod1)$coef[2,2] #calculating the information by your self: X = model.matrix(mod1) est_b1 = (solve(t(X)%*%X)%*%t(X)%*%y)[2] est_sigma = sqrt(crossprod(mod1$res)/(n-2)) est_sd_b1 = est_sigma*sqrt(solve(t(X)%*%X)[2,2]) #= est_sigma*sqrt( 1/(var(x1)*(n-1)) ) ###taking the t-test: tobs1<-(est_b1-1)/est_sd_b1 pval1<-2*(1-pt(abs(tobs1),98)); tobs2<-(est_b1-1.5)/est_sd_b1 pval2<-2*(1-pt(abs(tobs2),98)); pval1 #reject H0: b_1 != 1. pval2 #accepting H0: b_1 = 1.5 ## d) mod_true<-lm(y~x1+x2) summary(mod_true) s1<-sqrt(var(x1)) s2<-sqrt(var(x2)) mod_true$coeff[2]+r*s2/s1*mod_true$coeff[3] est_b1 #the same value