How to access a variable of class ets in c# while using RdotNet

562 views Asked by At

fit<-ets(myts)

where myts is a time series defined using ts() function.Now i want to read the output parameters like smoothing parameters alpha, beta and initial states and model type chosen by ets() function(eg: (A,N,N))... How do i do that in c#? I am using R.Net.

Any help will be appreciated.

1

There are 1 answers

0
j-m On

The result of the function ets is a list, so just coerce it to a list in C# too. See SupportSamples under https://github.com/jmp75/rdotnet-onboarding

    static void stackoverflow_27597542_2752565 (REngine engine)
    {
        var createModel = @"
        set.seed(0)
        x <- ts(rnorm(100))
        library(forecast)
        blah <- ets(x)
        # str(blah)
        ";
        engine.Evaluate (createModel);
        var m = engine.GetSymbol ("blah").AsList ();
        var components = m ["components"].AsCharacter ().ToArray ();
        for (int i = 0; i < components.Length; i++) {
            Console.WriteLine ("m$components[{0}] = {1}", i + 1, components [i]);
        }
    }