Retrieve OnlineStat.Series() statistics

I can’t understand from the docs how can I retrieve a result from a series. Specifically, if I follow the example

y = rand(1000)
s = Series(Mean(), Variance())
fit!(s, y)

And after I want to apply std() to the resulting Variance(), I can’t find a way to subselect the Variance from the series

I just found a way which seems convoluted, but works

x = randn(10^6)
things = Series(Mean(), Variance())
fit!(things,x)
std(things.stats[2])

Have you tried var(things) or std(things)?

yes it returns this error:

ERROR: MethodError: no method matching iterate(::Series{Number,Tuple{Mean{Float64,EqualWeight},Variance{Float64,EqualWeight}}})

Indeed.
I think your approach is ok. consider the dump function which can be helpful.

using OnlineStats

y = rand(1000)
o = fit!(Variance(), y)
@show var(o)
@show std(o)
@show mean(o)

s = Series(Mean(), Variance())
fit!(s, y)
@show var(s.stats[2])
@show std(s.stats[2])
@show mean(s.stats[2])

value(s.stats[2]) 
value(s.stats[1]) 

dump(s)
dump(o)

That’s probably the most correct way to do this. I don’t think adding a getter function e.g. stats(s) would be worth it.

Alternatively, you can give Series a named tuple:

julia> s = Series((m=Mean(), v=Variance()));

julia> fit!(s, randn(100));

julia> s.stats.v
Variance: n=100 | value=1.08054
1 Like