I have always thought that regressions has been too complicated in Maple. 
The Fit command is too fiddly ie you have to specify too many things and
it is easy to get it wrong plus the statistical output you get is far from
mainstream ie you dont get t-values, p-values, R, R^2, Adj R^2 etc etc.

I have therefore designed a module called SReg with a new procedure called Reg()
which only needs one input and that is a datamatrix. It is important however that
the first row in the datamatrix contains the variable names otherwise it wont
work and that the first column contains the y-variable.

I have submited it to the maple application center.

The only problem I have with it is that it is sensitive to what other variables have
been assigned previously. My question is does there exist a command to unassign
all other variables except for the data matrix (restart wount work).
It really is a catch 22-situation.


SReg := module () export Reg; option package; 

Reg := proc (Data) local Nr, Nc, Y, X, m, w1, w2, df, rs, rsd, msr, ts, prob, Rs, RsA, u1, u2;
uses Statistics, LinearAlgebra, ArrayTools:

Nr, Nc := ArrayTools:-Size(Data);
Y := Data[2 .. Nr, 1]; X := Data[2 .. Nr, 2 .. Nc];
Nr, Nc := ArrayTools:-Size(X);

interface(rtablesize = 20);

m := Fit(a+add(B[i]*x[i], i = 1 .. Nc), X, Y, [seq(x[i], i = 1 .. Nc)],
output = solutionmodule);
w1 := m:-Results(parametervector);
w2 := m:-Results(standarderrors);
df := m:-Results(degreesoffreedom);
rs := m:-Results(residualsumofsquares);
rsd := m:-Results(residualstandarddeviation);
msr := m:-Results(residualmeansquare);

ts := convert(map(proc (y) options operator, arrow; (y-Statistics:-ExpectedValue(Y))^2 end proc, Y), `+`);
prob := 2*(Int(Statistics:-PDF(StudentT(df), x), x = xx .. infinity));
Rs := 1-rs/ts; RsA := 1-(1-Rs)*(Nr-1)/(Nr-Nc-1);

u1 := [Data[1, 1] = a+add(b[i]*Data[1, i+1], i = 1 .. Nc)];
u2 := evalf(Matrix([[Parameter, Value, StError, Tstat, Pvalue, `Significant5%`],
[a, w1[1], w2[1], w1[1]/w2[1], eval(prob, xx = abs(w1[1]/w2[1])),
is(evalf(eval(prob, xx = abs(w1[1]/w2[1])), 6) <= 0.5e-1)],
seq([b[i-1], w1[i], w2[i], w1[i]/w2[i], eval(prob,
xx = abs(w1[i]/w2[i])), is(evalf(eval(prob, xx = abs(w1[i]/w2[i])), 6) <= 0.5e-1)], i = 2 .. Nc+1),
[Nobs, Nr, Ny, 1, Nx, Nc], [Df, df, StDevResidual, rsd, MSResidual, msr],
[TotalSS, ts, ResidualSS, rs, RegressionSS, ts-rs], [R, Rs^.5, R*Square,
Rs, Adj*R*square, RsA]]), 6);

print(u2) ;

end proc :
end module:

# savelib('SReg');



Please Wait...