迴歸直線(2)
Author: 藍邦偉  老師

$ O $

1

2

$ 迴歸直線 $
$又稱最小平方直線或y對x的最$
$適合直線$

$ 顯示相關統計量 $

3

$ 顯示迴歸直線 $

$ 幾何意義 $

u = Vector((x(Corner[1]), 0), (x(Corner[3]), 0))
v = Vector((0, y(Corner[1])), (0, y(Corner[3])))
O = (0, 0)
Q_2: 0.7 * Corner[1] + 0.3 * Corner[2]
Q_3: (x(Q_2), y(Corner[4]))
poly1, q_1, q_2, q_4, q_3 = Polygon(Corner[1], Q_2, Q_3, Corner[4])
P_1 = (17.643030655944578, 9.891208304735997)
P_2 = (7.261703838563736, 4.983408961408161)
P_3 = (3, 7)
P_4 = (9.328129081833856, 8.762414455770594)
P_5 = (25.26912381563193, 11.756172055200574)
P_6 = (14.543392791039398, 9.547662350703048)
P_7 = (13.756183174555543, 5.523266889174223)
P_8 = (22.021884147636026, 8.222556528004532)
A_3 = DynamicCoordinates(P_3, floor(x(P_3)), floor(y(P_3)))
A_1 = DynamicCoordinates(P_1, floor(x(P_1)), floor(y(P_1)))
A_2 = DynamicCoordinates(P_2, floor(x(P_2)), floor(y(P_2)))
A_4 = DynamicCoordinates(P_4, floor(x(P_4)), floor(y(P_4)))
A_5 = DynamicCoordinates(P_5, floor(x(P_5)), floor(y(P_5)))
A_6 = DynamicCoordinates(P_6, floor(x(P_6)), floor(y(P_6)))
A_7 = DynamicCoordinates(P_7, floor(x(P_7)), floor(y(P_7)))
A_8 = DynamicCoordinates(P_8, floor(x(P_8)), floor(y(P_8)))
A = (0.6688233005114462, 6.0631248169402845)
B = (23.547102779573496, 9.204116396670099)
L_1 = Line(A, B)
a_1 = OrthogonalLine(A_1, Vector[(0, 0), (1, 0)])
a_2 = OrthogonalLine(A_2, Vector[(0, 0), (1, 0)])
a_3 = OrthogonalLine(A_3, Vector[(0, 0), (1, 0)])
a_4 = OrthogonalLine(A_4, Vector[(0, 0), (1, 0)])
a_5 = OrthogonalLine(A_5, Vector[(0, 0), (1, 0)])
a_6 = OrthogonalLine(A_6, Vector[(0, 0), (1, 0)])
a_7 = OrthogonalLine(A_7, Vector[(0, 0), (1, 0)])
a_8 = OrthogonalLine(A_8, Vector[(0, 0), (1, 0)])
C_1 = Intersect(L_1, a_1)
C_2 = Intersect(L_1, a_2)
C_3 = Intersect(L_1, a_3)
C_4 = Intersect(L_1, a_4)
C_5 = Intersect(L_1, a_5)
C_6 = Intersect(L_1, a_6)
C_7 = Intersect(L_1, a_7)
C_8 = Intersect(L_1, a_8)
Poly1, a_9, c_1, a, b_1, C, D = Polygon(A_1, C_1, 4)
Poly2, a_{10}, c_2, c, d, E, F = Polygon(A_2, C_2, 4)
Poly3, a_{11}, c_3, e, f, G, H = Polygon(A_3, C_3, 4)
Poly4, a_{12}, c_4, g, h, I, J = Polygon(A_4, C_4, 4)
Poly5, a_{13}, c_5, i, j, K, L = Polygon(A_5, C_5, 4)
Poly6, a_{14}, c_6, k, l, M, N = Polygon(A_6, C_6, 4)
Poly7, a_{15}, c_7, m, n, P, Q = Polygon(A_7, C_7, 4)
Poly8, a_{16}, c_8, p, q, R, S = Polygon(A_8, C_8, 4)
b = false
L_2 = FitLineY({A_1, A_2, A_3, A_4, A_5, A_6, A_7, A_8})
o = false
t1: "$ 目前直線：$
$" + (LaTeX[L_1]) + " $"
t2: "$  迴歸直線：$
$" + (LaTeX[L_2]) + "$"
text1: "$ \sum_{i=1}^{8}{d_i\;^2 } $
$=" + (LaTeX[a_9^(2)]) + "+" + (LaTeX[a_{10}^(2)]) + "+" + (LaTeX[a_{11}^(2)]) + "+" + (LaTeX[a_{12}^(2)]) + "$
$+" + (LaTeX[a_{13}^(2)]) + "+" + (LaTeX[a_{14}^(2)]) + "+" + (LaTeX[a_{15}^(2)]) + "+" + (LaTeX[a_{16}^(2)]) + "$
$=" + (LaTeX[Poly8 + Poly7 + Poly6 + Poly5 + Poly4 + Poly3 + Poly2 + Poly1]) + "$"
A1: x(A_1)
A2: x(A_2)
A3: x(A_3)
A4: x(A_4)
A5: x(A_5)
A6: x(A_6)
A7: x(A_7)
A8: x(A_8)
B1: y(A_1)
B2: y(A_2)
B3: y(A_3)
B4: y(A_4)
B5: y(A_5)
B6: y(A_6)
B7: y(A_7)
B8: y(A_8)
list_1: {x(A_1), x(A_2), x(A_3), x(A_4), x(A_5), x(A_6), x(A_7), x(A_8)}
list_2: {y(A_1), y(A_2), y(A_3), y(A_4), y(A_5), y(A_6), y(A_7), y(A_8)}
table = TableText({list_1, list_2})
r = PMCC({A_1, A_2, A_3, A_4, A_5, A_6, A_7, A_8})
μ_x = Mean({x(A_1), x(A_2), x(A_3), x(A_4), x(A_5), x(A_6), x(A_7), x(A_8)})
μ_y = Mean({y(A_1), y(A_2), y(A_3), y(A_4), y(A_5), y(A_6), y(A_7), y(A_8)})
t_μ: "$ μ_x=" + (LaTeX[μ_x]) + ",μ_y=" + (LaTeX[μ_y]) + " $"
σ_{xx} = Variance({x(A_1), x(A_2), x(A_3), x(A_4), x(A_5), x(A_6), x(A_7), x(A_8)})
σ_{yy} = Variance({y(A_1), y(A_2), y(A_3), y(A_4), y(A_5), y(A_6), y(A_7), y(A_8)})
σ_{xy} = SXY({A_1, A_2, A_3, A_4, A_5, A_6, A_7, A_8})
t_r: "$ 相關係數\;r=" + (LaTeX[If[r ≠ 0, r, "0"]]) + " $"
t_L: "$ \frac{y-" + (LaTeX[μ_y]) + "}{x-" + (LaTeX[μ_x]) + "} =" + (LaTeX[r]) + " ×\frac{" + (LaTeX[sqrt(σ_{yy})]) + "}{" + (LaTeX[sqrt(σ_{xx})]) + "}$"
s = false
t_{Area}: "$ 8個正方形的面積和為\;" + (LaTeX[Poly8 + Poly7 + Poly6 + Poly5 + Poly4 + Poly3 + Poly2 + Poly1]) + " $"
t_{σσ}: "$ σ_x^2=" + (LaTeX[σ_{xx}]) + ",σ_y^2=" + (LaTeX[σ_{yy}]) + " $
$σ_x=" + (LaTeX[sqrt(σ_{xx})]) + ",σ_y=" + (LaTeX[sqrt(σ_{yy})]) + "$"
t_{σxy}: "$ \sum_{i=1}^{8}{ x_iy_i}-nμ_xμ_y$
$=" + (LaTeX[σ_{xy}]) + "-8×" + (LaTeX[μ_x]) + "×" + (LaTeX[μ_y]) + "$"