Implement AR (1) model, loop needed

I am trying to implement an AR (1) model in a Flux Script. To calculate the next forecasted value i need the previous value. The first implementation is working but doesn´t look good and is not very reusable.

last_value = prepData |> last(column: “_value”) |> findRecord(fn: (key) => true, idx: 0)

Y_1 = phi_0 + (phi_1._value * last_value._value)

Y_2 = phi_0 + (phi_1._value * Y_1)

Y_3 = phi_0 + (phi_1._value * Y_2)

Y_4 = phi_0 + (phi_1._value * Y_3)

Y_5 = phi_0 + (phi_1._value * Y_4)

Y_6 = phi_0 + (phi_1._value * Y_5)

Y_7 = phi_0 + (phi_1._value * Y_6)

All values are float types.

I am looking for a function in Flux or a better way to calculate these values. I tried to get it done with “map()” or “reduce()”, but those functions limit me in some way, so it wasn’t possible.

@Koma, there’s a PR for reduce() that would let you preserve previous rows and, I think, accomplish what you’re trying to accomplish:

It’s gone a bit stale, but feel free to add any comments to it. I’ll see if we can get things moving on it again.

While working with the reduce() function i tried to get an array as a “field” in the identity record. Int, float and strings work fine. Are arrays not supported?

@Koma, arrays are not supported column values, so you can’t store them as part of the identity.