I am trying to implement a multiple regression in MathNet using that model function for a start (may add another predictor variable later) :
Y = a + bX1 + cX2 + dX1X2+ eX1^2 + fX2^2
Dim impvol(IV(0).Count) As Double
Dim predictors1 As Double()() = New Double(2)() {} ' MN,DTE
Dim predictors2 As Double()() = New Double(2)() {} ' STRIKE,DTE
Try
For i = 1 To MN(0).Count
predictors1(i) = New Double() {CType(MN(0).Item(i), Double), CType(IV(0).Item(i), Double)}
Next
For i = 1 To Strike(0).Count
predictors2(i) = New Double() {CType(Strike(0).Item(i), Double), CType(IV(0).Item(i), Double)}
Next
For i = 1 To UBound(impvol)
impvol(i) = CType(IV(0).Item(i), Double)
Next
Catch exc As Exception
MessageBox.Show("Conversion Error (Vol Surface)")
End Try
' Model Surface is Y = a + bX1 + cX2 + dX1X2 + eX1^2 + fX2^2
' The following inline model functions are needed here to regress the 3D surface
'Dim p0 As Func(Of Double, Double) = Function(x) 1
'Dim p1 As Func(Of Double, Double) = Function(x) x
'Dim p2 As Func(Of Double(), Double) = Function(x) x(1) * x(2)
'Dim p3 As Func(Of Double, Double) = Function(x) x ^ 2
Dim p0 = Function(x As Double) 1
Dim p1 = Function(x As Double) x
Dim p2 = Function(x As Double, y As Double) x * y
Dim p3 = Function(x As Double) x ^ 2
Dim regparams1() As Double = MathNet.Numerics.Fit.LinearMultiDim(predictors1, impvol,
p0, p1(predictors1(0)), p1(predictors1(1)), p2(predictors1(0), predictors1(1)), p3(predictors1(0)), p3(predictors1(1)))
Dim regparams2() As Double = MathNet.Numerics.Fit.LinearMultiDim(predictors2, impvol, False)
The second regression compiles OK (with False) but not the first one. This is more of a VB.NET question: How do I implement the function as it is described on the Regression page in C# ?
Thanks in advance