Liner Regression results....

May 13, 2016 at 7:40 PM
Edited May 13, 2016 at 7:42 PM
I've got some simple code to do linear reqression on 2 vectors (below). What I'm not sure is how to I get the results back into C#? What would the result types be? I'm particularly interested in model and coef.

Thanks
var aVec = engine.CreateIntegerVector(new []{ 1, 2, 5 });
var bVec = engine.CreateIntegerVector(new []{ 12, 15, 20 });
engine.SetSymbol("a", aVec);
engine.SetSymbol("b", bVec);
engine.Evaluate("model = lm(a~b)"); // print out in the console
engine.Evaluate("summary(model)"); // print out in the console
engine.Evaluate("formula = formula(model)"); // print out in the console
engine.Evaluate("formula"); // print out in the console
engine.Evaluate("coef<-coefficients(model)"); // print out in the console
May 13, 2016 at 9:44 PM
Edited May 13, 2016 at 9:48 PM
PhilBoyd,

try the following:
var interestingObject = engine.GetSymbol("model");
var interestingObject = engine.GetSymbol("coef");

another way would be to set your evaluation to a variable:
var result = engine.Evaluate("model = lm(a~b)");
var result = engine.Evaluate("coef<-coefficients(model)");

either way, you'll get some sort of SymbolicExpression object back from the engine. that you can play with.

Good luck.