Fill This Form To Receive Instant Help
Homework answers / question archive / 1) Run the following code to create the vectors x1 , x2 , and y
1) Run the following code to create the vectors x1 , x2 , and y . set . seed (1) n <- 100 x1 <- runif(n) x2 <- runif(n, 10,20) y <- 2+2*x1+0.3*x2+rnorm(n) a. (2 pts) The last line of the code above corresponds to creating a linear model in which y is a function of x1 and x2 . Write out the form of the linear model. What are the values of the regression coefficients Bo. B, and 82? What is the value of of? b. (2 pts) Use the function cor() to calculate the correlation coefficient between x1 and x2 . Create a scatter plot using ggplot2 displaying the relationship between the variables x1 and x2 . What can you say about the dierction and strength of their relationship? c. (4 pts) Fit a least squares regression to predict y using x1 and x2 . Describe the obtained results. What are the values of Bo. B, and B2? How do these relate to the true values of Bo, B1 and B2? What is the value of s and how does it relate to the true value of of? Can you reject the null hypothesis Ho : 81 = 0? How about the null hypothesis Ho : B2 = 0? d. (3 pts) Now fit a least squares regression to predict y using only x1 . Comment on your results. What are the values of B, and B, ? How do these relate to the true values of Bo and B,? What is the value of s and how does it relate to the true value of of? Can you reject the null hypothesis Ho : B1 = 0? e. (3 pts) Now fit a least squares regression to predict y using only x2 . Comment on your results. What are the values of B, and B,? How do these relate to the true values of Bo and 82? What is the value of s and does it relate to the true value of of? Can you reject the null hypothesis Ho : B2 = 0? 2. Run the following code to create the vectors x1 , x2 , and y . set . seed (1) n <- 160 x1 <- runif(n) x2 <- 0.5*x1+rnorm(n, 0, .01) y <- 2+2*x1+0.3*x2+rnorm(n) a. (8 pts) Repeat parts b, c, d, and e of Exercise 1 using the new vectors x1 , x2 and y . What differences do you see between Exercise 1 and Exercise 2? Explain why these differences occur.