Question: Problem 1: Linear regression a) Write an R function called my. m that takes a vector x and a vector y and returns the slope


Problem 1: Linear regression a) Write an R function called my. m that takes a vector x and a vector y and returns the slope a and y-intercept b of the line f(x)=ax+b that minimizes the sum of squared errors between f(xi) and yi. Your function must not make use of the R functions 1m,lm. fit, or any R function that does linear regression (you may however use functions like sum or mean). Your function should return a named list with two elements named a and b. Provide your code. You may use the following code as a template: 1 of 3 b) Verify that the function my. 1m that you wrote in Problem 1a) is correct by running my. 1m on a vector x of length three with values given by the first three digits of your student number (one value per digit), and a vector y given by the last three digits of your student number. Print the values that my. 1m returns. Then, do the same regression with the R function 1m and print the resulting slope and y-intercept. Note whether or not the values returned by the two methods are the same
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
