# Relative (rolling) calculation window

## Recommended Posts

I've seen some discussions on creating boundaries using periodic conditions. But am interested in seeing if now() can help with creating a relative, rolling window for calculations.

For example, I am trying to create boundaries for temperature signal A (TempA) based on a prediction model for TempA, +/- the standard deviation of the model. Ideally, the StdDev would be calculated continuously over the preceeding 24hrs, offset by 1hr (i.e. the standard deviation of the model between -25h and -1hr).

Right now I've started with this: (\$p = prediction model for TempA)

\$p.standarddeviation(capsule(now()-25h,now()-1h))

But that yields a constant. And I would like it to continuously calculate over that relative -25hr:-1hr window.

##### Share on other sites

Hi John,

The following method can be used to calculate an hourly average and standard deviation over the lagging 24 hours.

1. Create a periodic condition 24 hours in length that begins every hour. Periodic conditions this specific cannot be done in the Periodic Condition wizard tool, but can be done in Formula using the following syntax: periods(24h, 1h)

2. Use signal from condition to calculate an hourly average over the last 24 hours. Make sure to select end as where you want to put the timestamp of the summary statistic.

3. Use a similar method with signal from condition to calculate an hourly standard deviation over the last 24 hours.

4. Use formula to calculate an upper limit for your temp signal equal to your 24 hr lagging average + X*standard deviation. In this example we chose + 3 SD, so the formula syntax is \$average + (3*\$standardDeviation)

5. Use formula to calculate a lower limit for your temp signal equal to your 24 hr lagging average - X*standard deviation. In this example we chose - 3 SD, so the formula syntax is \$average - (3*\$standardDeviation)

6. Use the Boundaries tool to transform your upper and lower limit signals into shaded boundaries.

Edited by Allison Buenemann
deleted duplicate screenshots
• 2