You have probably learned in one of your introductory statisics classes the matrix form of least squares regression. You have probably learned that \(\mathbf{\hat{\beta}} = \mathbf{{(X^TX)^{-1}}X^Ty}\). We have not yet learned about the way that R does regressions. We will write our own function to estimate the betas in least squares regression. This function will be called LinearRegression().

  1. Think carefully about what arguments the function should take. Explain in a paragraph or so the design decisions that you made about the arguments your function should take. What other options were there and why did you choose the options you did? How does your function deal with different object classes as arguments? What types of tests do you run on your arguments? What kind of error messages should your function give back to you? That is, how have you designed readable error messages for the users of yor function? Hint: don’t forget the intercept and look at the function solve().
  2. What type of object should our function return. Explain in words what the class of the object you will return is. Why have you made this decision?
  3. Design a test to ensure that LinearRegression() is working properly. Without having another function as a benchmark, how are you going to ensure that LinearRegression() is working properly?
  4. Implement your design for LinearRegression() and test it. Write up the results of your tests. What is your evidence for your function working. Having now designed the function is there something you would do differently the next time?
  5. Do the challenge problem to create the analyze_all() function from Software Capentry Lesson 3.

Extra Credit

Return the standard errors with your LinearRegression() Function.