Multiple regression: Difference between revisions

Content added Content deleted
(+Maple)
Line 1,116: Line 1,116:
[128.8128035798277, -143.1620228653037, 61.960325442985436]
[128.8128035798277, -143.1620228653037, 61.960325442985436]
</pre>
</pre>

=={{header|Maple}}==

First build a random dataset.

<lang maple>n:=200:
X:=<ArrayTools[RandomArray](n,4,distribution=normal)|Vector(n,1,datatype=float[8])>:
Y:=X.<4.2,-2.8,-1.4,3.1,1.75>+convert(ArrayTools[RandomArray](n,1,distribution=normal),Vector):</lang>

Now the linear regression, with either the LinearAlgebra package, or the Statistics package.

<lang maple>LinearAlgebra[LeastSquares](X,Y)^+;
# [4.33701132468683, -2.78654498997457, -1.41840666085642, 2.92065133466547, 1.76076442997642]

Statistics[LinearFit]([x1,x2,x3,x4,c],X,Y,[x1,x2,x3,x4,c],summarize=true)
# Summary:
# ----------------
# Model: 4.3370113*x1-2.7865450*x2-1.4184067*x3+2.9206513*x4+1.7607644*c
# ----------------
# Coefficients:
# Estimate Std. Error t-value P(>|t|)
# Parameter 1 4.3370 0.0691 62.7409 0.0000
# Parameter 2 -2.7865 0.0661 -42.1637 0.0000
# Parameter 3 -1.4184 0.0699 -20.2937 0.0000
# Parameter 4 2.9207 0.0687 42.5380 0.0000
# Parameter 5 1.7608 0.0701 25.1210 0.0000
# ----------------
# R-squared: 0.9767, Adjusted R-squared: 0.9761
# 4.33701132468683 x1 - 2.78654498997457 x2 - 1.41840666085642 x3
# + 2.92065133466547 x4 + 1.76076442997642 c</lang>


=={{header|Mathematica}}==
=={{header|Mathematica}}==