I need to get information out of LINEST Excel function. I'd like to know if there is libraries that have similar functions or if It's possible to use native Excel functions in C# somehow? It might be important that I'm working in MVS 2010 and using Windows Forms. I wrote a least square estimate function that calculates parameters only for 2-factor model, but I need to calculate parameters for a model with more then 2 factors.
P.S. Actually I did google for answers and i saw that somebody used package Microsoft.Office.Excel to calculate necessary information but there are no such an imports in my IDE. I don't want to invent a wheel, so I appreciate totally any information. Thank You.
Update: Finally i added a Microsoft.Office.Excel reference to my Project and solved my problem. Source code is attached below. The result is 2D Excel-like array. Code was written in a hurry so It's not really good and need to be modified. I just hope that It will help for other people. /w me if you need help
Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.WorksheetFunction wsf = xl.WorksheetFunction;
List<double> x = new List<double> { 107, 109, 110, 113, 120, 122, 123, 128, 136, 140, 145, 150 };
List<double> y = new List<double> { 102, 105, 108, 110, 115, 117, 119, 125, 132, 130, 141, 144 };
object result = wsf.LinEst(y.ToArray(), x.ToArray(), true, true);
Array resArray = (Array)result;
double[,] linest = new double[5, 2];
int i = 0, j = 0;
Console.WriteLine("{0,15:f10}", resArray.Length);
foreach (var element in resArray)
{
if (i == 0 || i == 2 || i == 4 || i == 6 || i == 8)
{
linest[j, 0] = (double)element;
}
else
{
linest[j, 1] = (double)element;
j++;
}
i++;
}
Console.WriteLine();
for (i = 0; i < linest.GetLength(0); i++)
{
for (j = 0; j < linest.GetLength(1); j++)
Console.Write("{0,25:f13}", linest[i, j]);
Console.WriteLine();
}