<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Is there a way we can calculate moving averages - Windows &amp;amp; x(t)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-we-can-calculate-moving-averages-Windows-amp-x-t/m-p/644966#M223356</link>
    <description>&lt;P&gt;Hello splunkers!&lt;/P&gt;
&lt;P&gt;Is there is a way we can calculate moving/rolling averages such that the current data point, ```x(t)```, is somewhere in the middle of the window, rather than at the boundaries?&amp;nbsp;&lt;BR /&gt;Ex: If ```window=5```, i want the MA to be calculated like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MA = avg(x(t-2), x(t-1), x(t), x(t+1), x(t+2))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am okay with using MLTK or any other method of implementing this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---------------------------&lt;/P&gt;
&lt;P&gt;For reference, in the following query, I show two similar methods of calculating MA - based on previous values of x(t)&lt;BR /&gt;here&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MA = avg(x(t-4), x(t-3), x(t-2), x(t-1), x(t))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=100
| streamstats count as s
| eval n=(random() % 100000) + 1
| table s n
| streamstats window=5 avg(n) as trend
| autoregress n p=1-5
| fillnull value=0
| eval ma = avg(n, n_p1, n_p2, n_p3, n_p4)
| fields s n ma trend&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---------&lt;/P&gt;
&lt;P&gt;PS: I am aware that in both methods, the absence of earlier/later values at the boundaries will cause the MA model to be inaccurate - I am okay to work around that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 May 2023 04:02:46 GMT</pubDate>
    <dc:creator>anirban_td</dc:creator>
    <dc:date>2023-05-30T04:02:46Z</dc:date>
    <item>
      <title>Is there a way we can calculate moving averages - Windows &amp; x(t)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-we-can-calculate-moving-averages-Windows-amp-x-t/m-p/644966#M223356</link>
      <description>&lt;P&gt;Hello splunkers!&lt;/P&gt;
&lt;P&gt;Is there is a way we can calculate moving/rolling averages such that the current data point, ```x(t)```, is somewhere in the middle of the window, rather than at the boundaries?&amp;nbsp;&lt;BR /&gt;Ex: If ```window=5```, i want the MA to be calculated like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MA = avg(x(t-2), x(t-1), x(t), x(t+1), x(t+2))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am okay with using MLTK or any other method of implementing this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---------------------------&lt;/P&gt;
&lt;P&gt;For reference, in the following query, I show two similar methods of calculating MA - based on previous values of x(t)&lt;BR /&gt;here&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MA = avg(x(t-4), x(t-3), x(t-2), x(t-1), x(t))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=100
| streamstats count as s
| eval n=(random() % 100000) + 1
| table s n
| streamstats window=5 avg(n) as trend
| autoregress n p=1-5
| fillnull value=0
| eval ma = avg(n, n_p1, n_p2, n_p3, n_p4)
| fields s n ma trend&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---------&lt;/P&gt;
&lt;P&gt;PS: I am aware that in both methods, the absence of earlier/later values at the boundaries will cause the MA model to be inaccurate - I am okay to work around that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2023 04:02:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-we-can-calculate-moving-averages-Windows-amp-x-t/m-p/644966#M223356</guid>
      <dc:creator>anirban_td</dc:creator>
      <dc:date>2023-05-30T04:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: Moving average - Windows &amp; x(t)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-we-can-calculate-moving-averages-Windows-amp-x-t/m-p/644975#M223359</link>
      <description>&lt;P&gt;What about something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=100
| streamstats count as s
| eval n=(random() % 100000) + 1
| table s n
| streamstats window=5 avg(n) as trend
| reverse
| autoregress trend p=2 as ra
| reverse
| fillnull value=0&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 29 May 2023 22:19:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-we-can-calculate-moving-averages-Windows-amp-x-t/m-p/644975#M223359</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-05-29T22:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way we can calculate moving averages - Windows &amp; x(t)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-we-can-calculate-moving-averages-Windows-amp-x-t/m-p/685624#M233943</link>
      <description>&lt;P&gt;you can use the "windowstats" command to achieve your goal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first download the windowstats app from here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://splunkbase.splunk.com/app/7329" target="_blank" rel="noopener"&gt;https://splunkbase.splunk.com/app/7329&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; your query | windowstats field=&amp;lt;field name&amp;gt; window=4 function=avg style=gradual&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;OR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; your query | windowstats field=&amp;lt;field name&amp;gt; window=4 function=avg style=dynamic&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the difference between gradual and dynamic is how the window will be on the edges.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when t=0 (first element) and window size is 4 ( &lt;STRONG&gt;&lt;U&gt;window=4 means 4 without counting the middle value (total window size will be 5)&lt;/U&gt;&lt;/STRONG&gt;))&lt;/P&gt;&lt;P&gt;gradual will be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; x(t), x(t+1), x(t+2), x(t+3), x(t+4)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dynamic will be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; x(t), x(t+1), x(t+2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when t=size (last element) and window size is 4 ( &lt;STRONG&gt;&lt;U&gt;window=4 means 4 without counting the middle value (total window size will be 5)&lt;/U&gt;&lt;/STRONG&gt;))&lt;/P&gt;&lt;P&gt;gradual will be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;x(t-4),  x(t-3),  x(t-2), x(t-1), x(t)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dynamic will be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; x(t-2), x(t-1), x(t)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;both dynamic and gradual work in the same way in the middle values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Happy Splunking!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 13:26:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-we-can-calculate-moving-averages-Windows-amp-x-t/m-p/685624#M233943</guid>
      <dc:creator>Adnan</dc:creator>
      <dc:date>2024-04-26T13:26:47Z</dc:date>
    </item>
  </channel>
</rss>

