Question: Including an error estimate in a least square procedure

Hi, I need to update a procedure prcLeastSquareLA so that it includes error estimate information as output in it. So far for the procedure I have this:

prcLeastSquareLA:=proc(data,degree)

local vars,y,A,V,k,e,i,j,v,c,lstVars;  

vars := seq(c_i, i = 0 .. degree);

y := unapply(`+`(seq((c_i)*t^i, i = 0 .. degree)), t);

 for k to nops(data) do 

e_k := y(data[k][1]) = data[k][2];

v_k := [coeffs(lhs(e_k))];

end do:

A := convert([seq(v_i, i = 1 .. nops(data))], Matrix);

V := convert([seq(data[i][2], i = 1 .. nops(data))], Vector);

lstVars := convert((1/(A^%T.A)).(A^%T).V, list);

#c_0, c_1,c_2,c_3

for j to 4 do

c_(j-1) := lstVars_j;

end do;  

return y;

 end proc:

data := [[1, 1], [2, 3], [4, 2.5], [5, 4.1], [6, 7.2]];

f := prcLeastSquareLA(data, 3);

f(x);

   3.7823529411764705+6.841316526610645x-2.2296218487394968x^2 +0.23284313725490205x^3
Please Wait...