This project is read-only.

Problem doing Linear Regression

Jul 3, 2015 at 11:27 PM
Hello, I'm new to this library. I'm having problem making a very simple linear regression and getting its coefficients. My code is this:
        double[] subidas = { 3.2, 6.4, 5.1 };
        double[] bajadas = { 1.5, 3.1, 2.5 };
        REngine engine = REngine.GetInstance();
        NumericVector ups = engine.CreateNumericVector(subidas);
        NumericVector downs = engine.CreateNumericVector(bajadas);
        NumericVector coeff = engine.Evaluate("coefficients(lm(ups ~ downs))").AsNumeric(); 
And is throwing me the following error:

"Error in eval(expr, envir, enclos) : object 'ups' not found"

Please help, thanks in advance!
Jul 3, 2015 at 11:30 PM
'ups` as created is a C# variable but is not a named variable in R. To set it in R, try this:
     engine.SetSymbol("ups", ups);
 engine.SetSymbol("downs", downs);
That should set the variable in R to have the symbol "ups" point to the data in ups.
Jul 6, 2015 at 6:56 AM
I tried it and now it's working, thanks!