Polynomial regression: Difference between revisions

Line 1,877:
<pre><3.000000e+00,2.000000e+00,1.000000e+00></pre>
 
=={{header|VBA}}==
Excel VBA has built in capability for line estimation.
<lang vb>Option Base 1
Private Function polynomial_regression(y As Variant, x As Variant, degree As Integer) As Variant
Dim a() As Double
ReDim a(UBound(x), 2)
For i = 1 To UBound(x)
For j = 1 To degree
a(i, j) = x(i) ^ j
Next j
Next i
polynomial_regression = WorksheetFunction.LinEst(WorksheetFunction.Transpose(y), a, True, True)
End Function
Public Sub main()
x = [{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]
y = [{1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321}]
result = polynomial_regression(y, x, 2)
Debug.Print "coefficients : ";
For i = UBound(result, 2) To 1 Step -1
Debug.Print Format(result(1, i), "0.#####"),
Next i
Debug.Print
Debug.Print "standard errors: ";
For i = UBound(result, 2) To 1 Step -1
Debug.Print Format(result(2, i), "0.#####"),
Next i
Debug.Print vbCrLf
Debug.Print "R^2 ="; result(3, 1)
Debug.Print "F ="; result(4, 1)
Debug.Print "Degrees of freedom:"; result(4, 2)
Debug.Print "Standard error of y estimate:"; result(3, 2)
End Sub</lang>{{out}}
<pre>coefficients : 1, 2, 3,
standard errors: 0, 0, 0,
 
R^2 = 1
F = 7,70461300500498E+31
Degrees of freedom: 8
Standard error of y estimate: 2,79482284961344E-14 </pre>
=={{header|zkl}}==
Using the GNU Scientific Library
255

edits