Question:How to write a procedure for Linear Regression

Question:How to write a procedure for Linear Regression

Maple 16

Hi,

I know all the necessary computational steps to create a Linear Regression line, but I am having trouble making it into a succient procedure. I have to make a 3 procedures for three methods, minimizing Vertical distance, Horizontal, and lastly, Diagonal.

I uploaded an example of my work to compute a linear regression line, minizming vertical distance. I have all the necessary steps for horizontal and diaganol as well.

example.mw

I attempted to make it into a procedure, but then syntax of if, then, end do, etc. is giving me trouble.

I attempted something like

VerticalRegression:= proc(x);

local, err, vertical, distance, VerticalLine;

(then defined each local variable)

do solve({diff(distance(vertical(m, b), data), b) = 0, diff(distance(vertical(m, b), data), m) = 0}, {b, m});

end do;

end proc;

But, as I am sure is obvious, it did not work. I was just trying to produce the b and m values, but I was unsuccesful. Best would be to have a proc such that I can do VerticalRegression(data) and spit out a graph/function of a line.

Thank you for any assistance.

﻿