Question: Implement a function plm that takes in an x and y vector, each of length n, that fits the following straight line: y = bx

 Implement a function plm that takes in an x and yvector, each of length n, that fits the following straight line: y

= bx + a using this algorithm. This algorithm is robust tooutliers, but it is computationally slower than ordinary least squares. 1. Compute

Implement a function plm that takes in an x and y vector, each of length n, that fits the following straight line: y = bx + a using this algorithm. This algorithm is robust to outliers, but it is computationally slower than ordinary least squares. 1. Compute the slope between every pair of points (x1, y1 ) and x2, y2). If x1 = x2 for any pair of points, the slope is undefined, so exclude that pair of points. If there are no ties in the x vector, then there should be (?) pairs. (Hint: see the combn () function.) 2. Compute the median of all defined slopes. This will be the slope of the fitted line, b.3. Compute ai = yi - bxi for each of the n points, and set a = median {ai} Your function should be called plm( ), as in "linear model using pairwise slopes". It should return a vector of length 2 containing (b, a). Here is how your function should work: # Example data x

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!